Finishing implementation

This commit is contained in:
Lucas Mello 2021-06-01 09:09:36 -03:00
commit f8a36d3cde
26 changed files with 1195 additions and 554 deletions

View file

@ -1,5 +1,5 @@
[*.{js,jsx,ts,tsx,vue}]
indent_style = space
indent_size = 2
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

View file

@ -1,5 +1,7 @@
{
"vetur.format.options.tabSize": 4,
"vetur.format.defaultFormatter.js": "vscode-typescript",
"prettier.tabWidth": 4
"prettier.tabWidth": 4,
"files.trimTrailingWhitespace": true,
"vetur.format.defaultFormatter.html": "none"
}

6
package-lock.json generated
View file

@ -1250,6 +1250,12 @@
"version": "4.2.18",
"dev": true
},
"@types/events": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz",
"integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==",
"dev": true
},
"@types/glob": {
"version": "7.1.3",
"dev": true,

View file

@ -20,6 +20,7 @@
"devDependencies": {
"@types/assert": "^1.4.7",
"@types/chai": "^4.2.11",
"@types/events": "^3.0.0",
"@types/lodash": "^4.14.154",
"@types/mocha": "^5.2.4",
"@vue/cli-plugin-babel": "~4.4.0",

6
pnpm-lock.yaml generated
View file

@ -3,6 +3,7 @@ lockfileVersion: 5.3
specifiers:
'@types/assert': ^1.4.7
'@types/chai': ^4.2.11
'@types/events': ^3.0.0
'@types/lodash': ^4.14.154
'@types/mocha': ^5.2.4
'@vue/cli-plugin-babel': ~4.4.0
@ -35,6 +36,7 @@ dependencies:
devDependencies:
'@types/assert': 1.5.4
'@types/chai': 4.2.18
'@types/events': 3.0.0
'@types/lodash': 4.14.169
'@types/mocha': 5.2.7
'@vue/cli-plugin-babel': 4.4.6_a17f8753fefa6d1bd7cb7a980cc59ef3
@ -1225,6 +1227,10 @@ packages:
resolution: {integrity: sha512-rS27+EkB/RE1Iz3u0XtVL5q36MGDWbgYe7zWiodyKNUnthxY0rukK5V36eiUCtCisB7NN8zKYH6DO2M37qxFEQ==}
dev: true
/@types/events/3.0.0:
resolution: {integrity: sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==}
dev: true
/@types/glob/7.1.3:
resolution: {integrity: sha512-SEYeGAIQIQX8NN6LDKprLjbrd5dARM5EXsd8GI/A5l0apYI1fGMWgPHSe4ZKL4eozlAyI+doUE9XbYS4xCkQ1w==}
dependencies:

View file

@ -0,0 +1,38 @@
<template>
<g class="button" @click="$emit('click')">
<rect :width="width" height="30" fill="gainsboro" stroke="black" rx="2"></rect>
<text text-anchor="middle" fill="black" :x="width / 2" y="16">{{ text }}</text>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
@Component
export default class Button extends Vue {
@Prop()
text?: string;
@Prop()
width?: number;
}
</script>
<style lang="scss">
.button {
cursor: pointer;
&:hover {
rect {
fill: silver;
stroke: white;
}
path {
fill: white;
}
text {
fill: white;
}
}
}
</style>

View file

@ -0,0 +1,34 @@
<template>
<g class="button" @click="$emit('click')">
<rect width="70" height="30" fill="gainsboro" stroke="black" rx="2"></rect>
<path transform="translate(10,10)" d="M0 0 L5 5 L0 10 Z M5 0 L10 5 L5 10 Z" fill="black" />
<text text-anchor="middle" fill="black" x="42" y="16">Pass</text>
</g>
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
@Component
export default class PassButton extends Vue {
}
</script>
<style lang="scss">
.button {
cursor: pointer;
&:hover {
rect {
fill: silver;
stroke: white;
}
path {
fill: white;
}
text {
fill: white;
}
}
}
</style>

View file

@ -0,0 +1,34 @@
<template>
<g class="button" @click="$emit('click')">
<rect width="70" height="30" fill="gainsboro" stroke="black" rx="2"></rect>
<path transform="translate(8,8) scale(0.025,0.025)" fill="black" d="M248.625,89.25 V0 l-127.5,127.5 l127.5,127.5 V140.25 c84.15,0,153,68.85,153,153 c0,84.15-68.85,153-153,153 c-84.15,0-153-68.85-153-153 h-51 c0,112.2,91.8,204,204,204 s204-91.8,204-204 S360.825,89.25,248.625,89.25z"/>
<text text-anchor="middle" fill="black" x="42" y="16">Undo</text>
</g>
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
@Component
export default class UndoButton extends Vue {
}
</script>
<style lang="scss">
.button {
cursor: pointer;
&:hover {
rect {
fill: silver;
stroke: white;
}
path {
fill: white;
}
text {
fill: white;
}
}
}
</style>

View file

@ -0,0 +1,67 @@
<template>
<g class="calculator">
<rect width="130" height="210" rx="2"></rect>
<rect x="10" y="10" width="110" height="30" fill="yellowgreen" rx="2"></rect>
<text class="visor" x="110" y="25" fill="black" text-anchor="end">{{ value }}</text>
<rect class="button" x="10" y="50" width="30" height="30" fill="gray" rx="2" @click="add(7)"></rect>
<text x="25" y="65" fill="white" stroke="white" text-anchor="middle">7</text>
<rect class="button" x="50" y="50" width="30" height="30" fill="gray" rx="2" @click="add(8)"></rect>
<text x="65" y="65" fill="white" stroke="white" text-anchor="middle">8</text>
<rect class="button" x="90" y="50" width="30" height="30" fill="gray" rx="2" @click="add(9)"></rect>
<text x="105" y="65" fill="white" stroke="white" text-anchor="middle">9</text>
<rect class="button" x="10" y="90" width="30" height="30" fill="gray" rx="2" @click="add(4)"></rect>
<text x="25" y="105" fill="white" stroke="white" text-anchor="middle">4</text>
<rect class="button" x="50" y="90" width="30" height="30" fill="gray" rx="2" @click="add(5)"></rect>
<text x="65" y="105" fill="white" stroke="white" text-anchor="middle">5</text>
<rect class="button" x="90" y="90" width="30" height="30" fill="gray" rx="2" @click="add(6)"></rect>
<text x="105" y="105" fill="white" stroke="white" text-anchor="middle">6</text>
<rect class="button" x="10" y="130" width="30" height="30" fill="gray" rx="2" @click="add(1)"></rect>
<text x="25" y="145" fill="white" stroke="white" text-anchor="middle">1</text>
<rect class="button" x="50" y="130" width="30" height="30" fill="gray" rx="2" @click="add(2)"></rect>
<text x="65" y="145" fill="white" stroke="white" text-anchor="middle">2</text>
<rect class="button" x="90" y="130" width="30" height="30" fill="gray" rx="2" @click="add(3)"></rect>
<text x="105" y="145" fill="white" stroke="white" text-anchor="middle">3</text>
<rect class="button" x="10" y="170" width="30" height="30" fill="gray" rx="2" @click="add(0)"></rect>
<text x="25" y="185" fill="white" stroke="white" text-anchor="middle">0</text>
<rect class="button" x="50" y="170" width="30" height="30" fill="orange" rx="2" @click="del()"></rect>
<text x="65" y="185" fill="white" text-anchor="middle">Del</text>
<rect class="button" x="90" y="170" width="30" height="30" fill="orange" rx="2" @click="bid()"></rect>
<text x="105" y="185" fill="white" text-anchor="middle">Bid</text>
</g>
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
@Component
export default class Calculator extends Vue {
value: number = 0;
add(number) {
this.value = Math.min(999, this.value * 10 + number);
}
del() {
this.value = Math.floor(this.value / 10);
}
bid() {
this.$emit("bid", this.value);
this.value = 0;
}
}
</script>
<style lang="scss">
.calculator {
fill: #333;
.button {
cursor: pointer;
}
.visor {
font-family: "system-ui";
}
}
</style>

View file

@ -1,19 +1,47 @@
<template>
<g>
<g :transform="'rotate(' + rotate + ', 10, 5)'">
<rect width="20" height="10" :fill="color" stroke="black"></rect>
</g>
<g :class="['container', {dragging}, {canDrag}]" :id="elId" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`">
<rect width="20" height="10" :fill="color" stroke="black"></rect>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { ContainerState, PieceType } from "@/types/ui-data";
import { Component, Mixins, Prop } from "vue-property-decorator";
import Piece from "./Piece.vue";
@Component
export default class Container extends Vue {
@Component({
created(this: Container) {
this.pieceType = PieceType.Container;
}
})
export default class Container extends Mixins(Piece) {
@Prop()
color?: string;
@Prop()
rotate?: number;
owner?: number;
@Prop()
state?: ContainerState;
}
</script>
<style lang="scss">
.container {
&:not(.dragging) {
transition-property: transform;
transition-duration: 0.8s;
transition-timing-function: ease-in-out;
}
&.canDrag {
cursor: pointer;
rect {
&:hover {
stroke: white;
}
}
}
}
</style>

View file

@ -1,100 +1,108 @@
<script lang="ts">
import {Vue, Component } from "vue-property-decorator";
import { Vue, Component, Prop } from "vue-property-decorator";
@Component({
mounted(this: Draggable) {
this.$nextTick(() => {
const endDrag = () => this.endDrag();
const drag = (event: MouseEvent | TouchEvent) => this.drag(event);
mounted(this: Draggable) {
this.$nextTick(() => {
const endDrag = () => this.endDrag();
const drag = (event: MouseEvent | TouchEvent) => this.drag(event);
this.htmlElement.addEventListener("mousedown", event => this.startDrag(event));
this.htmlElement.addEventListener('touchstart', event => this.startDrag(event));
this.htmlElement.addEventListener("mousedown", event => this.startDrag(event));
this.htmlElement.addEventListener('touchstart', event => this.startDrag(event));
this.svgElement.addEventListener('touchmove', drag);
this.svgElement.addEventListener('touchend', endDrag);
this.svgElement.addEventListener('touchleave', endDrag);
this.svgElement.addEventListener('touchcancel', endDrag);
this.svgElement.addEventListener('touchmove', drag);
this.svgElement.addEventListener('touchend', endDrag);
this.svgElement.addEventListener('touchleave', endDrag);
this.svgElement.addEventListener('touchcancel', endDrag);
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchmove", drag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchend", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchleave", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchcancel", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchmove", drag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchend", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchleave", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("touchcancel", endDrag));
this.svgElement.addEventListener("mouseleave", endDrag);
this.svgElement.addEventListener("mouseup", endDrag);
this.svgElement.addEventListener("mousemove", drag);
this.svgElement.addEventListener("mouseleave", endDrag);
this.svgElement.addEventListener("mouseup", endDrag);
this.svgElement.addEventListener("mousemove", drag);
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("mouseleave", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("mouseup", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("mousemove", drag));
});
}
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("mouseleave", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("mouseup", endDrag));
this.$on("hook:beforeDestroy", () => this.svgElement.removeEventListener("mousemove", drag));
});
}
})
export default class Draggable extends Vue {
dragging = false;
_offset = {x: 0, y: 0};
_transform?: SVGTransform;
_dragStart?: number;
@Prop()
canDrag;
get svgElement() {
return document.querySelector("#scene") as SVGSVGElement;
}
dragging = false;
_offset = { x: 0, y: 0 };
_transform?: SVGTransform;
_dragStart?: number;
get htmlElement() {
return this.$el as SVGGElement;
}
startDrag(evt: MouseEvent | TouchEvent) {
this.dragging = true;
this._offset = this.getMousePosition(evt);
// Get all the transforms currently on this element
const transforms: SVGTransformList = this.htmlElement.transform.baseVal;
// Ensure the first transform is a translate transform
if (transforms.numberOfItems === 0 ||
transforms.getItem(0).type !== SVGTransform.SVG_TRANSFORM_TRANSLATE) {
// Create an transform that translates by (0, 0)
const translate = this.svgElement.createSVGTransform();
translate.setTranslate(0, 0);
// Add the translation to the front of the transforms list
this.htmlElement.transform.baseVal.insertItemBefore(translate, 0);
}
// Get initial translation amount
this._transform = transforms.getItem(0);
this._offset.x -= this._transform.matrix.e;
this._offset.y -= this._transform.matrix.f;
this._dragStart = Date.now();
}
drag(evt: MouseEvent | TouchEvent) {
if (!this.dragging) {
return;
get svgElement() {
return document.querySelector("#scene") as SVGSVGElement;
}
evt.preventDefault();
const coord = this.getMousePosition(evt);
this._transform!.setTranslate(coord.x - this._offset.x, coord.y - this._offset.y);
this.$emit("draggedTo", {x: coord.x - this._offset.x, y: coord.y - this._offset.y});
}
endDrag() {
this.dragging = false;
if (Date.now() - this._dragStart! < 250) {
this.$emit("fastClick");
get htmlElement() {
return this.$el as SVGGElement;
}
}
getMousePosition(evt: MouseEvent | TouchEvent) {
if ((evt as TouchEvent).touches) {
evt = (evt as TouchEvent).touches[0] as any;
startDrag(evt: MouseEvent | TouchEvent) {
if (!this.canDrag)
return;
this.dragging = true;
this._offset = this.getMousePosition(evt);
// Get all the transforms currently on this element
const transforms: SVGTransformList = this.htmlElement.transform.baseVal;
// Ensure the first transform is a translate transform
if (transforms.numberOfItems === 0 ||
transforms.getItem(0).type !== SVGTransform.SVG_TRANSFORM_TRANSLATE) {
// Create an transform that translates by (0, 0)
const translate = this.svgElement.createSVGTransform();
translate.setTranslate(0, 0);
// Add the translation to the front of the transforms list
this.htmlElement.transform.baseVal.insertItemBefore(translate, 0);
}
// Get initial translation amount
this._transform = transforms.getItem(0);
this._offset.x -= this._transform.matrix.e;
this._offset.y -= this._transform.matrix.f;
this._dragStart = Date.now();
}
drag(evt: MouseEvent | TouchEvent) {
if (!this.dragging) {
return;
}
evt.preventDefault();
const coord = this.getMousePosition(evt);
this._transform!.setTranslate(coord.x - this._offset.x, coord.y - this._offset.y);
this.$emit("draggedTo", { x: coord.x - this._offset.x, y: coord.y - this._offset.y });
}
endDrag() {
this.dragging = false;
if (Date.now() - this._dragStart! < 100) {
this.$nextTick(() => { this.$emit("fastClick", this); });
}
}
getMousePosition(evt: MouseEvent | TouchEvent) {
if ((evt as TouchEvent).touches) {
evt = (evt as TouchEvent).touches[0] as any;
}
const CTM = this.svgElement.getScreenCTM()!;
return {
x: ((evt as any).clientX - CTM.e) / CTM.a,
y: ((evt as any).clientY - CTM.f) / CTM.d
};
}
const CTM = this.svgElement.getScreenCTM()!;
return {
x: ((evt as any).clientX - CTM.e) / CTM.a,
y: ((evt as any).clientY - CTM.f) / CTM.d
};
}
}
</script>

View file

@ -0,0 +1,87 @@
<template>
<g :class="['placeholder', { enabled, overlapping }]">
<rect :width="width" :height="height" />
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop, Watch, Inject } from "vue-property-decorator";
import { DropZoneType, UIData } from '../types/ui-data';
import { EventEmitter, Listener } from 'events';
import Piece from "./Piece.vue";
@Component
export default class DropZone extends Vue {
@Inject()
readonly ui!: UIData;
@Inject()
readonly communicator!: EventEmitter;
@Prop({ default: true })
enabled!: boolean;
@Prop()
width!: number;
@Prop()
height!: number;
@Prop()
accepts?: string;
@Prop()
data?: any;
listener?: Listener;
overlapping = false;
updateOverlapping(piece: Piece) {
if (!this.enabled || !this.ui.dragged) {
if (this.overlapping && this.enabled && !this.ui.dragged) {
if (this.accepts?.indexOf(piece.pieceType) != -1) {
console.log("emit pieceDrop", piece);
this.communicator.emit("pieceDrop", piece, this.data);
} else {
console.log("not accepted", piece.pieceType, this.accepts);
}
}
this.overlapping = false;
return;
}
const rect1 = this.$el.getBoundingClientRect();
const rect2 = this.ui.dragged!.$el.getBoundingClientRect();
this.overlapping = rect1.bottom >= rect2.top && rect1.right >= rect2.left && rect1.top <= rect2.bottom && rect1.left <= rect2.right;
}
@Watch("enabled", { immediate: true })
onEnabledChanged() {
if (!this.listener) {
this.listener = (piece) => this.updateOverlapping(piece);
this.$on("hook:beforeDestroy", () => this.communicator.off("draggedPosChanged", this.listener!));
}
if (this.enabled) {
this.communicator.on("draggedPosChanged", this.listener!);
} else {
this.communicator.off("draggedPosChanged", this.listener!);
}
}
}
</script>
<style lang="scss">
g.placeholder {
rect {
stroke: none;
fill: none;
}
&.canClick {
cursor: pointer;
}
}
</style>

View file

@ -1,14 +1,41 @@
<template>
<g>
<g :class="['factory', {dragging}, {canDrag}]" :id="elId" :transform="`translate(${currentX}, ${currentY})`">
<circle r="10" :fill="color" stroke="black"></circle>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { PieceType } from "@/types/ui-data";
import { Component, Mixins, Prop } from "vue-property-decorator";
import Piece from "./Piece.vue";
@Component
export default class Factory extends Vue {
@Component({
created(this: Factory) {
this.pieceType = PieceType.Factory;
}
})
export default class Factory extends Mixins(Piece) {
@Prop()
color?: string;
}
</script>
<style lang="scss">
.factory {
&:not(.dragging) {
transition-property: transform;
transition-duration: 0.8s;
transition-timing-function: ease-in-out;
}
&.canDrag {
cursor: pointer;
circle {
&:hover {
stroke: white;
}
}
}
}
</style>

View file

@ -8,35 +8,57 @@
</filter>
</defs>
<rect width="100%" height="100%" x="0" y="0" fill="lightblue" stroke="#000077"></rect>
<rect width="100%" height="100%" x="0" y="0" fill="lightblue"></rect>
<rect width="100%" height="100" x="0" y="0" fill="gray"></rect>
<rect width="390" height="220" x="860" y="430" fill="gray"></rect>
<PassButton transform="translate(1130, 15)" @click="pass()" />
<UndoButton transform="translate(1130, 55)" @click="undo()" />
<template v-if="G">
<template v-for="(player, i) in G.players">
<PlayerBoard :key="'B' + i" :name="player.name" :color="['dodgerblue', 'red', 'yellow', 'limegreen', 'mediumorchid'][i]" :transform="`translate(${250 * i}, 100)`" />
<PlayerBoard :key="'B' + i" :player="player" :color="['dodgerblue', 'red', 'yellow', 'limegreen', 'mediumorchid'][i]"
:transform="`translate(${250 * i}, 100)`" :owner="i" :currentPlayer="G.currentPlayer == i"
:ended="gameEnded(G)" @pieceDrop="onPieceDrop" />
<rect :key="'I' + i" width="390" height="41" x="860" :y="430 + i * 44" fill="none" stroke-width="3" :stroke="['dodgerblue', 'red', 'yellow', 'limegreen', 'mediumorchid'][i]"></rect>
</template>
</template>
<template v-for="ship in ships">
<Ship :key="'S' + ship.id" :rotate="ship.rotate" :color="ship.color" :transform="`translate(${ship.x}, ${ship.y})`" />
<Ship :key="ship.id"
:pieceId="ship.id"
:targetState="{ x: ship.x, y: ship.y, rotate: ship.rotate }"
:canDrag="ship.owner == G.currentPlayer"
:containers="ship.containers"
:color="ship.color" />
</template>
<template v-for="container in containers">
<Container :key="'C' + container.id" :rotate="container.rotate" :transform="`translate(${container.x}, ${container.y})`" :color="container.color" />
<Container :key="container.id"
:pieceId="container.id"
:targetState="{ x: container.x, y: container.y, rotate: container.rotate }"
:canDrag="canDragContainer(container)"
:color="container.color"
:owner="container.owner"
:state="container.state" />
</template>
<template v-for="factory in factories">
<Factory :key="'F' + factory.id" :transform="`translate(${factory.x}, ${factory.y})`" :color="factory.color" />
<Factory :key="factory.id" :pieceId="factory.id" :targetState="{ x: factory.x, y: factory.y}" :canDrag="canDragFactory(factory)" :color="factory.color" />
</template>
<template v-for="factory in factoriesBuilt">
<Factory :key="factory.id" :pieceId="factory.id" :targetState="{ x: factory.x, y: factory.y}" :canDrag="false" :color="factory.color" />
</template>
<template v-for="warehouse in warehouses">
<Warehouse :key="'W' + warehouse.id" :transform="`translate(${warehouse.x}, ${warehouse.y})`" />
<Warehouse :key="warehouse.id" :pieceId="warehouse.id" :targetState="{ x: warehouse.x, y: warehouse.y}" :canDrag="canDragWarehouse()" />
</template>
<template v-for="warehouse in warehousesBuilt">
<Warehouse :key="warehouse.id" :pieceId="warehouse.id" :targetState="{ x: warehouse.x, y: warehouse.y}" :canDrag="false" />
</template>
<template v-for="loanCard in loanCards">
<LoanCard :key="'L' + loanCard.id" :transform="`translate(${loanCard.x}, ${loanCard.y})`" />
<LoanCard :key="loanCard.id" :targetState="{ x: loanCard.x, y: loanCard.y }" :owner="loanCard.owner" :player="player" :canDrag="canDragLoan(loanCard)" @fastClick="loan($event)" />
</template>
<template v-if="G">
@ -44,58 +66,33 @@
<text x="20" y="620">Money: ${{ G.players[player].money }}</text>
</template>
<!-- Game Info
<GameInfo :round="round" transform="translate(-190, -240)" />
Players
<PlayerLabel :player="G.players[player || 0]" :playerIndex=player :main=true :points=G.players[player||0].points transform="translate(-150, 120)" v-if="G" />
<PlaceHolder :player="player || 0" transform="translate(-220, 170)" :playerTurn="canPlayerMove(player||0)" :enabled="canPlayerMove(player||0) && !G.players[player||0].faceDownCard" v-if="G" @cardDrop="onCardDrop" />
<DropZone :transform="`translate(300, 425)`" :width="400" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'openSea' }" />
<DropZone :transform="`translate(800, 425)`" :width="450" :height="225" :enabled="true" :accepts="'ship'" :data="{ type: 'islandHarbor' }" />
<template v-for="(player, i) in otherPlayers">
<PlayerLabel :player="G.players[player]" :playerIndex=player :points=G.players[player].points :transform="`translate(${i <= 5 ? 173 + 115 * (i % 2) : -300}, ${i <= 5 ? -218 + 110 * Math.floor(i /2) : -218 + 110 * (i - 6)})`" :key="'label-'+player" />
<PlaceHolder :player="player" :playerTurn="canPlayerMove(player)" :key="'placehold-player-' + player" :transform="`translate(${i <= 5 ? 173 + 115 * (i % 2) : -300}, ${i <= 5 ? -163 + 110 * Math.floor(i /2) : -163 + 110 * (i - 6)})`" />
</template>
Board
<template v-for="row in 4">
<template v-for="rowPos in 6">
<PlaceHolder
:key="`board-${row-1}-${rowPos-1}`"
:row=row-1
:rowPos=rowPos-1
:danger="rowPos===6"
:transform="`translate(${-203 + (rowPos-1) * 55}, ${((row - 1) - 1.5) * 80 - 75})`"
:enabled="isPlaceholderEnabled(row-1, rowPos-1)"
@cardDrop="onCardDrop"
/>
</template>
</template>
All the cards
<Card v-for="(card, i) in [...sortedHandCards].reverse()" :card="card" :key="card.number || `hand-${i}`" :targetState="handTargetState(handCards.length - 1 - i)" @fastClick="onCardDrop(card, {player})" />
<DropZone :transform="`translate(1045, 10)`" :width="40" :height="70" :enabled="true" :accepts="'loan'" :data="{ type: 'payLoan' }" />
<template v-if="G">
<template v-for="(player, i) in G.players">
<Card v-if="player.faceDownCard" :card="player.faceDownCard" :key="player.faceDownCard.number || 'player-'+i" :targetState="facedownTargetState(i)" @fastClick="onCardDrop(player.faceDownCard, {player: i, autoChooseRow: true})" />
<Calculator v-if="G.phase == 'bid'" transform="translate(140, 430)" @bid="bid($event)" />
<template v-if="G.currentPlayer == G.auctioningPlayer">
<template v-for="(bidder, i) in G.highestBidders">
<Button :key="bidder" :transform="`translate(140, ${450 + 40 * i})`" :width="130" :text="'Accept ' + G.players[bidder].name" @click="accept(bidder)" />
</template>
<Button :transform="`translate(140, ${450 + 40 * G.highestBidders.length})`" :width="130" :text="'Decline'" @click="decline()" />
</template>
</template>
<template v-for="row in 4">
<template v-for="rowPos in 6">
<Card v-if="G && G.rows[row-1][rowPos-1]" :card="G.rows[row-1][rowPos-1]" :key="G.rows[row-1][rowPos-1].number || 'board-card-'+row+'-'+rowPos" :targetState="boardTargetState(row-1, rowPos-1)" />
</template>
</template> -->
<use xlink:href="#moving" />
<use xlink:href="#dragged" />
</svg>
</div>
</template>
<script lang="ts">
import { Vue, Component, Prop, Watch, Provide, ProvideReactive, } from "vue-property-decorator";
import { LogItem, AvailableMoves, Phase, reconstructState, } from "container-engine";
import { LogItem, AvailableMoves, Phase, reconstructState, MoveName, ended } from "container-engine";
import type { GameState } from "container-engine";
import { EventEmitter } from "events";
import { range, isEqual, groupBy } from "lodash";
import { Piece, UIData } from "../types/ui-data";
import { ContainerState, DropZoneType, Piece, PieceType, ShipType, UIData } from "../types/ui-data";
import { logToText } from "../utils/log-to-text";
import { ContainerColor, ShipPosition } from "container-engine/src/gamestate";
import PlayerBoard from "./PlayerBoard.vue";
@ -105,6 +102,12 @@ import Warehouse from "./Warehouse.vue";
import LoanCard from "./LoanCard.vue";
import PointCard from "./PointCard.vue";
import Ship from "./Ship.vue";
import Button from "./Buttons/Button.vue";
import PassButton from "./Buttons/PassButton.vue";
import UndoButton from "./Buttons/UndoButton.vue";
import PieceComponent from "./Piece.vue";
import DropZone from "./DropZone.vue";
import Calculator from "./Calculator.vue";
@Component({
created(this: Game) {
@ -127,12 +130,12 @@ import Ship from "./Ship.vue";
pointCard: player.pointCard,
factories: player.factories,
warehouses: player.warehouses,
ship: { containers: [], shipPosition: ShipPosition.OpenSea },
ship: { piece: { id: '' }, containers: [], shipPosition: ShipPosition.OpenSea },
containersOnFactoryStore: player.containersOnFactoryStore,
containersOnWarehouseStore: [],
containersOnIsland: [],
money: 20,
loans: 0,
loans: [],
produced: [],
availableMoves: null,
lastMove: null,
@ -140,11 +143,14 @@ import Ship from "./Ship.vue";
isDropped: false,
bid: 0,
additionalBid: 0,
showBid: false,
showAdditionalBid: false,
})),
currentPlayer: this.G!.currentPlayer,
containersLeft: this.G!.containersLeft,
factoriesLeft: this.G!.factoriesLeft,
warehousesLeft: this.G!.warehousesLeft,
loansLeft: this.G!.loansLeft,
auctioningPlayer: -1,
highestBidders: [],
phase: Phase.Move,
@ -154,25 +160,13 @@ import Ship from "./Ship.vue";
round: 1
};
this.replaceState(
reconstructState(
baseState,
this._futureState!.log.slice(0, to)
),
false
);
this.replaceState(reconstructState(baseState, this._futureState!.log.slice(0, to)), false);
}
if (this.G!.log.length + 1 === to) {
this.advanceLog();
} else if (this.G!.log.length + 1 < to) {
this.replaceState(
reconstructState(
this.G!,
this._futureState!.log.slice(this.G!.log.length, to)
),
false
);
this.replaceState(reconstructState(this.G!, this._futureState!.log.slice(this.G!.log.length, to)), false);
}
this.emitter.emit("replay:info", {
@ -186,6 +180,9 @@ import Ship from "./Ship.vue";
this.paused = false;
this.emitter.emit("fetchState");
});
this.communicator.on("pieceDrop", this.onPieceDrop);
this.$on("hook:beforeDestroy", () => this.communicator.off("pieceDrop", this.onPieceDrop));
},
components: {
PlayerBoard,
@ -194,7 +191,12 @@ import Ship from "./Ship.vue";
Warehouse,
LoanCard,
PointCard,
Ship
Ship,
PassButton,
UndoButton,
DropZone,
Calculator,
Button
},
})
export default class Game extends Vue {
@ -212,9 +214,7 @@ export default class Game extends Vue {
@Provide()
ui: UIData = {
cards: {},
placeholders: { rows: [], players: [] },
waitingAnimations: 0,
waitingAnimations: 0
};
@Provide()
@ -226,9 +226,13 @@ export default class Game extends Vue {
containers: Piece[] = [];
factories: Piece[] = [];
factoriesBuilt: Piece[] = [];
warehouses: Piece[] = [];
warehousesBuilt: Piece[] = [];
loanCards: Piece[] = [];
ships: Piece[] = [];
ships: ShipType[] = [];
currentMove = 0;
addLog({ log, availableMoves, start }: { log: LogItem[]; start: number; availableMoves: AvailableMoves[] }) {
console.log("adding log...");
@ -245,11 +249,7 @@ export default class Game extends Vue {
}
// edge case when we do a move and another player just did a move
if (
start === this._futureState!.log.length &&
start > 0 &&
isEqual(log[0], this._futureState!.log.slice(-1)[0])
) {
if (start === this._futureState!.log.length && start > 0 && isEqual(log[0], this._futureState!.log.slice(-1)[0])) {
this.emitter.emit("fetchState");
return;
}
@ -258,10 +258,12 @@ export default class Game extends Vue {
...this._futureState!.log.slice(0, start),
...log,
];
this._pendingAvailableMoves = {
index: start + log.length,
availableMoves: availableMoves,
};
this.updateUI();
}
@ -278,75 +280,18 @@ export default class Game extends Vue {
this.G = JSON.parse(JSON.stringify(state));
if (this.G) {
this.emitter.emit(
"uplink:replaceLog",
[
...this.G!.log.map((x: LogItem) => logToText(this.G!, x)),
].flat(1)
);
}
if (this.G)
this.emitter.emit("uplink:replaceLog", [...this.G!.log.map((x: LogItem) => logToText(this.G!, x))].flat(1));
this.createComponents();
this.createPieces();
// if (this.G?.phase === Phase.Setup) {
// this._futureState?.log.push({ type: "phase", phase: Phase.Setup });
// this.advanceLog();
// }
}
createComponents() {
let pieceId = 0;
// if (this.G) {
// let player = this.G.players[0];
// player.ship.shipPosition = ShipPosition.Island;
// player.ship.containers = [ContainerColor.White, ContainerColor.Black, ContainerColor.Orange, ContainerColor.Tan, ContainerColor.Brown];
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnFactoryStore.push({ containerColor: ContainerColor.Black, price: 2 });
// player.containersOnFactoryStore.push({ containerColor: ContainerColor.Black, price: 2 });
// player.containersOnFactoryStore.push({ containerColor: ContainerColor.Black, price: 2 });
// player.containersOnFactoryStore.push({ containerColor: ContainerColor.Black, price: 2 });
// player.containersOnFactoryStore.push({ containerColor: ContainerColor.Tan, price: 2 });
// player = this.G.players[1];
// player.ship.shipPosition = ShipPosition.Island;
// player.ship.containers = [ContainerColor.White, ContainerColor.Black, ContainerColor.Orange, ContainerColor.Tan, ContainerColor.Brown];
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Orange);
// player.containersOnIsland.push(ContainerColor.Black);
// player.containersOnIsland.push(ContainerColor.White);
// player.containersOnIsland.push(ContainerColor.Brown);
// player = this.G.players[2];
// player.ship.shipPosition = ShipPosition.Island;
// player.ship.containers = [ContainerColor.White, ContainerColor.Black, ContainerColor.Orange, ContainerColor.Tan, ContainerColor.Brown];
// player.containersOnIsland.push(ContainerColor.Orange);
// player.containersOnIsland.push(ContainerColor.Orange);
// player.containersOnIsland.push(ContainerColor.Orange);
// player.containersOnIsland.push(ContainerColor.White);
// player.containersOnIsland.push(ContainerColor.Brown);
// player = this.G.players[3];
// player.ship.shipPosition = ShipPosition.Island;
// player.ship.containers = [ContainerColor.White, ContainerColor.Black, ContainerColor.Orange, ContainerColor.Tan, ContainerColor.Brown];
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player = this.G.players[4];
// player.ship.shipPosition = ShipPosition.Island;
// player.ship.containers = [ContainerColor.White, ContainerColor.Black, ContainerColor.Orange, ContainerColor.Tan, ContainerColor.Brown];
// player.containersOnWarehouseStore.push({ containerColor: ContainerColor.Brown, price: 4 });
// player.containersOnWarehouseStore.push({ containerColor: ContainerColor.Brown, price: 5 });
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Tan);
// player.containersOnIsland.push(ContainerColor.Black);
// player.containersOnIsland.push(ContainerColor.Black);
// player.containersOnIsland.push(ContainerColor.White);
// }
createPieces() {
// Containers
this.containers = [];
this.G?.players.forEach((player, pi) => {
@ -354,11 +299,14 @@ export default class Game extends Vue {
Object.keys(grouped).forEach(price => {
grouped[price].forEach((container, ci) => {
this.containers.push({
id: pieceId++,
id: container.piece.id,
x: 8 + pi * 250 + (container.price - 1) * 48 + (ci % 2) * 20,
y: 160 + Math.floor(ci / 2) * 10,
rotate: 0,
color: container.containerColor.toString() });
color: container.piece.color.toString(),
owner: pi,
state: ContainerState.OnFactoryStore
});
});
});
@ -366,112 +314,111 @@ export default class Game extends Vue {
Object.keys(grouped).forEach(price => {
grouped[price].forEach((container, ci) => {
this.containers.push({
id: pieceId++,
id: container.piece.id,
x: 8 + pi * 250 + (container.price - 2) * 48 + (ci % 2) * 20,
y: 250 + Math.floor(ci / 2) * 10,
rotate: 0,
color: container.containerColor.toString() });
color: container.piece.color.toString(),
owner: pi,
state: ContainerState.OnWarehouseStore
});
});
});
let lastColor;
let offset = 0;
player.containersOnIsland.sort().forEach((containerColor, ci) => {
if (containerColor !== lastColor)
player.containersOnIsland.sort((a, b) => a.color.localeCompare(b.color)).forEach((container, ci) => {
if (container.color !== lastColor)
offset += 10;
this.containers.push({ id: pieceId++, x: 860 + offset + 12 * ci, y: 445 + 44 * pi, rotate: 90, color: containerColor.toString() });
lastColor = containerColor;
});
this.containers.push({
id: container.id,
x: 860 + offset + 12 * ci,
y: 445 + 44 * pi,
rotate: 90,
color: container.color.toString(),
owner: pi,
state: ContainerState.OnIsland
});
player.ship.containers.forEach((containerColor, ci) => {
switch (player.ship.shipPosition) {
case ShipPosition.OpenSea:
this.containers.push({ id: pieceId++, x: 525 - 12 * ci, y: 445 + pi * 44, rotate: 90, color: containerColor.toString() });
break;
case ShipPosition.Island:
this.containers.push({ id: pieceId++, x: 825 - 12 * ci, y: 445 + pi * 44, rotate: 90, color: containerColor.toString() });
break;
case ShipPosition.Player0:
this.containers.push({ id: pieceId++, x: 31 + 62 * (pi - 1), y: 320 + 12 * ci, rotate: 0, color: containerColor.toString() });
break;
case ShipPosition.Player1:
this.containers.push({ id: pieceId++, x: 281 + 62 * (pi > 1 ? pi - 1 : pi), y: 320 + 12 * ci, rotate: 0, color: containerColor.toString() });
break;
case ShipPosition.Player2:
this.containers.push({ id: pieceId++, x: 531 + 62 * (pi > 2 ? pi - 1 : pi), y: 320 + 12 * ci, rotate: 0, color: containerColor.toString() });
break;
case ShipPosition.Player3:
this.containers.push({ id: pieceId++, x: 781 + 62 * (pi > 3 ? pi - 1 : pi), y: 320 + 12 * ci, rotate: 0, color: containerColor.toString() });
break;
case ShipPosition.Player4:
this.containers.push({ id: pieceId++, x: 1031 + 62 * (pi > 4 ? pi - 1 : pi), y: 320 + 12 * ci, rotate: 0, color: containerColor.toString() });
break;
}
lastColor = container.color;
});
});
if (this.G?.containersLeft) {
let c = 0;
let lastColor;
this.G?.containersLeft.sort().forEach(containerColor => {
if (lastColor !== containerColor) {
this.G?.containersLeft.sort().forEach(container => {
if (lastColor !== container.color) {
c = 0;
}
const offset = 120 * Object.values(ContainerColor).indexOf(containerColor);
this.containers.push({ id: pieceId++, x: 10 + offset + 22 * (c % 5), y: 40 + Math.floor(c / 5) * 12, rotate: 0, color: containerColor.toString() });
lastColor = containerColor;
const offset = 120 * Object.values(ContainerColor).indexOf(container.color);
this.containers.push({
id: container.id,
x: 10 + offset + 22 * (c % 5),
y: 40 + Math.floor(c / 5) * 12,
rotate: 0,
color: container.color.toString(),
owner: -1,
state: ContainerState.OnBoard
});
lastColor = container.color;
c++
});
}
// Factories
this.factories = [];
this.factoriesBuilt = [];
this.G?.players.forEach((player, pi) => {
player.factories.forEach((factory, i) => {
this.factories.push({ id: pieceId++, x: 28 + pi * 250 + i * 48, y: 140, color: factory.toString() });
this.factoriesBuilt.push({ id: factory.id, x: 28 + pi * 250 + i * 48, y: 140, color: factory.color.toString() });
});
});
this.factories = [];
if (this.G?.factoriesLeft) {
let c = 0;
let lastColor;
this.G?.factoriesLeft.sort().forEach(containerColor => {
if (lastColor !== containerColor) {
this.G?.factoriesLeft.sort().forEach(factory => {
if (lastColor !== factory.color) {
c = 0;
}
const offset = 120 * Object.values(ContainerColor).indexOf(containerColor);
this.factories.push({ id: pieceId++, x: 20 + offset + 22 * (c % 5), y: 20 + Math.floor(c / 5) * 12, color: containerColor.toString() });
lastColor = containerColor;
const offset = 120 * Object.values(ContainerColor).indexOf(factory.color);
this.factories.push({ id: factory.id, x: 20 + offset + 22 * (c % 5), y: 20 + Math.floor(c / 5) * 12, color: factory.color.toString() });
lastColor = factory.color;
c++
});
}
// Warehouses
this.warehouses = [];
this.warehousesBuilt = [];
this.G?.players.forEach((player, pi) => {
for (let c = 0; c < player.warehouses; c++) {
this.warehouses.push({ id: pieceId++, x: 13 + pi * 250 + c * 48, y: 210 });
for (let c = 0; c < player.warehouses.length; c++) {
this.warehousesBuilt.push({ id: player.warehouses[c].id, x: 13 + pi * 250 + c * 48, y: 210 });
}
});
this.warehouses = [];
if (this.G?.warehousesLeft) {
for (let c = 0; c < this.G.warehousesLeft; c++) {
this.warehouses.push({ id: pieceId++, x: 620 + 32 * (c % 13), y: 15 + Math.floor(c / 13) * 32 });
for (let c = 0; c < this.G.warehousesLeft.length; c++) {
this.warehouses.push({ id: this.G.warehousesLeft[c].id, x: 620 + 32 * (c % 13), y: 15 + Math.floor(c / 13) * 32 });
}
}
// Loan Cards
this.loanCards = [];
this.G?.players.forEach((player, pi) => {
for (let c = 0; c < player.loans; c++) {
this.loanCards.push({ id: pieceId++, x: 205 + pi * 250 + c * 5, y: 130 - c * 15 });
}
player.loans.forEach((loan, c) => {
this.loanCards.push({ id: loan.id, x: 205 + pi * 250 + c * 7, y: 135 - c * 7, owner: player.id });
});
});
this.loanCards.push({ id: pieceId++, x: 1050, y: 15 });
this.G?.loansLeft.forEach(loan => {
this.loanCards.push({ id: loan.id, x: 1050, y: 15, owner: -1 });
});
// Ships
this.ships = [];
@ -479,31 +426,31 @@ export default class Game extends Vue {
const color = ["dodgerblue", "red", "yellow", "limegreen", "mediumorchid"][pi];
switch (player.ship.shipPosition) {
case ShipPosition.OpenSea:
this.ships.push({ id: pieceId++, x: 500, y: 410 + pi * 44, rotate: 90, color });
this.ships.push({ id: player.ship.piece.id, x: 500, y: 410 + pi * 44, rotate: 90, color, containers: player.ship.containers, owner: pi });
break;
case ShipPosition.Island:
this.ships.push({ id: pieceId++, x: 800, y: 410 + pi * 44, rotate: 90, color });
this.ships.push({ id: player.ship.piece.id, x: 800, y: 410 + pi * 44, rotate: 90, color, containers: player.ship.containers, owner: pi });
break;
case ShipPosition.Player0:
this.ships.push({ id: pieceId++, x: 26 + 62 * (pi - 1), y: 305, rotate: 0, color });
this.ships.push({ id: player.ship.piece.id, x: 26 + 62 * (pi - 1), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
break;
case ShipPosition.Player1:
this.ships.push({ id: pieceId++, x: 276 + 62 * (pi > 1 ? pi - 1 : pi), y: 305, rotate: 0, color });
this.ships.push({ id: player.ship.piece.id, x: 276 + 62 * (pi > 1 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
break;
case ShipPosition.Player2:
this.ships.push({ id: pieceId++, x: 526 + 62 * (pi > 2 ? pi - 1 : pi), y: 305, rotate: 0, color });
this.ships.push({ id: player.ship.piece.id, x: 526 + 62 * (pi > 2 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
break;
case ShipPosition.Player3:
this.ships.push({ id: pieceId++, x: 776 + 62 * (pi > 3 ? pi - 1 : pi), y: 305, rotate: 0, color });
this.ships.push({ id: player.ship.piece.id, x: 776 + 62 * (pi > 3 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
break;
case ShipPosition.Player4:
this.ships.push({ id: pieceId++, x: 1026 + 62 * (pi > 4 ? pi - 1 : pi), y: 305, rotate: 0, color });
this.ships.push({ id: player.ship.piece.id, x: 1026 + 62 * (pi > 4 ? pi - 1 : pi), y: 305, rotate: 0, color, containers: player.ship.containers, owner: pi });
break;
}
});
@ -517,6 +464,7 @@ export default class Game extends Vue {
if (!this.G) {
return [];
}
return range(0, this.G.players.length).filter(pl => pl !== (this.player || 0));
}
@ -524,58 +472,11 @@ export default class Game extends Vue {
return !!this.G?.players[player]?.availableMoves;
}
onContainerDrop(container: ContainerColor, { player, row, rowPos, autoChooseRow }: { player?: number; row?: number; rowPos?: number; autoChooseRow?: boolean }) {
console.log("card drop");
if (this.player === undefined || (player !== undefined && player !== this.player)) {
return;
}
const commands = this.G!.players[this.player].availableMoves!;
if (!commands) {
return;
}
if (this.G!.log.length !== this._futureState!.log.length) {
return;
}
this.G!.players[this.player].availableMoves = null;
console.log(player, row, rowPos, autoChooseRow);
// if (player !== undefined && !autoChooseRow) {
// this._futureState!.log.push({
// player: this.player!,
// type: "move",
// move: { name: MoveName.ChooseCard, data: card },
// });
// this.emitter.emit("move", {
// name: MoveName.ChooseCard,
// data: card,
// });
// } else {
// this._futureState!.log.push({
// player: this.player!,
// type: "move",
// move: {
// name: MoveName.PlaceCard,
// data: commands.placeCard!.find((item) => item.row === row)!,
// },
// });
// this.emitter.emit("move", {
// name: MoveName.PlaceCard,
// data: commands.placeCard!.find((item) => item.row === row),
// });
// }
this.updateUI();
}
loadAvailableMoves(availableMoves: AvailableMoves[]) {
for (let i = 0; i < availableMoves.length; i++) {
this.G!.players[i].availableMoves = availableMoves[i];
}
this._pendingAvailableMoves = null;
}
@ -616,95 +517,45 @@ export default class Game extends Vue {
this.delay(1);
switch (logItem.type) {
case "phase":
return;
case "move": {
const { player, move } = logItem;
case "phase": {
const { phase } = logItem;
console.log("phase", phase);
switch (phase) {
case Phase.Setup: {
this.queueAnimation(() => {
console.log("delaying");
this.delay(200);
});
switch (move.name) {
// case MoveName.ChooseCard: {
// console.log("choosing card", player);
// this.G!.players[player].faceDownCard = move.data;
for (let i = 0; i < this.G!.players.length; i++) {
this.queueAnimation(() => {
this.G?.players[i].warehouses.push(this.G?.warehousesLeft.pop()!);
this.createPieces();
});
}
// this.delay(200);
return;
}
// if (player === (this.player || 0)) {
// this.G!.players[this.player!].hand = this.handCards!.filter(card => card.number !== move.data.number);
// } else {
// this.G!.players[player].hand.shift();
// }
// return;
// }
// case MoveName.PlaceCard: {
// console.log("placing card", player);
// const card = this.G!.players[player].faceDownCard!;
// this.G!.players[player].faceDownCard = null;
// if (move.data.replace) {
// // put new card on 6th spot
// this.G!.rows[move.data.row][5] = card;
// this.G!.rows = [...this.G!.rows];
// this.queueAnimation(() => {
// console.log("delaying before taking row");
// this.delay(200);
// });
// this.queueAnimation(() => {
// console.log("Taking row");
// this.G!.players[player].points += sumBy(
// this.G!.rows[move.data.row].slice(0, 5),
// "points"
// );
// this.G!.rows[move.data.row] = [];
// this.G!.rows[move.data.row][5] = card;
// this.G!.rows = [...this.G!.rows];
// console.log("delaying after taking row");
// this.delay(300);
// });
// // Then move card to correct spot
// this.queueAnimation(() => {
// this.G!.rows[move.data.row] = [card];
// this.G!.rows = [...this.G!.rows];
// });
// } else {
// this.G!.rows[move.data.row].push(card);
// this.G!.rows = [...this.G!.rows];
// }
// return;
// }
default:
return;
}
}
case "move": {
const { player, move } = logItem;
console.log("move", player, move);
switch (move.name) {
default:
return;
}
}
case "event": {
const { event } = logItem;
console.log("event", event);
switch (event.name) {
// case GameEventName.RevealCards: {
// const cards = event.cards;
// for (let player = 0; player < cards.length; player++) {
// this.G!.players[player].faceDownCard =
// cards[player];
// }
// this.delay(200);
// return;
// }
// case GameEventName.RoundStart: {
// console.log(JSON.parse(JSON.stringify(event)));
// this.G!.rows = event.cards.board.map((card) => [
// card,
// ]) as [ICard[], ICard[], ICard[], ICard[]];
// for (let i = 0; i < this.G!.players.length; i++) {
// this.G!.players[i].hand = event.cards.players[i];
// }
// return;
// }
default:
return;
}
@ -728,11 +579,202 @@ export default class Game extends Vue {
_pendingAvailableMoves: { index: number; availableMoves: AvailableMoves[]; } | null = null;
animationQueue: Array<Function> = [];
pass() {
this.emitter.emit("move", { name: MoveName.Pass, data: true });
}
undo() {
this.emitter.emit("move", { name: MoveName.Undo, data: true });
}
loan(event) {
const loan = event as LoanCard;
if (loan.owner == -1) {
this.emitter.emit("move", { name: MoveName.GetLoan, data: true });
} else if (loan.owner == this.G?.currentPlayer) {
this.emitter.emit("move", { name: MoveName.PayLoan, data: true });
}
}
bid(event) {
this.emitter.emit("move", { name: MoveName.Bid, data: true, extraData: { price: event } });
}
accept(bidder) {
this.emitter.emit("move", { name: MoveName.Accept, data: bidder });
}
decline() {
this.emitter.emit("move", { name: MoveName.Decline, data: true });
}
onPieceDrop(e: PieceComponent, d: any) {
switch (e.pieceType) {
case PieceType.Warehouse:
this.sendMove({ name: MoveName.BuyWarehouse, data: true, extraData: { id: e.pieceId } });
break;
case PieceType.Factory:
const factory = e as Factory;
this.sendMove({ name: MoveName.BuyFactory, data: factory.color, extraData: { id: factory.pieceId, color: factory.color } });
break;
case PieceType.Container:
const container = e as Container;
if (container.state == ContainerState.OnBoard) {
this.sendMove({ name: MoveName.Produce, data: container.color, extraData: { piece: { id: container.pieceId, color: container.color }, price: d.price } });
} else if (container.state == ContainerState.OnFactoryStore) {
if (d.type == DropZoneType.FactoryStore) {
this.sendMove({ name: MoveName.ArrangeFactory, data: { id: container.pieceId, color: container.color }, extraData: { price: d.price } });
} else if (d.type == DropZoneType.WarehouseStore) {
this.sendMove({ name: MoveName.BuyFromFactory, data: { player: container.owner, piece: { id: container.pieceId, color: container.color } }, extraData: { price: d.price } });
}
} else if (container.state == ContainerState.OnWarehouseStore) {
if (d.type == DropZoneType.WarehouseStore) {
this.sendMove({ name: MoveName.ArrangeWarehouse, data: { id: container.pieceId, color: container.color }, extraData: { price: d.price } });
} else if (d.type == DropZoneType.Ship) {
this.sendMove({ name: MoveName.BuyFromWarehouse, data: { player: container.owner, piece: { id: container.pieceId, color: container.color } } });
}
}
break;
case PieceType.Ship:
if (d.type === DropZoneType.PlayerHarbour) {
this.sendMove({ name: MoveName.Sail, data: "player" + d.owner });
} else if (d.type === DropZoneType.OpenSea) {
this.sendMove({ name: MoveName.Sail, data: ShipPosition.OpenSea });
} else if (d.type === DropZoneType.IslandHarbor) {
this.sendMove({ name: MoveName.Sail, data: ShipPosition.Island });
}
break;
case PieceType.Loan:
const loan = e as LoanCard;
if (loan.owner == -1 && d.type == DropZoneType.GetLoan) {
this.sendMove({ name: MoveName.GetLoan, data: true });
} else if (loan.owner !== -1 && d.type == DropZoneType.PayLoan) {
this.sendMove({ name: MoveName.PayLoan, data: true });
}
break;
}
this.updateUI();
}
sendMove(move) {
console.log("send move", move);
this.emitter.emit("move", move);
}
gameEnded(G: GameState) {
return ended(G);
}
canDragContainer(container: Piece) {
if (this.G?.currentPlayer == undefined)
return false;
const currentPlayer = this.G.players[this.G.currentPlayer];
if (!currentPlayer)
return false;
const availableMoves = currentPlayer.availableMoves;
if (!availableMoves)
return false;
switch (container.state) {
case ContainerState.OnBoard: {
const available = availableMoves[MoveName.Produce];
return available && available.indexOf(container.color as ContainerColor) != -1 && currentPlayer.produced.indexOf(container.color as ContainerColor) == -1;
}
case ContainerState.OnFactoryStore: {
if (container.owner == currentPlayer.id) {
return availableMoves[MoveName.ArrangeFactory] != undefined;
} else {
const available = availableMoves[MoveName.BuyFromFactory];
return available && available.find(a => a.piece.id == container.id);
}
}
case ContainerState.OnWarehouseStore: {
if (container.owner == currentPlayer.id) {
return availableMoves[MoveName.ArrangeWarehouse] != undefined;
} else {
const available = availableMoves[MoveName.BuyFromWarehouse];
return available && available.find(a => a.piece.id == container.id);
}
}
case ContainerState.OnShip:
case ContainerState.OnIsland:
default:
return false;
}
}
canDragFactory(factory: Piece) {
if (this.G?.currentPlayer == undefined)
return false;
const currentPlayer = this.G.players[this.G.currentPlayer];
if (!currentPlayer)
return false;
const availableMoves = currentPlayer.availableMoves;
if (!availableMoves)
return false;
const available = availableMoves[MoveName.BuyFactory];
return available && available.find(a => a == factory.color);
}
canDragWarehouse() {
if (this.G?.currentPlayer == undefined)
return false;
const currentPlayer = this.G.players[this.G.currentPlayer];
if (!currentPlayer)
return false;
const availableMoves = currentPlayer.availableMoves;
if (!availableMoves)
return false;
return availableMoves[MoveName.BuyWarehouse] != undefined;
}
canDragLoan(loanCard: Piece) {
if (this.G?.currentPlayer == undefined)
return false;
const currentPlayer = this.G.players[this.G.currentPlayer];
if (!currentPlayer)
return false;
const availableMoves = currentPlayer.availableMoves;
if (!availableMoves)
return false;
if (loanCard.owner == -1) {
return availableMoves[MoveName.GetLoan] != undefined;
} else if (loanCard.owner == currentPlayer.id) {
return availableMoves[MoveName.PayLoan] != undefined;
}
return false;
}
}
</script>
<style lang="scss">
.game {
background-color: white;
height: 100%;;
background-color: lightblue;
display: flex;
align-items: center;
flex-direction: column;
@ -755,5 +797,11 @@ text {
font-family: "Arial";
pointer-events: none;
dominant-baseline: central;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>

View file

@ -1,24 +0,0 @@
<template>
<g :class="['game-info']"> >
<text>Round: {{round}}</text>
</g>
</template>
<script lang="ts">
import {Vue, Component, Prop, Watch} from "vue-property-decorator";
@Component
export default class GameInfo extends Vue {
@Prop()
round?: number;
}
</script>
<style lang="scss">
.game-info {
text {
font-size: 12px;
}
}
</style>

View file

@ -1,5 +1,5 @@
<template>
<g>
<g :class="['loan', {dragging}, {canDrag}]" :id="elId" :transform="`translate(${currentX}, ${currentY})`" @fastClick="onClick">
<rect width="30" height="60" fill="royalblue" stroke="white" stroke-width="2" rx="2"></rect>
<g transform="translate(33, -10) rotate(280, 15, 30)">
<text text-anchor="middle" fill="white">Loan</text>
@ -7,9 +7,50 @@
</g>
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import { PieceType } from "@/types/ui-data";
import { Component, Mixins, Prop } from "vue-property-decorator";
import Piece from "./Piece.vue";
@Component
export default class LoanCard extends Vue {
@Component({
created(this: LoanCard) {
this.pieceType = PieceType.Loan;
}
})
export default class LoanCard extends Mixins(Piece) {
@Prop()
owner?: number;
@Prop()
player?: number;
onClick() {
console.log("click", this.owner);
if (this.owner == -1) {
this.$emit('click', 'getLoan');
} else if (this.owner == this.player) {
this.$emit('click', 'payLoan');
}
}
}
</script>
<style lang="scss">
.loan {
&:not(.dragging) {
transition-property: transform;
transition-duration: 0.8s;
transition-timing-function: ease-in-out;
}
&.canDrag {
cursor: pointer;
rect {
&:hover {
stroke: white;
}
}
}
}
</style>

128
src/components/Piece.vue Normal file
View file

@ -0,0 +1,128 @@
<script lang="ts">
import { Component, Inject, Prop, Watch } from "vue-property-decorator";
import Draggable from "./Draggable.vue";
import { EventEmitter } from 'events';
import { PieceType, UIData } from "@/types/ui-data";
@Component({
created(this: Piece) {
this.$on("draggedTo", (coords: { x: number, y: number }) => {
[this.currentX, this.currentY] = [coords.x, coords.y];
this.$nextTick(() => {
this.communicator.emit("draggedPosChanged", this);
});
});
},
mounted(this: Piece) {
this.mounted = true;
},
beforeDestroy(this: Piece) {
this.onTransitionEnd();
}
})
export default class Piece extends Draggable {
@Prop({ default: () => ({ x: 20, y: 20, rotate: 0 }) })
targetState!: {
x: number,
y: number,
rotate: number
};
@Prop()
pieceId!: number;
@Inject()
readonly communicator!: EventEmitter;
@Inject()
readonly ui!: UIData;
public pieceType!: PieceType;
currentX = 0;
currentY = 0;
rotate = 0;
mounted = false;
transitioning = false;
transitionCount = 0;
moving = false;
startTransitioning() {
if (this.transitioning) {
return;
}
this.ui.waitingAnimations += 1;
this.transitioning = true;
this.transitionCount += 1;
const count = this.transitionCount;
// Safeguard to make sure even if we don't catch the transition end event, we stop the transition
setTimeout(() => {
if (count === this.transitionCount) {
this.onTransitionEnd();
}
}, 1000);
}
@Watch("dragging")
@Watch("targetState", { immediate: true })
onTargetChanged(newVal: boolean, oldVal: boolean) {
if (this.dragging) {
return;
}
if (this.targetState.x === this.currentX && this.targetState.y === this.currentY) {
return;
}
if (!this.transitioning && this.mounted) {
if (!(oldVal && !newVal)) {
this.startTransitioning();
} else {
this.moving = true;
setTimeout(() => this.moving = false, 800);
}
}
if (!this.mounted) {
this.currentX = this.targetState.x;
this.currentY = this.targetState.y;
this.rotate = this.targetState.rotate;
} else {
// Make sure the animation plays by waiting until the class "dragging" is removed for sure from the element
setTimeout(() => {
this.currentX = this.targetState.x;
this.currentY = this.targetState.y;
this.rotate = this.targetState.rotate;
});
}
}
@Watch("dragging")
onDraggingChanged() {
if (this.dragging) {
this.ui.dragged = this;
} else {
this.ui.dragged = null;
this.communicator.emit("draggedPosChanged", this);
}
}
onTransitionEnd() {
console.log("on transition end", this.transitioning);
if (this.transitioning) {
this.transitioning = false;
this.ui.waitingAnimations = Math.max(this.ui.waitingAnimations - 1, 0);
}
}
get elId() {
return this.dragging ? 'dragged' : (this.transitioning || this.moving ? 'moving' : undefined);
}
}
</script>

View file

@ -1,13 +1,19 @@
<template>
<g>
<g class="player-board">
<rect width="250" height="20" x="0" y="0" :fill="color"></rect>
<text x="5" y="10" font-weight="600" fill="black">{{ name }}</text>
<text x="5" y="10" font-weight="600" fill="black" :text-decoration="currentPlayer ? 'underline' : ''">{{ getPlayerName() }}</text>
<rect width="250" height="180" x="0" y="20" fill="gray"></rect>
<DropZone :transform="`translate(60, 200)`" :width="149" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor', owner: owner }" />
<rect width="20" height="80" x="0" y="200" fill="gray"></rect>
<rect width="20" height="80" x="62" y="200" fill="gray"></rect>
<rect width="20" height="80" x="124" y="200" fill="gray"></rect>
<rect width="20" height="80" x="186" y="200" fill="gray"></rect>
<DropZone :transform="`translate(200, 25)`" :width="40" :height="70" :enabled="currentPlayer" :accepts="'loan'" :data="{ type: 'getLoan' }" />
<DropZone :transform="`translate(13, 25)`" :width="174" :height="30" :enabled="currentPlayer" :accepts="'factory'" />
<circle r="14" cx="28" cy="40" fill="none" stroke="lightgray"></circle>
<text text-anchor="middle" x="28" y="40" fill="lightgray">-</text>
<circle r="14" cx="76" cy="40" fill="none" stroke="lightgray"></circle>
@ -16,16 +22,21 @@
<text text-anchor="middle" x="124" y="40" fill="lightgray">9</text>
<circle r="14" cx="172" cy="40" fill="none" stroke="lightgray"></circle>
<text text-anchor="middle" x="171" y="40" fill="lightgray">12</text>
<DropZone :transform="`translate(12, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 1 }" />
<rect x="8" y="60" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="28" y="90" fill="lightgray">1</text>
<DropZone :transform="`translate(60, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 2 }" />
<rect x="56" y="60" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="76" y="90" fill="lightgray">2</text>
<DropZone :transform="`translate(108, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 3 }" />
<rect x="104" y="60" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="124" y="90" fill="lightgray">3</text>
<DropZone :transform="`translate(156, 64)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'factoryStore', price: 4 }" />
<rect x="152" y="60" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="172" y="90" fill="lightgray">4</text>
<DropZone :transform="`translate(7, 104)`" :width="234" :height="42" :enabled="currentPlayer" :accepts="'warehouse'" />
<rect x="8" y="105" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="28" y="125" fill="lightgray">-</text>
<rect x="56" y="105" width="40" height="40" fill="none" stroke="lightgray"></rect>
@ -37,27 +48,69 @@
<rect x="200" y="105" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="220" y="125" fill="lightgray">7</text>
<DropZone :transform="`translate(12, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 2 }" />
<rect x="8" y="150" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="28" y="180" fill="lightgray">2</text>
<DropZone :transform="`translate(60, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 3 }" />
<rect x="56" y="150" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="76" y="180" fill="lightgray">3</text>
<DropZone :transform="`translate(108, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 4 }" />
<rect x="104" y="150" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="124" y="180" fill="lightgray">4</text>
<DropZone :transform="`translate(156, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 5 }" />
<rect x="152" y="150" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="172" y="180" fill="lightgray">5</text>
<DropZone :transform="`translate(204, 154)`" :width="32" :height="32" :enabled="currentPlayer" :accepts="'container'" :data="{ type: 'warehouseStore', price: 6 }" />
<rect x="200" y="150" width="40" height="40" fill="none" stroke="lightgray"></rect>
<text text-anchor="middle" x="220" y="180" fill="lightgray">6</text>
</g>
</template>
<script lang="ts">
import { Player } from "container-engine";
import { Vue, Component, Prop } from "vue-property-decorator";
import DropZone from "./DropZone.vue";
@Component
@Component({
components: {
DropZone,
}
})
export default class PlayerBoard extends Vue {
@Prop()
color?: string;
@Prop()
name?: string;
player!: Player;
@Prop()
currentPlayer?: boolean;
@Prop()
owner?: number;
@Prop()
ended?: boolean;
onPieceDrop(e) {
this.$emit("pieceDrop", e);
}
getPlayerName() {
let name = '';
if (this.currentPlayer) {
name += '• ';
}
name += this.player.name;
if (this.player.showBid) {
name += ' (Bid: $' + (this.player.bid + this.player.additionalBid) + ')';
} else if (this.ended) {
name += ' (Score: $' + (this.player.money) + ')';
}
return name;
}
}
</script>
</script>

View file

@ -1,53 +0,0 @@
<template>
<g :class="['player-label', {main}]">
<text style="filter: url(#shadow); fill: white" class="shadow" >{{player.name || `Player ${playerIndex + 1}`}}</text>
<text class="player-name">{{player.name || `Player ${playerIndex + 1}`}}</text>
<text class="points" :y="main ? 13 : 11.5" style="stroke: #ffffff33;">{{player.points}}</text>
<text class="points" :y="main ? 13 : 11.5">{{player.points}}</text>
</g>
</template>
<script lang="ts">
import {Vue, Component, Prop, Watch} from "vue-property-decorator";
import type {Player} from "container-engine";
@Component
export default class PlayerLabel extends Vue {
@Prop({default: false})
main!: boolean;
@Prop()
player!: Player;
@Prop()
playerIndex!: number;
}
</script>
<style lang="scss">
.player-label {
&.main {
fill: orange;
}
&.main .player-name {
font-size: 12px;
}
&.main .shadow {
font-size: 12px;
opacity: 0.4;
}
.player-name, .shadow {
font-size: 11px;
}
.shadow {
opacity: 0.2;
}
.points {
font-size: 10px;
}
}
</style>

View file

@ -1,16 +1,21 @@
<template>
<g>
<rect width="100" height="160" fill="silver" stroke="white" stroke-width="2" rx="2"></rect>
<rect x="20" y="15" width="20" height="10" :fill="pointCard.containerValues[0].containerColor" stroke="black"></rect>
<text x="70" y="20" text-anchor="middle">10</text>
<rect x="20" y="45" width="20" height="10" :fill="pointCard.containerValues[1].containerColor" stroke="black"></rect>
<text x="70" y="50" text-anchor="middle">5/10</text>
<rect x="20" y="75" width="20" height="10" :fill="pointCard.containerValues[2].containerColor" stroke="black"></rect>
<text x="70" y="80" text-anchor="middle">6</text>
<rect x="20" y="105" width="20" height="10" :fill="pointCard.containerValues[3].containerColor" stroke="black"></rect>
<text x="70" y="110" text-anchor="middle">4</text>
<rect x="20" y="135" width="20" height="10" :fill="pointCard.containerValues[4].containerColor" stroke="black"></rect>
<text x="70" y="140" text-anchor="middle">2</text>
<g class="point-card" @click="turned = !turned">
<g v-if="turned">
<rect width="100" height="160" fill="dimgray" stroke="white" stroke-width="2" rx="2"></rect>
</g>
<g v-else>
<rect width="100" height="160" fill="silver" stroke="white" stroke-width="2" rx="2"></rect>
<rect x="20" y="15" width="20" height="10" :fill="pointCard.containerValues[0].containerColor" stroke="black"></rect>
<text x="70" y="20" text-anchor="middle">10</text>
<rect x="20" y="45" width="20" height="10" :fill="pointCard.containerValues[1].containerColor" stroke="black"></rect>
<text x="70" y="50" text-anchor="middle">5/10</text>
<rect x="20" y="75" width="20" height="10" :fill="pointCard.containerValues[2].containerColor" stroke="black"></rect>
<text x="70" y="80" text-anchor="middle">6</text>
<rect x="20" y="105" width="20" height="10" :fill="pointCard.containerValues[3].containerColor" stroke="black"></rect>
<text x="70" y="110" text-anchor="middle">4</text>
<rect x="20" y="135" width="20" height="10" :fill="pointCard.containerValues[4].containerColor" stroke="black"></rect>
<text x="70" y="140" text-anchor="middle">2</text>
</g>
</g>
</template>
<script lang="ts">
@ -21,5 +26,14 @@ import type { PointCard as PointCardInfo } from "container-engine"
export default class PointCard extends Vue {
@Prop()
pointCard?: PointCardInfo;
turned = false;
}
</script>
<style lang="scss">
.point-card {
cursor: pointer;
}
</style>

View file

@ -1,19 +1,59 @@
<template>
<g>
<g :transform="'rotate(' + rotate + ', 15, 40)'">
<path d="M15 0 L30 10 L30 80 L0 80 L0 10Z" :fill="color" stroke="black"></path>
</g>
<g :class="['ship', {dragging}, {canDrag}]" :id="elId" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 15, 40)`">
<path d="M15 0 L30 10 L30 80 L0 80 L0 10Z" :fill="color" stroke="black"></path>
<template v-for="(container, i) in containers">
<Container :key="container.id"
:pieceId="container.id"
:targetState="{ x: 5, y: 15 + 12 * i, rotate: 0 }"
:canDrag="false"
:color="container.color" />
</template>
<DropZone :width="30" :height="80" :enabled="true" :accepts="'container'" :data="{ type: 'ship' }" />
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import { PieceType } from "@/types/ui-data";
import { ContainerPiece } from "container-engine/src/gamestate";
import { Component, Mixins, Prop } from "vue-property-decorator";
import Piece from "./Piece.vue";
import Container from "./Container.vue";
import DropZone from "./DropZone.vue";
@Component
export default class Warehouse extends Vue {
@Component({
created(this: Ship) {
this.pieceType = PieceType.Ship;
},
components: {
Container,
DropZone
}
})
export default class Ship extends Mixins(Piece) {
@Prop()
color?: string;
@Prop()
rotate?: number;
containers?: ContainerPiece[];
}
</script>
<style lang="scss">
.ship {
&:not(.dragging) {
transition-property: transform;
transition-duration: 0.8s;
transition-timing-function: ease-in-out;
}
&.canDrag {
cursor: pointer;
path {
&:hover {
stroke: white;
}
}
}
}
</style>

View file

@ -1,12 +1,39 @@
<template>
<g>
<g :class="['warehouse', {dragging}, {canDrag}]" :id="elId" :transform="`translate(${currentX}, ${currentY})`">
<path d="M15 0 L30 10 L30 30 L0 30 L0 10Z" fill="dimgray" stroke="black"></path>
</g>
</template>
<script lang="ts">
import { Vue, Component } from "vue-property-decorator";
import { PieceType } from "@/types/ui-data";
import { Component, Mixins } from "vue-property-decorator";
import Piece from "./Piece.vue";
@Component
export default class Warehouse extends Vue {
@Component({
created(this: Warehouse) {
this.pieceType = PieceType.Warehouse;
}
})
export default class Warehouse extends Mixins(Piece) {
}
</script>
<style lang="scss">
.warehouse {
&:not(.dragging) {
transition-property: transform;
transition-duration: 0.8s;
transition-timing-function: ease-in-out;
}
&.canDrag {
cursor: pointer;
path {
&:hover {
stroke: white;
}
}
}
}
</style>

3
src/icons/pass.svg Normal file
View file

@ -0,0 +1,3 @@
<svg width="40" height="40" xmlns="http://www.w3.org/2000/svg">
<path d="M0 0 L20 20 L0 40 Z M20 0 L40 20 L20 40 Z" />
</svg>

After

Width:  |  Height:  |  Size: 130 B

3
src/icons/undo.svg Normal file
View file

@ -0,0 +1,3 @@
<svg width="497.25px" height="497.25px" viewBox="0 0 497.25 497.25" xmlns="http://www.w3.org/2000/svg">
<path fill="black" d="M248.625,89.25 V0 l-127.5,127.5 l127.5,127.5 V140.25 c84.15,0,153,68.85,153,153 c0,84.15-68.85,153-153,153 c-84.15,0-153-68.85-153-153 h-51 c0,112.2,91.8,204,204,204 s204-91.8,204-204 S360.825,89.25,248.625,89.25z"/>
</svg>

After

Width:  |  Height:  |  Size: 354 B

View file

@ -3,9 +3,11 @@ import { setup, Move, move as execMove, stripSecret } from "container-engine";
import { cloneDeep } from "lodash";
function launchSelfContained(selector = "#app") {
const strip = false;
const emitter = launch(selector);
let gameState = setup(5, {});
let gameState = setup(3, {});
for (let i = 0; i < gameState.players.length; i++) {
gameState.players[i].name = `Player ${i + 1}`;
@ -13,26 +15,18 @@ function launchSelfContained(selector = "#app") {
emitter.on("move", async (move: Move) => {
console.log("move received", JSON.stringify(move));
const index = gameState.log.length;
gameState = execMove(gameState, move, 0);
gameState = execMove(gameState, move, gameState.currentPlayer!);
setTimeout(() =>
emitter.emit("gamelog", cloneDeep({
start: index,
data: {
log: stripSecret(gameState, 0).log.slice(index),
availableMoves: stripSecret(gameState, 0).players.map(pl => pl.availableMoves)
}
})), 200);
emitter.emit("state", cloneDeep(strip ? stripSecret(gameState, 0) : gameState));
});
emitter.on('fetchSate', () => emitter.emit("state", cloneDeep(stripSecret(gameState, 0))));
emitter.on('fetchSate', () => emitter.emit("state", cloneDeep(strip ? stripSecret(gameState, 0) : gameState)));
emitter.on('addLog', data => console.log('addLog', data));
emitter.on('replaceLog', data => console.log('replaceLog', data));
emitter.emit("player", { index: 0 });
emitter.emit("state", cloneDeep(stripSecret(gameState, 0)));
emitter.emit("state", cloneDeep(strip ? stripSecret(gameState, 0) : gameState));
}
export default launchSelfContained;

View file

@ -1,20 +1,49 @@
import type Card from '../components/Card.vue';
import type Placeholder from '../components/Placeholder.vue';
import { ContainerPiece } from 'container-engine/src/gamestate';
export interface UIData {
cards: { [key: number]: Card };
placeholders: {
rows: Placeholder[][];
players: Placeholder[];
};
dragged?: Vue | null;
waitingAnimations: number;
}
export interface Piece {
id: number;
id: string;
x: number;
y: number;
owner?: number;
color?: string;
rotate?: number;
state?: string;
}
export interface ShipType extends Piece {
containers: ContainerPiece[];
}
export enum PieceType {
Warehouse = "warehouse",
Factory = "factory",
Container = "container",
Ship = "ship",
Loan = "loan"
}
export enum DropZoneType {
Ship = "ship",
PlayerHarbour = "playerHarbor",
Factory = "factory",
FactoryStore = "factoryStore",
Warehouse = "warehouse",
WarehouseStore = "warehouseStore",
OpenSea = "openSea",
IslandHarbor = "islandHarbor",
GetLoan = "getLoan",
PayLoan = "payLoan"
}
export enum ContainerState {
OnBoard = "onBoard",
OnFactoryStore = "onFactoryStore",
OnWarehouseStore = "onWarehouseStore",
OnShip = "onShip",
OnIsland = "onIsland"
}