Merge remote-tracking branch 'viewer/master'

This commit is contained in:
coyotte508 2021-07-03 21:26:21 +02:00
commit 1780a2f9fc
52 changed files with 20668 additions and 65 deletions

3
.browserslistrc Normal file
View file

@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead

5
.editorconfig Normal file
View file

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

View file

@ -1,37 +1,26 @@
module.exports = {
root: true,
extends: ["eslint:recommended", "plugin:vue/recommended"],
rules: {
"vue/no-unused-vars": "error",
"vue/html-indent": ["error", 4, { alignAttributesVertically: false }],
"vue/max-attributes-per-line": 0,
"vue/html-closing-bracket-newline": [
"error",
{
singleline: "never",
multiline: "never",
},
],
"vue/attribute-hyphenation": ["error", "never"],
"vue/singleline-html-element-content-newline": "off",
"no-case-declarations": "off",
"no-unused-vars": "off",
quotes: ["error", "single"],
},
env: {
node: true
node: true,
},
parserOptions: {
ecmaVersion: 2020
parser: "@typescript-eslint/parser",
},
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
semi: ['error', 'always'],
'@typescript-eslint/no-non-null-assertion': 'off',
// '@typescript-eslint/consistent-type-assertions': 'off',
// '@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unused-vars': ["warn", { "argsIgnorePattern": "^_" }],
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-namespace': 'off',
'no-inner-declarations': 'off',
'no-return-assign': 'off',
// 'no-fallthrough': 'off',
quotes: 'off',
'no-empty': 'off',
'quotes': ['error', 'single']
}
};

21
.gitignore vendored
View file

@ -1,2 +1,21 @@
.DS_Store
node_modules
/dist
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View file

@ -1,4 +0,0 @@
language: node_js
node_js:
- node

36
.vscode/launch.json vendored
View file

@ -2,33 +2,15 @@
"version": "0.2.0",
"configurations": [
{
"type": "node",
"type": "chrome",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"--require",
"ts-node/register",
"--reporter",
"dot",
"--slow",
"5000",
"--colors",
"${workspaceFolder}/src/*.spec.ts",
],
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": [
"<node_internals>/**"
]
},
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.js"
"name": "vuejs: chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
}
]
}
}

17
.vscode/settings.json vendored
View file

@ -1,3 +1,16 @@
{
"editor.formatOnSave": true
}
"editor.tabSize": 4,
"editor.acceptSuggestionOnCommitCharacter": false,
"editor.formatOnSave": true,
"editor.suggestSelection": "first",
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
"vetur.format.options.tabSize": 4,
"vetur.format.defaultFormatter.js": "vscode-typescript",
"prettier.tabWidth": 4,
"files.trimTrailingWhitespace": true,
"vetur.format.defaultFormatter.html": "none",
"eslint.validate": ["javascript", "typescript", "vue"]
}

View file

@ -0,0 +1,12 @@
<template>
</template>
<script lang="ts">
import {Vue, Component, Prop, Watch} from "vue-property-decorator";
@Component
export default class $0 extends Vue {
}
</script>

29
README.md Normal file
View file

@ -0,0 +1,29 @@
# container-viewer
## Project setup
```
yarn install
```
### Compiles and hot-reloads for development
```
yarn serve
```
### Compiles and minifies for production
```
yarn build
```
### Run your unit tests
```
yarn test:unit
```
### Lints and fixes files
```
yarn lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

5
babel.config.js Normal file
View file

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

50
package.json Normal file
View file

@ -0,0 +1,50 @@
{
"name": "container-viewer",
"version": "1.0.14",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit",
"package": "vue-cli-service build --target lib src/wrapper.ts",
"prepublishOnly": "npm run package"
},
"dependencies": {
"container-engine": "workspace:../container-engine",
"core-js": "^3.6.5",
"lodash": "^4.17.19",
"regenerator-runtime": "^0.13.7",
"tslib": "^2.2.0",
"vue": "^2.6.11",
"vue-class-component": "^7.2.3",
"vue-property-decorator": "^8.4.2"
},
"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",
"@typescript-eslint/parser": "^4.26.1",
"@vue/cli-plugin-babel": "~4.4.0",
"@vue/cli-plugin-typescript": "~4.4.0",
"@vue/cli-plugin-unit-mocha": "~4.4.0",
"@vue/cli-service": "~4.4.0",
"@vue/test-utils": "^1.0.3",
"chai": "^4.1.2",
"eslint": "^7.28.0",
"eslint-plugin-vue": "^7.11.0",
"sass": "^1.26.5",
"sass-loader": "^8.0.2",
"typescript": "~3.9.9",
"vue-template-compiler": "^2.6.11"
},
"files": [
"src",
"dist/container-viewer.umd.min.js",
"dist/container-viewer.css",
"dist/img",
"dist/media",
"tsconfig.json",
"public/audio"
]
}

9445
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load diff

17
public/index.html Normal file
View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<!-- <link rel="icon" href="<%= BASE_URL %>favicon.ico">-->
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

BIN
src/audio/notification.mp3 Normal file

Binary file not shown.

BIN
src/audio/notification.ogg Normal file

Binary file not shown.

BIN
src/audio/piece-drop.mp3 Normal file

Binary file not shown.

View file

@ -0,0 +1,26 @@
<template>
<g :class="['button', { enabled }]" @click="enabled && $emit('click')">
<rect :width="width" height="30" fill="gainsboro" stroke="black" rx="2" />
<text text-anchor="middle" fill="black" :x="width / 2" y="16">{{ getText() }}</text>
<title>{{ text }}</title>
</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;
@Prop({ default: true })
enabled!: boolean;
getText() {
return this.text!.length > 15 ? this.text?.substring(0, 12).concat('...') : this.text;
}
}
</script>

View file

@ -0,0 +1,18 @@
<template>
<g class="button enabled" @click="$emit('click')">
<circle cx="15" cy="15" r="15" fill="gainsboro" stroke="black" stroke-width="2px" />
<image x="5" y="5" width="20" height="20" href="../../icons/help.svg" />
<line v-if="!isOn" x1="5" y1="25" x2="25" y2="5" stroke="black" stroke-width="3px" stroke-linecap="round" />
<title v-if="isOn">Help off</title>
<title v-else>Help on</title>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
@Component
export default class HelpButton extends Vue {
@Prop()
isOn?: boolean;
}
</script>

View file

@ -0,0 +1,15 @@
<template>
<g class="button enabled" @click="$emit('click')">
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
<image x="11" y="5" width="16" height="16" href="../../icons/log.svg" />
<text text-anchor="middle" fill="black" x="47" y="13">Log</text>
<title>Show log</title>
</g>
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
@Component
export default class LogButton extends Vue {
}
</script>

View file

@ -0,0 +1,17 @@
<template>
<g :class="['button', { enabled }]" @click="enabled && $emit('click')">
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
<image x="15" y="8" width="10" height="10" href="../../icons/pass.svg" />
<text text-anchor="middle" fill="black" x="47" y="13">Pass</text>
<title>Pass turn</title>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
@Component
export default class PassButton extends Vue {
@Prop()
enabled!: boolean;
}
</script>

View file

@ -0,0 +1,18 @@
<template>
<g class="button enabled" @click="$emit('click')">
<circle cx="15" cy="15" r="15" fill="gainsboro" stroke="black" stroke-width="2px" />
<image v-if="isOn" x="5" y="5" width="20" height="20" href="../../icons/sound-on.svg" />
<image v-else x="5" y="5" width="20" height="20" href="../../icons/sound-off.svg" />
<title v-if="isOn">Sound off</title>
<title v-else>Sound on</title>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
@Component
export default class SoundButton extends Vue {
@Prop()
isOn?: boolean;
}
</script>

View file

@ -0,0 +1,17 @@
<template>
<g :class="['button', { enabled }]" @click="enabled && $emit('click')">
<rect width="80" height="26" fill="gainsboro" stroke="black" rx="2" />
<image x="11" y="4" width="16" height="16" href="../../icons/undo.svg" />
<text text-anchor="middle" fill="black" x="47" y="13">Undo</text>
<title>Undo last move</title>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
@Component
export default class UndoButton extends Vue {
@Prop()
enabled!: boolean;
}
</script>

View file

@ -0,0 +1,8 @@
import Button from './Button.vue';
import HelpButton from './HelpButton.vue';
import LogButton from './LogButton.vue';
import PassButton from './PassButton.vue';
import SoundButton from './SoundButton.vue';
import UndoButton from './UndoButton.vue';
export { Button, HelpButton, LogButton, PassButton, SoundButton, UndoButton };

View file

@ -0,0 +1,66 @@
<template>
<g class="calculator">
<rect width="130" height="210" rx="2" />
<rect x="10" y="10" width="110" height="30" fill="yellowgreen" rx="2" />
<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)" />
<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)" />
<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)" />
<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)" />
<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)" />
<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)" />
<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)" />
<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)" />
<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)" />
<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)" />
<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()" />
<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()" />
<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>

176
src/components/DropZone.vue Normal file
View file

@ -0,0 +1,176 @@
<template>
<g :class="['placeholder', { showDrop }]">
<rect :width="width" :height="height" fill="black" />
<title v-if="data && data.type == 'playerHarbor'">Harbor</title>
<title v-else-if="data && data.type == 'factoryStore'">Factory Store</title>
<title v-else-if="data && data.type == 'warehouseStore'">Harbor Store</title>
<title v-else-if="data && data.type == 'factory'">Factory Slot</title>
<title v-else-if="data && data.type == 'warehouse'">Warehouse Slot</title>
<title v-else-if="data && data.type == 'supply'">Supply</title>
<title v-else-if="data && data.type == 'openSea'">Open Sea</title>
<title v-else-if="data && data.type == 'islandHarbor'">Island Harbor</title>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop, Watch, Inject, InjectReactive } from 'vue-property-decorator';
import { ContainerState, DropZoneType, PieceType, UIData } from '../types/ui-data';
import { EventEmitter, Listener } from 'events';
import Piece from './pieces/Piece.vue';
import { Ship, Container, LoanCard } from './pieces';
import { ShipPosition } from 'container-engine/src/gamestate';
@Component
export default class DropZone extends Vue {
@Inject()
readonly ui!: UIData;
@InjectReactive()
readonly player!: number;
@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.overlapping = false;
return;
}
if (!this.ui.dragged) {
if (this.overlapping) {
if (this.accepts?.indexOf(piece.pieceType) != -1) {
this.communicator.emit('pieceDrop', piece, this.data);
}
}
this.overlapping = false;
return;
}
if (!this.canDrop) {
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) {
if (this.communicator.listenerCount('draggedPosChanged') + 1 > this.communicator.getMaxListeners()) {
this.communicator.setMaxListeners(this.communicator.getMaxListeners() + 10);
}
this.communicator.on('draggedPosChanged', this.listener!);
} else {
this.communicator.off('draggedPosChanged', this.listener!);
}
}
get canDrop() {
if (!this.enabled || !this.ui.dragged || this.accepts?.indexOf(this.ui.dragged.pieceType) == -1)
return false;
if (this.ui.dragged.pieceType == PieceType.Loan) {
const loan = this.ui.dragged as LoanCard;
if (loan.owner == this.player) {
if (this.data.type == DropZoneType.GetLoan)
return false;
} else {
if (this.data.type == DropZoneType.PayLoan)
return false;
}
} else if (this.ui.dragged.pieceType == PieceType.Ship) {
const ship = this.ui.dragged as Ship;
if (ship.position == ShipPosition.OpenSea) {
if (this.data.type == DropZoneType.OpenSea)
return false;
if (this.data.type == DropZoneType.IslandHarbor && ship.containers?.length == 0)
return false;
if (this.data.owner == this.player)
return false;
} else {
if (this.data.type != DropZoneType.OpenSea)
return false;
}
} else if (this.ui.dragged.pieceType == PieceType.Container) {
const container = this.ui.dragged as Container;
if (container.state == ContainerState.OnBoard) {
if (this.data.type != DropZoneType.FactoryStore)
return false;
} else if (container.state == ContainerState.OnFactoryStore) {
if (container.owner == this.player) {
if (this.data.type != DropZoneType.FactoryStore && this.data.type != DropZoneType.Supply)
return false;
} else {
if (this.data.type != DropZoneType.WarehouseStore)
return false;
}
} else if (container.state == ContainerState.OnWarehouseStore) {
if (container.owner == this.player) {
if (this.data.type != DropZoneType.WarehouseStore && this.data.type != DropZoneType.Supply)
return false;
} else {
if (this.data.type != DropZoneType.Ship)
return false;
}
}
}
return true;
}
get showDrop() {
return this.ui.helpOn && this.canDrop;
}
}
</script>
<style lang="scss">
g.placeholder {
rect {
stroke: none;
fill: transparent;
}
&.showDrop {
rect {
stroke: blue;
stroke-width: 2px;
}
}
&.canClick {
cursor: pointer;
}
}
</style>

1084
src/components/Game.vue Normal file

File diff suppressed because it is too large Load diff

View file

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

View file

@ -0,0 +1,38 @@
<template>
<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" />
</g>
<g v-else>
<rect width="100" height="160" fill="silver" stroke="white" stroke-width="2" rx="2" />
<rect x="20" y="15" width="20" height="10" :fill="pointCard.containerValues[0].containerColor" stroke="black" />
<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" />
<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" />
<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" />
<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" />
<text x="70" y="140" text-anchor="middle">2</text>
</g>
</g>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator';
import type { PointCard as PointCardInfo } from 'container-engine'
@Component
export default class PointCard extends Vue {
@Prop()
pointCard?: PointCardInfo;
turned = false;
}
</script>
<style lang="scss">
.point-card {
cursor: pointer;
}
</style>

View file

@ -0,0 +1,37 @@
<template>
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`">
<filter id="my-filter">
<feComponentTransfer>
<feFuncR type="linear" slope="0.5" />
<feFuncG type="linear" slope="0.5" />
<feFuncB type="linear" slope="0.5" />
</feComponentTransfer>
</filter>
<rect width="20" height="10" :fill="color" stroke="black" />
<title>Container</title>
</g>
</template>
<script lang="ts">
import { ContainerState, PieceType } from '@/types/ui-data';
import { Component, Mixins, Prop } from 'vue-property-decorator';
import Piece from './Piece.vue';
@Component({
created(this: Container) {
this.pieceType = PieceType.Container;
}
})
export default class Container extends Mixins(Piece) {
@Prop()
color?: string;
@Prop()
owner?: number;
@Prop()
state?: ContainerState;
}
</script>

View file

@ -0,0 +1,107 @@
<script lang="ts">
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);
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.$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.$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 {
@Prop()
canDrag!: boolean;
dragging = false;
_offset = { x: 0, y: 0 };
_transform?: SVGTransform;
_dragStart?: number;
get svgElement() {
return document.querySelector('#scene') as SVGSVGElement;
}
get htmlElement() {
return this.$el as SVGGElement;
}
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
};
}
}
</script>

View file

@ -0,0 +1,23 @@
<template>
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
<circle r="10" :fill="color" stroke="black" />
<title>Factory</title>
</g>
</template>
<script lang="ts">
import { PieceType } from '@/types/ui-data';
import { Component, Mixins, Prop } from 'vue-property-decorator';
import Piece from './Piece.vue';
@Component({
created(this: Factory) {
this.pieceType = PieceType.Factory;
}
})
export default class Factory extends Mixins(Piece) {
@Prop()
color?: string;
}
</script>

View file

@ -0,0 +1,48 @@
<template>
<g :id="elId" :class="['loan', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
<rect width="30" height="60" fill="royalblue" stroke="white" stroke-width="2" rx="2" />
<g transform="translate(33, -10) rotate(280, 15, 30)">
<text text-anchor="middle" fill="white">Loan</text>
</g>
<title v-if="owner == -1">Get Loan</title>
<title v-else-if="owner == player">Pay Loan</title>
</g>
</template>
<script lang="ts">
import { PieceType } from '@/types/ui-data';
import { Component, Mixins, Prop } from 'vue-property-decorator';
import Piece from './Piece.vue';
@Component({
created(this: LoanCard) {
this.pieceType = PieceType.Loan;
}
})
export default class LoanCard extends Mixins(Piece) {
@Prop()
owner?: number;
@Prop()
player?: number;
}
</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>

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!: string;
@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

@ -0,0 +1,52 @@
<template>
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 15, 40)`">
<path d="M15 0 L30 10 L30 80 L0 80 L0 10Z" :fill="color" stroke="black" />
<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="player == owner" :accepts="'container'" :data="{ type: 'ship' }" />
<title>{{ ownerName }}'s Ship</title>
</g>
</template>
<script lang="ts">
import { PieceType } from '@/types/ui-data';
import { ContainerPiece, ShipPosition } from 'container-engine/src/gamestate';
import { Component, InjectReactive, Mixins, Prop } from 'vue-property-decorator';
import Piece from './Piece.vue';
import Container from './Container.vue';
import DropZone from '../DropZone.vue';
@Component({
created(this: Ship) {
this.pieceType = PieceType.Ship;
},
components: {
Container,
DropZone
}
})
export default class Ship extends Mixins(Piece) {
@InjectReactive()
readonly player!: number;
@Prop()
color?: string;
@Prop()
containers?: ContainerPiece[];
@Prop()
owner?: number;
@Prop()
ownerName?: string;
@Prop()
position!: ShipPosition;
}
</script>

View file

@ -0,0 +1,20 @@
<template>
<g :id="elId" :class="['piece', { dragging, canDrag }]" :transform="`translate(${currentX}, ${currentY})`">
<path d="M15 0 L30 10 L30 30 L0 30 L0 10Z" fill="dimgray" stroke="black" />
<title>Warehouse</title>
</g>
</template>
<script lang="ts">
import { PieceType } from '@/types/ui-data';
import { Component, Mixins } from 'vue-property-decorator';
import Piece from './Piece.vue';
@Component({
created(this: Warehouse) {
this.pieceType = PieceType.Warehouse;
}
})
export default class Warehouse extends Mixins(Piece) {
}
</script>

View file

@ -0,0 +1,8 @@
import Container from './Container.vue';
import Factory from './Factory.vue';
import LoanCard from './LoanCard.vue';
import Piece from './Piece.vue';
import Ship from './Ship.vue';
import Warehouse from './Warehouse.vue';
export { Container, Factory, LoanCard, Piece, Ship, Warehouse };

1
src/icons/help.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M14.601 21.5c0 1.38-1.116 2.5-2.499 2.5-1.378 0-2.499-1.12-2.499-2.5s1.121-2.5 2.499-2.5c1.383 0 2.499 1.119 2.499 2.5zm-2.42-21.5c-4.029 0-7.06 2.693-7.06 8h3.955c0-2.304.906-4.189 3.024-4.189 1.247 0 2.57.828 2.684 2.411.123 1.666-.767 2.511-1.892 3.582-2.924 2.78-2.816 4.049-2.816 7.196h3.943c0-1.452-.157-2.508 1.838-4.659 1.331-1.436 2.986-3.222 3.021-5.943.047-3.963-2.751-6.398-6.697-6.398z"/></svg>

After

Width:  |  Height:  |  Size: 499 B

1
src/icons/log.svg Normal file
View file

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M24 12c0 6.627-5.373 12-12 12s-12-5.373-12-12h2c0 5.514 4.486 10 10 10s10-4.486 10-10-4.486-10-10-10c-2.777 0-5.287 1.141-7.099 2.977l2.061 2.061-6.962 1.354 1.305-7.013 2.179 2.18c2.172-2.196 5.182-3.559 8.516-3.559 6.627 0 12 5.373 12 12zm-13-6v8h7v-2h-5v-6h-2z"/></svg>

After

Width:  |  Height:  |  Size: 364 B

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/sound-off.svg Normal file
View file

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M5 17h-5v-10h5v10zm2-10v10l9 5v-20l-9 5zm15.324 4.993l1.646-1.659-1.324-1.324-1.651 1.67-1.665-1.648-1.316 1.318 1.67 1.657-1.65 1.669 1.318 1.317 1.658-1.672 1.666 1.653 1.324-1.325-1.676-1.656z"/>
</svg>

After

Width:  |  Height:  |  Size: 302 B

3
src/icons/sound-on.svg Normal file
View file

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M5 17h-5v-10h5v10zm2-10v10l9 5v-20l-9 5zm17 4h-5v2h5v-2zm-1.584-6.232l-4.332 2.5 1 1.732 4.332-2.5-1-1.732zm1 12.732l-4.332-2.5-1 1.732 4.332 2.5 1-1.732z"/>
</svg>

After

Width:  |  Height:  |  Size: 261 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

32
src/launch.ts Normal file
View file

@ -0,0 +1,32 @@
import type { GameState, Move } from 'container-engine';
import { EventEmitter } from 'events';
import Vue from 'vue';
import Game from './components/Game.vue';
function launch(selector: string) {
let params: { state: null | GameState; player?: number; emitter: EventEmitter } = { state: null, emitter: new EventEmitter() };
const app = new Vue({
render: (h) => h(Game, { props: params }, [])
}).$mount(selector);
const item: EventEmitter = new EventEmitter();
params.emitter.on('move', (move: Move) => item.emit('move', move));
item.addListener('state', data => {
params.state = data;
app.$forceUpdate();
app.$nextTick().then(() => item.emit('ready'));
});
item.addListener('state:updated', () => item.emit('fetchState'));
item.addListener('player', data => {
params.player = data.index;
app.$forceUpdate();
});
item.addListener('gamelog', _ => item.emit('fetchState'));
return item;
}
export default launch;

3
src/main.ts Normal file
View file

@ -0,0 +1,3 @@
import launchSelfContained from './self-contained';
launchSelfContained();

58
src/self-contained.ts Normal file
View file

@ -0,0 +1,58 @@
import { move as execMove, Move, setup, stripSecret } from 'container-engine';
import { moveAI } from 'container-engine/src/engine';
import { cloneDeep } from 'lodash';
import launch from './launch';
function launchSelfContained(selector = '#app') {
const strip = false;
const emitter = launch(selector);
let gameState = setup(5, {});
for (let i = 0; i < gameState.players.length; i++) {
gameState.players[i].name = `Player ${i + 1}`;
}
const playerIndex = 1;
for (const player of gameState.players) {
if (player.id != playerIndex)
player.isAI = true;
}
emitter.on('move', async (move: Move) => {
console.log('move received', move);
gameState = execMove(gameState, move, playerIndex);
console.log('new game state', gameState);
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
let delay = 800;
while (gameState.players.some(pl => pl.isAI && pl.availableMoves)) {
gameState = moveAI(gameState, gameState.players.findIndex(pl => pl.isAI && pl.availableMoves));
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
setTimeout(() => emitter.emit('state', newState), delay);
delay += 800;
}
console.log('available moves', gameState.players[playerIndex].availableMoves);
});
emitter.on('fetchSate', () => emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState)));
emitter.emit('player', { index: playerIndex });
emitter.emit('state', cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState));
let delay = 800;
while (gameState.players.some(pl => pl.isAI && pl.availableMoves)) {
gameState = moveAI(gameState, gameState.players.findIndex(pl => pl.isAI && pl.availableMoves));
let newState = cloneDeep(strip ? stripSecret(gameState, playerIndex) : gameState);
setTimeout(() => emitter.emit('state', newState), delay);
delay += 800;
}
console.log('available moves', gameState.players[playerIndex].availableMoves);
}
export default launchSelfContained;

13
src/shims-tsx.d.ts vendored Normal file
View file

@ -0,0 +1,13 @@
import Vue, { VNode } from 'vue'
declare global {
namespace JSX {
// tslint:disable no-empty-interface
interface Element extends VNode {}
// tslint:disable no-empty-interface
interface ElementClass extends Vue {}
interface IntrinsicElements {
[elem: string]: any;
}
}
}

4
src/shims-vue.d.ts vendored Normal file
View file

@ -0,0 +1,4 @@
declare module '*.vue' {
import Vue from 'vue'
export default Vue
}

68
src/types/ui-data.ts Normal file
View file

@ -0,0 +1,68 @@
import { ContainerPiece, ShipPosition } from 'container-engine/src/gamestate';
import PieceComponent from '../components/pieces/Piece.vue';
export interface UIData {
dragged?: PieceComponent | null;
waitingAnimations: number;
helpOn: boolean;
}
export interface Piece {
id: string;
x: number;
y: number;
owner?: number;
color?: string;
rotate?: number;
state?: string;
}
export interface ShipType extends Piece {
containers: ContainerPiece[];
position: ShipPosition;
}
export enum PieceType {
Warehouse = 'warehouse',
Factory = 'factory',
Container = 'container',
Ship = 'ship',
Loan = 'loan'
}
export enum DropZoneType {
Ship = 'ship',
PlayerHarbor11 = 'playerHarbor11',
PlayerHarbor12 = 'playerHarbor12',
PlayerHarbor13 = 'playerHarbor13',
PlayerHarbor14 = 'playerHarbor14',
PlayerHarbor21 = 'playerHarbor21',
PlayerHarbor22 = 'playerHarbor22',
PlayerHarbor23 = 'playerHarbor23',
PlayerHarbor24 = 'playerHarbor24',
PlayerHarbor31 = 'playerHarbor31',
PlayerHarbor32 = 'playerHarbor32',
PlayerHarbor33 = 'playerHarbor33',
PlayerHarbor34 = 'playerHarbor34',
PlayerHarbor41 = 'playerHarbor41',
PlayerHarbor42 = 'playerHarbor42',
PlayerHarbor43 = 'playerHarbor43',
PlayerHarbor44 = 'playerHarbor44',
Factory = 'factory',
FactoryStore = 'factoryStore',
Warehouse = 'warehouse',
WarehouseStore = 'warehouseStore',
OpenSea = 'openSea',
IslandHarbor = 'islandHarbor',
GetLoan = 'getLoan',
PayLoan = 'payLoan',
Supply = 'supply'
}
export enum ContainerState {
OnBoard = 'onBoard',
OnFactoryStore = 'onFactoryStore',
OnWarehouseStore = 'onWarehouseStore',
OnShip = 'onShip',
OnIsland = 'onIsland'
}

8
src/wrapper.ts Normal file
View file

@ -0,0 +1,8 @@
// Import vue component
import launch from './launch';
if (typeof window !== 'undefined') {
(window as any).container = { launch };
}
export default launch;

View file

@ -0,0 +1,13 @@
import { expect } from 'chai'
import { shallowMount } from '@vue/test-utils'
import HelloWorld from '@/components/HelloWorld.vue'
describe('HelloWorld.vue', () => {
it('renders props.msg when passed', () => {
const msg = 'new message'
const wrapper = shallowMount(HelloWorld, {
propsData: { msg }
})
expect(wrapper.text()).to.include(msg)
})
})

42
tsconfig.json Normal file
View file

@ -0,0 +1,42 @@
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"noImplicitAny": false,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env",
"mocha",
"chai"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
]
}

8754
yarn.lock Normal file

File diff suppressed because it is too large Load diff