Publish auction journal improvements and Supporter badges
This commit is contained in:
parent
41993b8131
commit
8ccc2a1396
34 changed files with 398 additions and 38 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "container-engine",
|
||||
"version": "2.1.3",
|
||||
"version": "2.1.4",
|
||||
"description": "An engine for Container",
|
||||
"main": "dist/index.js",
|
||||
"types": "index.ts",
|
||||
|
|
|
|||
80
engine/src/auction-messages.spec.ts
Normal file
80
engine/src/auction-messages.spec.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import { expect } from 'chai';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import * as wrapper from '../wrapper';
|
||||
import { availableMoves } from './available-moves';
|
||||
import { setup } from './engine';
|
||||
import { Phase, ShipPosition } from './gamestate';
|
||||
import { LogMove } from './log';
|
||||
import { MoveName } from './move';
|
||||
|
||||
function auction(bid = 7, additionalBid = 3) {
|
||||
const state = setup(3, {}, 'auction-messages');
|
||||
state.phase = Phase.AcceptDecline;
|
||||
state.currentPlayers = [0];
|
||||
state.auctioningPlayer = 0;
|
||||
state.highestBidders = [1];
|
||||
state.players[0].name = 'slim_shagen';
|
||||
state.players[1].name = 'coyotte508';
|
||||
state.players[0].ship.shipPosition = ShipPosition.Island;
|
||||
state.players[0].ship.containers = [state.containersLeft.pop()!];
|
||||
state.players[1].bid = bid;
|
||||
state.players[1].additionalBid = additionalBid;
|
||||
state.players.forEach((player) => (player.availableMoves = availableMoves(state, player)));
|
||||
return state;
|
||||
}
|
||||
|
||||
describe('Auction results in journal and chat', () => {
|
||||
for (const [bid, additionalBid] of [
|
||||
[7, 3],
|
||||
[7, 0],
|
||||
[0, 0],
|
||||
]) {
|
||||
it(`reports the accepted total ${bid + additionalBid} before clearing bids`, async () => {
|
||||
const state = await wrapper.move(auction(bid, additionalBid), { name: MoveName.Accept, data: 1 }, 0);
|
||||
const entry = state.log[state.log.length - 1] as LogMove;
|
||||
expect(entry.simple).to.equal(
|
||||
`slim_shagen accepts coyotte508's bid of $${bid + additionalBid} and receives $${
|
||||
2 * (bid + additionalBid)
|
||||
}`
|
||||
);
|
||||
expect(entry.pretty).to.contain(`bid of $${bid + additionalBid}`);
|
||||
expect(state.players[1].bid).to.equal(0);
|
||||
expect(state.players[1].additionalBid).to.equal(0);
|
||||
const result = wrapper.messages(state);
|
||||
expect(result.messages).to.deep.equal([entry.simple]);
|
||||
expect(wrapper.messages(result.data).messages).to.deep.equal([]);
|
||||
expect(state.pendingMessages).to.deep.equal([entry.simple]);
|
||||
});
|
||||
}
|
||||
|
||||
it('announces a self-purchase and its cost', async () => {
|
||||
const state = await wrapper.move(auction(), { name: MoveName.Decline, data: true }, 0);
|
||||
expect(wrapper.messages(state).messages).to.deep.equal([
|
||||
'slim_shagen declines all bids and buys the cargo for $10',
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not backfill old auctions or expose an unresolved bid', () => {
|
||||
const state = auction();
|
||||
expect(wrapper.messages(state).messages).to.deep.equal([]);
|
||||
state.log.push({
|
||||
type: 'move',
|
||||
player: 0,
|
||||
move: { name: MoveName.Accept, data: 1 },
|
||||
simple: 'Old auction',
|
||||
pretty: 'Old auction',
|
||||
});
|
||||
expect(wrapper.messages(state).messages).to.deep.equal([]);
|
||||
state.pendingMessages = ['Pending'];
|
||||
state.newTurn = false;
|
||||
expect(wrapper.messages(state)).to.deep.equal({ messages: [], data: state });
|
||||
});
|
||||
|
||||
it('does not manufacture announcements when replaying history', () => {
|
||||
const state = setup(3, {}, 'auction-replay');
|
||||
state.pendingMessages = ['Still pending'];
|
||||
expect(wrapper.replay(cloneDeep(state)).pendingMessages).to.deep.equal(['Still pending']);
|
||||
const acknowledged = wrapper.messages(state).data;
|
||||
expect(wrapper.messages(wrapper.replay(acknowledged)).messages).to.deep.equal([]);
|
||||
});
|
||||
});
|
||||
|
|
@ -14,7 +14,7 @@ import {
|
|||
Player,
|
||||
ShipPosition,
|
||||
} from './gamestate';
|
||||
import { GameEventName, LogItem } from './log';
|
||||
import { GameEventName, LogItem, LogMove } from './log';
|
||||
import { Move, MoveName, Moves } from './move';
|
||||
import { asserts, shuffle } from './utils';
|
||||
|
||||
|
|
@ -512,10 +512,11 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
|
||||
case MoveName.Accept: {
|
||||
const otherPlayer = G.players[move.data];
|
||||
const bid = otherPlayer.bid + otherPlayer.additionalBid;
|
||||
otherPlayer.containersOnIsland.push(...player.ship.containers);
|
||||
player.ship.containers = [];
|
||||
otherPlayer.money -= otherPlayer.bid + otherPlayer.additionalBid;
|
||||
player.money += (otherPlayer.bid + otherPlayer.additionalBid) * 2;
|
||||
otherPlayer.money -= bid;
|
||||
player.money += bid * 2;
|
||||
G.players.forEach((p) => {
|
||||
p.bid = p.additionalBid = 0;
|
||||
});
|
||||
|
|
@ -541,9 +542,15 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} accepts ${otherPlayer.name}'s bid`,
|
||||
pretty: `${playerNameHTML(player)} accepts ${playerNameHTML(otherPlayer)}'s bid`,
|
||||
simple: `${player.name} accepts ${otherPlayer.name}'s bid of $${bid} and receives $${bid * 2}`,
|
||||
pretty: `${playerNameHTML(player)} accepts ${playerNameHTML(
|
||||
otherPlayer
|
||||
)}'s bid of $${bid} and receives $${bid * 2}`,
|
||||
});
|
||||
if (!fake) {
|
||||
const entry = G.log[G.log.length - 1] as LogMove;
|
||||
(G.pendingMessages ||= []).push(entry.simple);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -578,9 +585,13 @@ export function move(G: GameState, move: Move, playerNumber: number, fake?: bool
|
|||
type: 'move',
|
||||
player: playerNumber,
|
||||
move,
|
||||
simple: `${player.name} declines all bids`,
|
||||
pretty: `${playerNameHTML(player)} declines all bids`,
|
||||
simple: `${player.name} declines all bids and buys the cargo for $${bid}`,
|
||||
pretty: `${playerNameHTML(player)} declines all bids and buys the cargo for $${bid}`,
|
||||
});
|
||||
if (!fake) {
|
||||
const entry = G.log[G.log.length - 1] as LogMove;
|
||||
(G.pendingMessages ||= []).push(entry.simple);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ export interface ShipPiece {
|
|||
|
||||
export interface GameState {
|
||||
analysisCash?: number[];
|
||||
pendingMessages?: string[];
|
||||
players: Player[];
|
||||
startingPlayer: number;
|
||||
currentPlayers: number[];
|
||||
|
|
|
|||
|
|
@ -414,6 +414,11 @@ describe('wrapper (tentative turns)', () => {
|
|||
expect(platform.saved.currentPlayers).to.deep.equal([B]);
|
||||
expect(platform.saved.newTurn).to.be.true;
|
||||
|
||||
const announced = wrapper.messages(platform.saved);
|
||||
expect(announced.messages).to.have.length(1);
|
||||
expect(announced.messages[0]).to.contain('bid of $3 and receives $6');
|
||||
expect(wrapper.messages(wrapper.replay(cloneDeep(announced.data))).messages).to.deep.equal([]);
|
||||
|
||||
// The saved log never shrank across committed states
|
||||
for (let i = 1; i < platform.logLengths.length; i++) {
|
||||
expect(platform.logLengths[i]).to.be.at.least(platform.logLengths[i - 1]);
|
||||
|
|
|
|||
|
|
@ -151,6 +151,9 @@ export function replay(G: GameState) {
|
|||
G = engine.move(G, move.move, move.player);
|
||||
}
|
||||
|
||||
// Reconstructing history must not announce old auctions again.
|
||||
if (oldG.pendingMessages) G.pendingMessages = [...oldG.pendingMessages];
|
||||
else delete G.pendingMessages;
|
||||
return G;
|
||||
}
|
||||
|
||||
|
|
@ -199,10 +202,10 @@ export function currentPlayer(G: GameState) {
|
|||
}
|
||||
|
||||
export function messages(G: GameState) {
|
||||
return {
|
||||
messages: [],
|
||||
data: G,
|
||||
};
|
||||
if (G.newTurn === false || !G.pendingMessages?.length) return { messages: [], data: G };
|
||||
const data = { ...G };
|
||||
delete data.pendingMessages;
|
||||
return { messages: [...G.pendingMessages], data };
|
||||
}
|
||||
|
||||
export function logLength(G: GameState, _player?: number) {
|
||||
|
|
|
|||
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
|
|
@ -86,8 +86,8 @@ importers:
|
|||
viewer:
|
||||
dependencies:
|
||||
'@boardgamers/protocol':
|
||||
specifier: 0.6.2
|
||||
version: 0.6.2
|
||||
specifier: 0.8.1
|
||||
version: 0.8.1
|
||||
container-engine:
|
||||
specifier: workspace:../engine
|
||||
version: link:../engine
|
||||
|
|
@ -1042,10 +1042,10 @@ packages:
|
|||
}
|
||||
engines: { node: '>=6.9.0' }
|
||||
|
||||
'@boardgamers/protocol@0.6.2':
|
||||
'@boardgamers/protocol@0.8.1':
|
||||
resolution:
|
||||
{
|
||||
integrity: sha512-6FKgLsB4guCzNww1rkanhrsLHIdQVajDs1B4qNsYcgtUobTBRM2VPt9T4mlc8ZDX4JDQltvJVHuK7XDZ1J556A==,
|
||||
integrity: sha512-BZNj+wof1aR1nSybRMqmQ+yAVNR3ZZy+mczIz2KbXSLXMLL3Jv21yi50CRbJ2ipdkPiPatcSP0nJj+xJbFgIfQ==,
|
||||
}
|
||||
|
||||
'@cspotcode/source-map-support@0.8.1':
|
||||
|
|
@ -11587,7 +11587,7 @@ snapshots:
|
|||
'@babel/helper-string-parser': 7.29.7
|
||||
'@babel/helper-validator-identifier': 7.29.7
|
||||
|
||||
'@boardgamers/protocol@0.6.2':
|
||||
'@boardgamers/protocol@0.8.1':
|
||||
dependencies:
|
||||
zod: 4.6.2
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ allowBuilds:
|
|||
autoInstallPeers: false
|
||||
|
||||
minimumReleaseAgeExclude:
|
||||
- '@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1 || 0.3.3 || 0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.6.2'
|
||||
|
||||
- '@boardgamers/protocol@0.2.2 || 0.3.0 || 0.3.1 || 0.3.3 || 0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.6.2 || 0.8.1'
|
||||
# The cli-plugin-typescript fork-ts-checker shim does a bare
|
||||
# require('@vue/compiler-sfc') expecting the vue-3 parse shape ({descriptor}).
|
||||
# It declares no such dependency, so resolution falls back to pnpm's hidden
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
"preview:tutorial": "node scripts/tutorial-preview.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.6.2",
|
||||
"@boardgamers/protocol": "0.8.1",
|
||||
"container-engine": "workspace:../engine",
|
||||
"core-js": "^3.6.5",
|
||||
"lodash": "^4.17.19",
|
||||
|
|
|
|||
50
viewer/scripts/auction-messages-smoke.mjs
Normal file
50
viewer/scripts/auction-messages-smoke.mjs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import assert from 'node:assert/strict';
|
||||
|
||||
export async function checkAuctionMessages(page, state) {
|
||||
const accepted = "slim_shagen accepts coyotte508's bid of $10 and receives $20";
|
||||
const declined = 'slim_shagen declines all bids and buys the cargo for $10';
|
||||
await page.evaluate(
|
||||
({ state, accepted, declined }) => {
|
||||
state.players[0].name = 'slim_shagen';
|
||||
state.players[1].name = 'coyotte508';
|
||||
state.log = [
|
||||
{
|
||||
type: 'move',
|
||||
player: 0,
|
||||
move: { name: 'accept', data: 1 },
|
||||
simple: accepted,
|
||||
pretty: "<b>slim_shagen</b> accepts <b>coyotte508</b>'s bid of $10 and receives $20",
|
||||
},
|
||||
];
|
||||
host.emit('state', state);
|
||||
host.emit('chat:messages', [
|
||||
{ _id: '000000050000000000000001', type: 'system', text: accepted },
|
||||
{ _id: '000000050000000000000002', type: 'system', text: declined },
|
||||
{ _id: '000000050000000000000003', type: 'text', author: 'coyotte508', text: accepted },
|
||||
]);
|
||||
host.emit('preferences', { locale: 'fr' });
|
||||
},
|
||||
{ state, accepted, declined }
|
||||
);
|
||||
await page.waitForFunction(() => document.querySelector('.journal-entry')?.textContent.includes('reçoit $20'));
|
||||
await page.waitForFunction(() =>
|
||||
document.querySelector('.bgs-game-chat article.system')?.textContent.includes('reçoit $20')
|
||||
);
|
||||
assert.match(
|
||||
await page.locator('.journal-entry').textContent(),
|
||||
/slim_shagen accepte l’enchère de coyotte508 de \$10 et reçoit \$20/
|
||||
);
|
||||
assert.match(
|
||||
await page.locator('.bgs-game-chat article.system').nth(1).textContent(),
|
||||
/achète la cargaison pour \$10/
|
||||
);
|
||||
assert.ok(
|
||||
(await page.locator('.bgs-game-chat article:not(.system)').textContent()).includes(accepted),
|
||||
'player messages remain untouched'
|
||||
);
|
||||
await page.evaluate(() => host.emit('preferences', { locale: 'en' }));
|
||||
await page.waitForFunction(() =>
|
||||
document.querySelector('.bgs-game-chat article.system')?.textContent.includes('bid of $10 and receives $20')
|
||||
);
|
||||
assert.ok((await page.locator('.journal-entry').textContent()).includes(accepted));
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ import { createServer } from 'node:http';
|
|||
import { createRequire } from 'node:module';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { chromium } from 'playwright';
|
||||
import { checkAuctionMessages } from './auction-messages-smoke.mjs';
|
||||
import { checkFinalScore } from './final-score-smoke.mjs';
|
||||
import { checkHostPresentation } from './host-presentation-smoke.mjs';
|
||||
|
||||
|
|
@ -393,6 +394,7 @@ try {
|
|||
'opening chat clears restored unread'
|
||||
);
|
||||
await checkHostPresentation(page, 'host', `/tmp/container-board-thumbnail-${width}.png`);
|
||||
await checkAuctionMessages(page, state);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.close();
|
||||
console.log(`${game} ${width}px: protocol/chat smoke passed`);
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@
|
|||
:title="p.name"
|
||||
@click="viewPlayerBoard(i)"
|
||||
>
|
||||
<img
|
||||
v-if="supporterBadge(i)"
|
||||
:src="supporterBadge(i).url"
|
||||
:alt="supporterBadge(i).label"
|
||||
:title="supporterBadge(i).label"
|
||||
width="14"
|
||||
height="14"
|
||||
/>
|
||||
<span class="player-board-marker" aria-hidden="true">{{ preferences.colorBlind ? i + 1 : '' }}</span
|
||||
><span class="player-board-name" :data-bgs-player="i">{{ i === player ? 'You' : p.name }}</span>
|
||||
</button>
|
||||
|
|
@ -242,6 +250,13 @@
|
|||
/>
|
||||
</template>
|
||||
|
||||
<g v-if="ownIslandValue !== undefined" class="island-value" transform="translate(860, 410)">
|
||||
<title>
|
||||
Island score if the game ended now, including the discarded colour and full-set bonus.
|
||||
</title>
|
||||
<text x="0" y="0">Your island: ${{ ownIslandValue }}</text>
|
||||
</g>
|
||||
|
||||
<template v-if="G && player != undefined">
|
||||
<text x="20" y="440">Money: ${{ G.players[player].money }}</text>
|
||||
<PointCard :pointCard="G.players[player].pointCard" transform="translate(20, 460)" />
|
||||
|
|
@ -679,6 +694,7 @@
|
|||
</template>
|
||||
<script lang="ts">
|
||||
import InlineLog from './InlineLog.vue';
|
||||
import { islandValue } from '../island-value';
|
||||
import ColorBlindButton from './buttons/ColorBlindButton.vue';
|
||||
import { colorBadgeHtml } from '../color-blind';
|
||||
import { journalPieces } from '../journal-pieces';
|
||||
|
|
@ -756,6 +772,11 @@ export default class Game extends Vue {
|
|||
@ProvideReactive()
|
||||
G?: GameState | null = null;
|
||||
|
||||
get ownIslandValue() {
|
||||
const ownPlayer = this.player == null ? undefined : this.G?.players[this.player];
|
||||
return ownPlayer ? islandValue(ownPlayer) : undefined;
|
||||
}
|
||||
|
||||
// Pieces
|
||||
containers: Piece[] = [];
|
||||
factories: Piece[] = [];
|
||||
|
|
@ -1099,6 +1120,10 @@ export default class Game extends Vue {
|
|||
if (piece?.canDrag) this.ui.selected = piece;
|
||||
}
|
||||
|
||||
supporterBadge(index: number) {
|
||||
return this.preferences.bgs?.players?.[index]?.pro ? this.preferences.bgs.supporterBadge : undefined;
|
||||
}
|
||||
|
||||
viewPlayerBoard(index: number) {
|
||||
this.mobilePlayer = index;
|
||||
this.$nextTick(() => {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
:data-bgs-player="owner"
|
||||
style="pointer-events: all"
|
||||
tabindex="0"
|
||||
x="5"
|
||||
:x="supporterBadge ? 23 : 5"
|
||||
y="10"
|
||||
font-weight="600"
|
||||
fill="black"
|
||||
|
|
@ -13,6 +13,16 @@
|
|||
>{{ preferences.colorBlind ? owner + 1 + '. ' : '' }}{{ getPlayerName() }}</text
|
||||
>
|
||||
|
||||
<image
|
||||
v-if="supporterBadge"
|
||||
:href="supporterBadge.url"
|
||||
x="4"
|
||||
y="2"
|
||||
width="16"
|
||||
height="16"
|
||||
:aria-label="supporterBadge.label"
|
||||
><title>{{ supporterBadge.label }}</title></image
|
||||
>
|
||||
<rect width="250" height="180" x="0" y="20" fill="#e2e0d3" stroke="#899997" />
|
||||
<rect width="246" height="2" x="2" y="21" :fill="color" />
|
||||
<text x="248" y="104" text-anchor="end" font-size="8" fill="#45585b">FACTORY SALES</text>
|
||||
|
|
@ -208,6 +218,11 @@ import DropZone from './DropZone.vue';
|
|||
})
|
||||
export default class PlayerBoard extends Vue {
|
||||
@InjectReactive() readonly preferences!: Preferences;
|
||||
get supporterBadge() {
|
||||
return this.owner !== undefined && this.preferences.bgs?.players?.[this.owner]?.pro
|
||||
? this.preferences.bgs.supporterBadge
|
||||
: undefined;
|
||||
}
|
||||
@Prop({ default: false })
|
||||
openMoney!: boolean;
|
||||
|
||||
|
|
|
|||
27
viewer/src/island-value.ts
Normal file
27
viewer/src/island-value.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
import type { Player } from 'container-engine';
|
||||
|
||||
/** Island-only score if the game ended now; never infer a hidden value card. */
|
||||
export function islandValue(player: Player): number | undefined {
|
||||
const values = player.pointCard?.containerValues;
|
||||
if (!values) return undefined;
|
||||
const counts = new Map<string, number>();
|
||||
player.containersOnIsland.forEach(({ color }) => counts.set(color, (counts.get(color) || 0) + 1));
|
||||
if (!counts.size) return 0;
|
||||
|
||||
// Match final scoring: discard the most numerous colour, preferring the
|
||||
// $5/10 colour on ties, then the lowest base value among the tied colours.
|
||||
const most = Math.max(...counts.values());
|
||||
const tied = values.filter((value) => counts.get(value.containerColor) === most);
|
||||
const discarded =
|
||||
tied.find((value) => value === values[1]) ||
|
||||
tied.reduce((lowest, value) => (value.baseValue < lowest.baseValue ? value : lowest));
|
||||
const completeSet = counts.size === 5;
|
||||
return values.reduce(
|
||||
(total, value) =>
|
||||
total +
|
||||
(value === discarded
|
||||
? 0
|
||||
: (counts.get(value.containerColor) || 0) * (completeSet ? value.specialValue : value.baseValue)),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
|
@ -36,6 +36,7 @@ function launch(selector: string) {
|
|||
// from a non-reactive parent — plain-object mutations (the in-game sound/help
|
||||
// toggles, platform preference pushes) would only paint on the next re-render.
|
||||
preferences: Vue.observable({
|
||||
bgs: {},
|
||||
sound: true,
|
||||
colorBlind: false,
|
||||
disableHelp: false,
|
||||
|
|
@ -69,6 +70,7 @@ function launch(selector: string) {
|
|||
return;
|
||||
}
|
||||
Object.assign(params.preferences, data);
|
||||
params.preferences.bgs = (data.bgs ?? {}) as NonNullable<Preferences['bgs']>;
|
||||
app.$forceUpdate();
|
||||
},
|
||||
async onLog(logData) {
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "fabrik (beige)",
|
||||
"white factory": "fabrik (hvid)",
|
||||
"dark green factory": "fabrik (mørkegrøn)",
|
||||
"Close": "Luk"
|
||||
"Close": "Luk",
|
||||
"Your island: ${p0}": "Din ø: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Øens værdi hvis spillet sluttede nu, inklusive den kasserede farve og bonussen for et komplet sæt.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} accepterer buddet fra {p1} på ${p2} og modtager ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} afviser alle bud og køber lasten for ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "Fabrik (beige)",
|
||||
"white factory": "Fabrik (weiß)",
|
||||
"dark green factory": "Fabrik (dunkelgrün)",
|
||||
"Close": "Schließen"
|
||||
"Close": "Schließen",
|
||||
"Your island: ${p0}": "Deine Insel: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Inselwertung bei sofortigem Spielende, einschließlich der entfernten Farbe und des Bonus für alle fünf Farben.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} nimmt das Gebot von {p1} über ${p2} an und erhält ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} lehnt alle Gebote ab und kauft die Ladung für ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "εργοστάσιο (μπεζ)",
|
||||
"white factory": "εργοστάσιο (λευκό)",
|
||||
"dark green factory": "εργοστάσιο (σκούρο πράσινο)",
|
||||
"Close": "Κλείσιμο"
|
||||
"Close": "Κλείσιμο",
|
||||
"Your island: ${p0}": "Το νησί σου: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Βαθμολογία νησιού αν το παιχνίδι τελείωνε τώρα, με την αφαίρεση του χρώματος και το μπόνους πλήρους σετ.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} δέχεται την προσφορά ${p2} του παίκτη {p1} και λαμβάνει ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} απορρίπτει όλες τις προσφορές και αγοράζει το φορτίο για ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "tan factory",
|
||||
"white factory": "white factory",
|
||||
"dark green factory": "dark green factory",
|
||||
"Close": "Close"
|
||||
"Close": "Close",
|
||||
"Your island: ${p0}": "Your island: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Island score if the game ended now, including the discarded colour and full-set bonus.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} accepts {p1}'s bid of ${p2} and receives ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} declines all bids and buys the cargo for ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "کارخانهٔ بژ",
|
||||
"white factory": "کارخانهٔ سفید",
|
||||
"dark green factory": "کارخانهٔ سبز تیره",
|
||||
"Close": "بستن"
|
||||
"Close": "بستن",
|
||||
"Your island: ${p0}": "جزیرهٔ شما: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "امتیاز جزیره اگر بازی همین حالا تمام شود، با احتساب رنگ حذفشده و پاداش مجموعهٔ کامل رنگها.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} پیشنهاد ${p2} از {p1} را میپذیرد و ${p3} دریافت میکند",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} همهٔ پیشنهادها را رد میکند و محموله را به قیمت ${p1} میخرد"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "usine (beige)",
|
||||
"white factory": "usine (blanc)",
|
||||
"dark green factory": "usine (vert foncé)",
|
||||
"Close": "Fermer"
|
||||
"Close": "Fermer",
|
||||
"Your island: ${p0}": "Votre île : ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Score de votre île si la partie se terminait maintenant, après retrait de la couleur défaussée et application du bonus des cinq couleurs.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} accepte l’enchère de {p1} de ${p2} et reçoit ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} refuse toutes les enchères et achète la cargaison pour ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "कारखाना (हल्का भूरा)",
|
||||
"white factory": "कारखाना (सफ़ेद)",
|
||||
"dark green factory": "कारखाना (गहरा हरा)",
|
||||
"Close": "बंद करें"
|
||||
"Close": "बंद करें",
|
||||
"Your island: ${p0}": "आपका द्वीप: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "यदि खेल अभी समाप्त हो जाए तो द्वीप का स्कोर, हटाए गए रंग और पूरे सेट के बोनस सहित।",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0}, {p1} की ${p2} की बोली स्वीकार करता है और ${p3} प्राप्त करता है",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} सभी बोलियाँ अस्वीकार करके ${p1} में माल खरीदता है"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "fabbrica (marrone chiaro)",
|
||||
"white factory": "fabbrica (bianco)",
|
||||
"dark green factory": "fabbrica (verde scuro)",
|
||||
"Close": "Chiudi"
|
||||
"Close": "Chiudi",
|
||||
"Your island: ${p0}": "La tua isola: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Punteggio dell’isola se la partita finisse ora, inclusi il colore scartato e il bonus del set completo.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} accetta l’offerta di ${p2} di {p1} e riceve ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} rifiuta tutte le offerte e acquista il carico per ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "공장 (베이지색)",
|
||||
"white factory": "공장 (흰색)",
|
||||
"dark green factory": "공장 (짙은 녹색)",
|
||||
"Close": "닫기"
|
||||
"Close": "닫기",
|
||||
"Your island: ${p0}": "내 섬: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "지금 게임이 끝날 경우의 섬 점수입니다. 버리는 색상과 전체 색상 세트 보너스를 반영합니다.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0}: {p1}의 ${p2} 입찰을 수락하고 ${p3}를 받습니다",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0}: 모든 입찰을 거절하고 화물을 ${p1}에 구매합니다"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "fabriek (beige)",
|
||||
"white factory": "fabriek (wit)",
|
||||
"dark green factory": "fabriek (donkergroen)",
|
||||
"Close": "Sluiten"
|
||||
"Close": "Sluiten",
|
||||
"Your island: ${p0}": "Jouw eiland: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Eilandscore als het spel nu zou eindigen, inclusief de verwijderde kleur en de bonus voor een volledige set.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} accepteert het bod van {p1} van ${p2} en ontvangt ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} wijst alle biedingen af en koopt de lading voor ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "fabryka (beżowy)",
|
||||
"white factory": "fabryka (biały)",
|
||||
"dark green factory": "fabryka (ciemnozielony)",
|
||||
"Close": "Zamknij"
|
||||
"Close": "Zamknij",
|
||||
"Your island: ${p0}": "Twoja wyspa: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Wynik wyspy, gdyby gra skończyła się teraz, z uwzględnieniem odrzuconego koloru i premii za komplet kolorów.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} przyjmuje ofertę {p1} w wysokości ${p2} i otrzymuje ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} odrzuca wszystkie oferty i kupuje ładunek za ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "fábrica (bege)",
|
||||
"white factory": "fábrica (branco)",
|
||||
"dark green factory": "fábrica (verde-escuro)",
|
||||
"Close": "Fechar"
|
||||
"Close": "Fechar",
|
||||
"Your island: ${p0}": "Sua ilha: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Pontuação da ilha se a partida terminasse agora, considerando a cor descartada e o bônus do conjunto completo.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} aceita o lance de ${p2} de {p1} e recebe ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} recusa todos os lances e compra a carga por ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "fabrică (bej)",
|
||||
"white factory": "fabrică (alb)",
|
||||
"dark green factory": "fabrică (verde închis)",
|
||||
"Close": "Închide"
|
||||
"Close": "Închide",
|
||||
"Your island: ${p0}": "Insula ta: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Scorul insulei dacă jocul s-ar termina acum, incluzând culoarea eliminată și bonusul pentru setul complet.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} acceptă oferta de ${p2} a lui {p1} și primește ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} refuză toate ofertele și cumpără încărcătura pentru ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "фабрика (бежевый)",
|
||||
"white factory": "фабрика (белый)",
|
||||
"dark green factory": "фабрика (тёмно-зелёный)",
|
||||
"Close": "Закрыть"
|
||||
"Close": "Закрыть",
|
||||
"Your island: ${p0}": "Ваш остров: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Стоимость острова, если бы игра закончилась сейчас, с учётом сброшенного цвета и бонуса за полный набор.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} принимает ставку {p1} в размере ${p2} и получает ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} отклоняет все ставки и покупает груз за ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -170,7 +170,15 @@ export function mountLocalization(target, catalogs, initialLocale = 'en') {
|
|||
let destroyed = false;
|
||||
function apply(node, attribute) {
|
||||
const element = node.nodeType === 3 ? node.parentElement : node;
|
||||
if (!element || element.closest?.(excluded)) {
|
||||
const sourceText = originals.get(node)?.get('text')?.source ?? node.data;
|
||||
const auctionAnnouncement =
|
||||
!attribute &&
|
||||
node.nodeType === 3 &&
|
||||
element?.matches('.bgs-game-chat article.system[data-message-id]') &&
|
||||
/^(.+ accepts .+'s bid of \$\d+ and receives \$\d+|.+ declines all bids and buys the cargo for \$\d+)$/.test(
|
||||
sourceText
|
||||
);
|
||||
if (!element || (element.closest?.(excluded) && !auctionAnnouncement)) {
|
||||
return;
|
||||
}
|
||||
const value = attribute ? node.getAttribute(attribute) : node.data;
|
||||
|
|
@ -239,6 +247,12 @@ export function mountLocalization(target, catalogs, initialLocale = 'en') {
|
|||
if (node.innerHTML !== rendered.innerHTML) node.innerHTML = rendered.innerHTML;
|
||||
return;
|
||||
}
|
||||
if (node.matches?.('.bgs-game-chat article.system[data-message-id]')) {
|
||||
for (const child of node.childNodes) {
|
||||
if (child.nodeType === 3) apply(child);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (node.matches?.(excluded)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "nhà máy (nâu nhạt)",
|
||||
"white factory": "nhà máy (trắng)",
|
||||
"dark green factory": "nhà máy (xanh lá đậm)",
|
||||
"Close": "Đóng"
|
||||
"Close": "Đóng",
|
||||
"Your island: ${p0}": "Đảo của bạn: ${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "Điểm đảo nếu trò chơi kết thúc ngay bây giờ, đã tính màu bị loại và thưởng đủ bộ màu.",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} chấp nhận giá ${p2} của {p1} và nhận ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} từ chối mọi giá đấu và mua hàng với giá ${p1}"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -647,5 +647,9 @@
|
|||
"tan factory": "工廠 (米色)",
|
||||
"white factory": "工廠 (白色)",
|
||||
"dark green factory": "工廠 (深綠色)",
|
||||
"Close": "關閉"
|
||||
"Close": "關閉",
|
||||
"Your island: ${p0}": "你的島嶼:${p0}",
|
||||
"Island score if the game ended now, including the discarded colour and full-set bonus.": "若遊戲現在結束,島嶼的計分價值,已計入棄置顏色與完整顏色組合加成。",
|
||||
"{p0} accepts {p1}'s bid of ${p2} and receives ${p3}": "{p0} 接受 {p1} 的 ${p2} 出價並獲得 ${p3}",
|
||||
"{p0} declines all bids and buys the cargo for ${p1}": "{p0} 拒絕所有出價並以 ${p1} 購買貨物"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ export interface UIData {
|
|||
}
|
||||
|
||||
export type Preferences = {
|
||||
bgs?: { players?: { pro: boolean }[]; supporterBadge?: { url: string; label: string } };
|
||||
analysis?: boolean;
|
||||
sound: boolean;
|
||||
colorBlind?: boolean;
|
||||
|
|
|
|||
61
viewer/tests/unit/island-value.spec.ts
Normal file
61
viewer/tests/unit/island-value.spec.ts
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import { islandValue } from '@/island-value';
|
||||
import Game from '@/components/Game.vue';
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import { expect } from 'chai';
|
||||
import { setup } from 'container-engine';
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
function playerWithCounts(counts: number[], offset = 1000) {
|
||||
const player = setup(3, { beginner: true }, 'island-value').players[0];
|
||||
player.containersOnIsland = player.pointCard!.containerValues.flatMap((value, index) =>
|
||||
Array.from({ length: counts[index] }, (_, i) => ({
|
||||
id: `C${offset + index * 10 + i}` as const,
|
||||
color: value.containerColor,
|
||||
}))
|
||||
);
|
||||
return player;
|
||||
}
|
||||
|
||||
describe('Private island value', () => {
|
||||
for (const [counts, expected] of [
|
||||
[[0, 0, 0, 0, 0], 0],
|
||||
[[3, 0, 0, 0, 0], 0],
|
||||
[[2, 1, 1, 1, 3], 40], // all five colours: the $5/10 colour scores $10
|
||||
[[2, 1, 1, 0, 3], 31], // no full-set bonus
|
||||
[[1, 1, 1, 1, 1], 22], // tied $5/10 colour is discarded
|
||||
[[2, 0, 2, 1, 0], 24], // other ties discard the lower value
|
||||
] as [number[], number][]) {
|
||||
it(`scores ${counts.join('/')} as $${expected}`, () => {
|
||||
const player = playerWithCounts(counts);
|
||||
const before = JSON.stringify(player);
|
||||
expect(islandValue(player)).to.equal(expected);
|
||||
expect(JSON.stringify(player)).to.equal(before);
|
||||
});
|
||||
}
|
||||
|
||||
it('shows only the viewing player’s island, updates with state, and hides for spectators or hidden cards', async () => {
|
||||
const state = setup(3, { beginner: true }, 'island-value');
|
||||
const first = playerWithCounts([2, 1, 1, 1, 3]);
|
||||
const second = playerWithCounts([2, 0, 2, 1, 0], 2000);
|
||||
state.players[0].containersOnIsland = first.containersOnIsland;
|
||||
state.players[1].containersOnIsland = second.containersOnIsland;
|
||||
state.players[1].pointCard = second.pointCard;
|
||||
const wrapper = shallowMount(Game, {
|
||||
propsData: { state, player: 0, emitter: new EventEmitter(), preferences: { sound: false } },
|
||||
});
|
||||
expect(wrapper.findAll('.island-value')).to.have.length(1);
|
||||
expect(wrapper.find('.island-value').text()).to.contain('Your island: $40');
|
||||
await wrapper.setProps({ player: 1 });
|
||||
expect(wrapper.find('.island-value').text()).to.contain('Your island: $24');
|
||||
const updated = JSON.parse(JSON.stringify(state));
|
||||
updated.players[1].containersOnIsland = [];
|
||||
await wrapper.setProps({ state: updated });
|
||||
expect(wrapper.find('.island-value').text()).to.contain('Your island: $0');
|
||||
await wrapper.setProps({ player: undefined });
|
||||
expect(wrapper.find('.island-value').exists()).to.equal(false);
|
||||
delete updated.players[0].pointCard;
|
||||
await wrapper.setProps({ state: JSON.parse(JSON.stringify(updated)), player: 0 });
|
||||
expect(wrapper.find('.island-value').exists()).to.equal(false);
|
||||
wrapper.destroy();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue