Log, Help and Sound buttons, final score
This commit is contained in:
parent
2161f44895
commit
04f16714b8
16 changed files with 267 additions and 23 deletions
BIN
public/audio/notification.mp3
Normal file
BIN
public/audio/notification.mp3
Normal file
Binary file not shown.
BIN
public/audio/notification.ogg
Normal file
BIN
public/audio/notification.ogg
Normal file
Binary file not shown.
BIN
public/audio/piece-drop.mp3
Normal file
BIN
public/audio/piece-drop.mp3
Normal file
Binary file not shown.
|
|
@ -17,7 +17,7 @@ export default class Button extends Vue {
|
|||
width?: number;
|
||||
|
||||
getText() {
|
||||
return this.text!.length > 15 ? this.text?.substring(0, 5).concat('...') : this.text;
|
||||
return this.text!.length > 15 ? this.text?.substring(0, 12).concat('...') : this.text;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
18
src/components/Buttons/HelpButton.vue
Normal file
18
src/components/Buttons/HelpButton.vue
Normal 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>
|
||||
15
src/components/Buttons/LogButton.vue
Normal file
15
src/components/Buttons/LogButton.vue
Normal 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>
|
||||
18
src/components/Buttons/SoundButton.vue
Normal file
18
src/components/Buttons/SoundButton.vue
Normal 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>
|
||||
8
src/components/Buttons/index.js
Normal file
8
src/components/Buttons/index.js
Normal 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 };
|
||||
|
|
@ -115,6 +115,9 @@ export default class DropZone extends Vue {
|
|||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -103,6 +103,10 @@
|
|||
</template>
|
||||
</template>
|
||||
|
||||
<template v-if="G && gameEnded(G)">
|
||||
<Button :transform="`translate(140, 580)`" :width="130" :text="'Final Score'" @click="endScoreVisible = true" />
|
||||
</template>
|
||||
|
||||
<template v-if="ui.helpOn">
|
||||
<template v-if="ui.dragged == null">
|
||||
<rect v-if="canBuyFactory('orange')" x="8" y="8" width="114" height="24" fill="none" stroke="blue" stroke-width="2px" rx="2px" />
|
||||
|
|
@ -148,6 +152,37 @@
|
|||
<use xlink:href="#moving" />
|
||||
<use xlink:href="#dragged" />
|
||||
</svg>
|
||||
|
||||
<div v-if="G" :class="['modal', { visible: logVisible }]">
|
||||
<div class="modal-content">
|
||||
<span class="close" @click="logVisible = false">×</span>
|
||||
<div class="modal-title">Log</div>
|
||||
<div class="modal-log">
|
||||
<div v-for="(log, i) in logReversed" :key="'L' + i" class="log-line" v-html="log" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="G" :class="['modal', { visible: endScoreVisible }]">
|
||||
<div class="modal-content">
|
||||
<span class="close" @click="endScoreVisible = false">×</span>
|
||||
<div class="modal-title">Final Score</div>
|
||||
<table class="final-score-table">
|
||||
<tr>
|
||||
<th>Player</th>
|
||||
<th v-for="player in G.players" :key="'FS' + player.id">{{ player.name }}</th>
|
||||
</tr>
|
||||
<tr v-for="(cat, i) in ['Money', 'Brown', 'Dark Green', 'Orange', 'Tan', 'White', 'Containers in Warehouse', 'Containers in Ship', 'Loans']" :key="'FC_' + cat">
|
||||
<td>{{ cat }}</td>
|
||||
<td v-for="player in G.players" :key="'FS' + player.id + i">{{ player.finalScoreBreakdown ? player.finalScoreBreakdown[i] : '0' }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Final Score</td>
|
||||
<td v-for="player in G.players" :key="'FS' + player.id + 'money'">{{ player.money > 0 ? '$' + player.money : '-$' + Math.abs(player.money) }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
|
|
@ -164,7 +199,7 @@ import PlayerBoard from './PlayerBoard.vue';
|
|||
import PointCard from './PointCard.vue';
|
||||
import DropZone from './DropZone.vue';
|
||||
import Calculator from './Calculator.vue';
|
||||
import { LogMove } from 'container-engine/src/log';
|
||||
import { GameEventName, LogMove } from 'container-engine/src/log';
|
||||
|
||||
@Component({
|
||||
created(this: Game) {
|
||||
|
|
@ -229,17 +264,21 @@ export default class Game extends Vue {
|
|||
|
||||
soundOn = true;
|
||||
|
||||
logVisible = false;
|
||||
|
||||
endScoreVisible = false;
|
||||
|
||||
@Watch('state', { immediate: true })
|
||||
onStateChanged(state: GameState) {
|
||||
this.replaceState(state);
|
||||
this.replaceState(state, false);
|
||||
}
|
||||
|
||||
replaceState(state: GameState) {
|
||||
replaceState(state: GameState, fake: boolean) {
|
||||
this.G = JSON.parse(JSON.stringify(state));
|
||||
|
||||
this.createPieces();
|
||||
|
||||
if (this.soundOn && this.G?.log[this.G?.log.length - 1].type == 'move') {
|
||||
if (!fake && this.soundOn && this.G?.log[this.G?.log.length - 1].type == 'move') {
|
||||
const move = (this.G?.log[this.G?.log.length - 1] as LogMove).move;
|
||||
if (move.name == MoveName.Pass && this.G.currentPlayer == this.player) {
|
||||
(document.getElementById('notification')!.cloneNode(true) as HTMLAudioElement).play();
|
||||
|
|
@ -295,15 +334,27 @@ export default class Game extends Vue {
|
|||
if (container.color !== lastColor)
|
||||
offset += 10;
|
||||
|
||||
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
|
||||
});
|
||||
if (player.containersOnIsland.length <= 28) {
|
||||
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
|
||||
});
|
||||
} else {
|
||||
this.containers.push({
|
||||
id: container.id,
|
||||
x: 860 + offset + 6 * ci,
|
||||
y: 435 + 44 * pi + 20 * (ci % 2),
|
||||
rotate: 90,
|
||||
color: container.color.toString(),
|
||||
owner: pi,
|
||||
state: ContainerState.OnIsland
|
||||
});
|
||||
}
|
||||
|
||||
lastColor = container.color;
|
||||
});
|
||||
|
|
@ -486,10 +537,6 @@ export default class Game extends Vue {
|
|||
break;
|
||||
}
|
||||
|
||||
// if (this.soundOn && e.pieceType != PieceType.Loan) {
|
||||
// (document.getElementById('piece-drop')!.cloneNode(true) as HTMLAudioElement).play();
|
||||
// }
|
||||
|
||||
this.updateUI();
|
||||
}
|
||||
|
||||
|
|
@ -529,7 +576,7 @@ export default class Game extends Vue {
|
|||
sendMove(move) {
|
||||
this.emitter.emit('move', move);
|
||||
|
||||
this.replaceState(engineMove(this.G!, move, this.player!, true));
|
||||
this.replaceState(engineMove(this.G!, move, this.player!, true), true);
|
||||
}
|
||||
|
||||
gameEnded(G: GameState) {
|
||||
|
|
@ -660,6 +707,7 @@ export default class Game extends Vue {
|
|||
}
|
||||
|
||||
showLog() {
|
||||
this.logVisible = true;
|
||||
}
|
||||
|
||||
getStatusMessage() {
|
||||
|
|
@ -668,7 +716,15 @@ export default class Game extends Vue {
|
|||
} else if (this.G?.currentPlayer == this.player) {
|
||||
return 'It\'s your turn!';
|
||||
} else {
|
||||
return `Waiting for ${this.G?.players[this.G!.currentPlayer].name} to play...`;
|
||||
if (!this.G.log || this.G.log.length == 0 || this.G.log[this.G.log.length - 1].type != 'move' || (this.G.log[this.G.log.length - 1] as LogMove).move.name == MoveName.Pass)
|
||||
return `Waiting for ${this.G?.players[this.G!.currentPlayer].name} to play...`;
|
||||
|
||||
let log = (this.G.log[this.G.log.length - 1] as LogMove).pretty!;
|
||||
while (log?.indexOf('>') != -1) {
|
||||
log = log?.substr(0, log.indexOf('<')) + log.substr(log.indexOf('>') + 1);
|
||||
}
|
||||
|
||||
return log.replaceAll('darkslategray', 'dark green');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -787,6 +843,29 @@ export default class Game extends Vue {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
get logReversed() {
|
||||
let logReversed: string[] = [];
|
||||
if (this.G && this.G.log) {
|
||||
this.G.log.forEach(log => {
|
||||
if (log.type == 'phase') {
|
||||
logReversed.push('New phase: ' + log.phase);
|
||||
} else if (log.type == 'event') {
|
||||
if (log.event.name == GameEventName.Upkeep) {
|
||||
logReversed.push('New event: ' + log.event.interest);
|
||||
} else {
|
||||
logReversed.push('New event: ' + log.event.name);
|
||||
}
|
||||
} else if (log.type == 'move') {
|
||||
logReversed.push(log.pretty!.replaceAll('darkslategray', 'dark green'));
|
||||
}
|
||||
});
|
||||
|
||||
logReversed.reverse();
|
||||
}
|
||||
|
||||
return logReversed;
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
|
@ -905,4 +984,91 @@ text {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
.modal {
|
||||
display: none; /* Hidden by default */
|
||||
position: fixed; /* Stay in place */
|
||||
z-index: 1; /* Sit on top */
|
||||
padding-top: 100px; /* Location of the box */
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%; /* Full width */
|
||||
height: 100%; /* Full height */
|
||||
overflow: auto; /* Enable scroll if needed */
|
||||
background-color: rgb(0, 0, 0); /* Fallback color */
|
||||
background-color: rgba(0, 0, 0, 0.4); /* Black w/ opacity */
|
||||
|
||||
&.visible {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
border-radius: 5px;
|
||||
background-color: #fefefe;
|
||||
margin: auto;
|
||||
padding: 10px 20px 20px 20px;
|
||||
border: 1px solid #888;
|
||||
width: 50%;
|
||||
height: 70%;
|
||||
}
|
||||
|
||||
.modal-log {
|
||||
max-height: calc(100% - 42px);
|
||||
overflow: auto;
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
.log-line {
|
||||
padding: 5px;
|
||||
|
||||
&:nth-last-child(even) {
|
||||
background: #ccc;
|
||||
}
|
||||
&:nth-last-child(odd) {
|
||||
background: #fff;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-title {
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.close {
|
||||
color: #aaaaaa;
|
||||
float: right;
|
||||
font-size: 28px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.close:hover,
|
||||
.close:focus {
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.final-score-table {
|
||||
margin: auto;
|
||||
border: 1px solid black;
|
||||
|
||||
tr {
|
||||
padding: 4px;
|
||||
|
||||
td,
|
||||
th {
|
||||
border: 1px solid black;
|
||||
text-align: center;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
max-width: 130px;
|
||||
width: 130px;
|
||||
height: 38px;
|
||||
padding: 0 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@
|
|||
<rect width="250" height="180" x="0" y="20" fill="gray" />
|
||||
|
||||
<rect width="20" height="80" x="0" y="200" fill="gray" />
|
||||
<DropZone :transform="`translate(20, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '1', owner: owner }" />
|
||||
<rect width="20" height="80" x="62" y="200" fill="gray" />
|
||||
<DropZone :transform="`translate(82, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '2', owner: owner }" />
|
||||
<rect width="20" height="80" x="124" y="200" fill="gray" />
|
||||
<DropZone :transform="`translate(144, 200)`" :width="42" :height="80" :accepts="'ship'" :data="{ type: 'playerHarbor' + owner + '3', owner: owner }" />
|
||||
<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' }" />
|
||||
|
|
|
|||
8
src/components/pieces/index.js
Normal file
8
src/components/pieces/index.js
Normal 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
1
src/icons/help.svg
Normal 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
1
src/icons/log.svg
Normal 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/sound-off.svg
Normal file
3
src/icons/sound-off.svg
Normal 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
3
src/icons/sound-on.svg
Normal 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 |
Loading…
Add table
Add a link
Reference in a new issue