Use player bid tokens and simplify the offshore harbor
This commit is contained in:
parent
d360520964
commit
928d227f36
5 changed files with 136 additions and 58 deletions
|
|
@ -98,9 +98,17 @@ try {
|
|||
assert.equal(bid.at(-1).data.lot, 2);
|
||||
for (const action of bid) state = engine.move(state, action, player);
|
||||
await push();
|
||||
assert.match(await page.locator('.bank-bid-amount').textContent(), /^2/);
|
||||
assert.match(await page.locator('.bank-bid-amount').textContent(), /^\$2/);
|
||||
assert.equal(await page.locator('.bank-bid-amount').getAttribute('font-size'), '16');
|
||||
assert.ok(!(await page.locator('.bank-bid-amount').textContent()).includes('$'));
|
||||
assert.equal(await page.getByRole('button', { name: 'Sail to bank', exact: true }).count(), 0);
|
||||
const bidder = page.locator('.bank-bidder');
|
||||
assert.equal(await bidder.getAttribute('aria-label'), state.players[player].name);
|
||||
assert.equal((await bidder.locator('text').textContent()).trim(), String(player + 1));
|
||||
await page.evaluate(() => host.emit('preferences', { colorBlind: false }));
|
||||
await page.waitForFunction(() => !document.querySelector('.bank-bidder text'));
|
||||
assert.equal(await bidder.locator('text').count(), 0, 'normal mode shows only a player token');
|
||||
await page.evaluate(() => host.emit('preferences', { colorBlind: true }));
|
||||
await page.waitForFunction(() => !!document.querySelector('.bank-bidder text'));
|
||||
|
||||
// A fresh turn fixture: calling the bank twice in one turn is illegal.
|
||||
state = engine.setup(3, { offshoreIsland: true }, 'offshore-browser');
|
||||
|
|
@ -183,17 +191,30 @@ try {
|
|||
await page.screenshot({ path: `/tmp/container-offshore-${width}.png`, fullPage: true });
|
||||
await page.evaluate(() => host.emit('preferences', { locale: 'en' }));
|
||||
|
||||
// Arrival-only pickup, using the displayed holding cargo (no component internals).
|
||||
state.players[player].ship.shipPosition = 'offshoreBank';
|
||||
state.players[player].lastMove = { name: 'sail', data: 'offshoreBank' };
|
||||
// Sail using the normal ship selection/destination flow, without a separate button.
|
||||
state.players[player].ship.shipPosition = engine.ShipPosition.OpenSea;
|
||||
state.players[player].lastMove = null;
|
||||
state.players[player].actions = 2;
|
||||
const pickup = state.containersLeft.pop();
|
||||
state.players[player].bankHolding.push(pickup);
|
||||
state.newTurn = true;
|
||||
await push();
|
||||
await page
|
||||
.locator('.piece')
|
||||
.filter({ hasText: `${state.players[player].name}'s Ship` })
|
||||
.click();
|
||||
await page.locator('.bank-harbor.canClick').click();
|
||||
const sailing = await page.evaluate(() => moves.at(-1));
|
||||
assert.deepEqual(sailing.at(-1), { name: 'sail', data: 'offshoreBank' });
|
||||
for (const action of sailing) state = engine.move(state, action, player);
|
||||
assert.equal(state.players[player].ship.shipPosition, 'offshoreBank');
|
||||
await push();
|
||||
// Arrival-only pickup still uses the displayed holding cargo.
|
||||
await page.locator(`.bank-holding [data-piece-id="${pickup.id}"]`).click();
|
||||
const loading = await page.evaluate(() => moves.at(-1));
|
||||
assert.equal(loading.at(-1).name, 'loadBankContainer');
|
||||
for (const action of loading) state = engine.move(state, action, player);
|
||||
// The emitted turn buffer includes sailing, already applied to this fixture above.
|
||||
state = engine.move(state, loading.at(-1), player);
|
||||
assert.ok(state.players[player].ship.containers.some((piece) => piece.id === pickup.id));
|
||||
await push();
|
||||
|
||||
|
|
|
|||
|
|
@ -206,8 +206,8 @@
|
|||
<DropZone
|
||||
v-if="G && G.options.offshoreIsland"
|
||||
class="bank-harbor"
|
||||
transform="translate(342 690)"
|
||||
:width="102"
|
||||
transform="translate(336 684)"
|
||||
:width="108"
|
||||
:height="210"
|
||||
:enabled="true"
|
||||
:accepts="'ship'"
|
||||
|
|
@ -1190,7 +1190,7 @@ export default class Game extends Vue {
|
|||
this.ships.push({
|
||||
id: player.ship.piece.id,
|
||||
x: 373,
|
||||
y: 665 + pi * 44,
|
||||
y: 660 + pi * 42,
|
||||
rotate: 90,
|
||||
color,
|
||||
containers: player.ship.containers,
|
||||
|
|
|
|||
|
|
@ -47,9 +47,9 @@
|
|||
}}
|
||||
</title>
|
||||
</rect>
|
||||
<text v-if="type === 'cash'" class="bank-money" x="6" y="18" font-size="16" pointer-events="none">{{
|
||||
bank.cashLots[i - 1]
|
||||
}}</text>
|
||||
<text v-if="type === 'cash'" class="bank-money" x="6" y="18" font-size="16" pointer-events="none"
|
||||
>${{ bank.cashLots[i - 1] }}</text
|
||||
>
|
||||
<OffshoreCargo
|
||||
v-else
|
||||
:pieces="bank.containerLots[i - 1]"
|
||||
|
|
@ -58,18 +58,13 @@
|
|||
:rows="2"
|
||||
/>
|
||||
<g v-if="auction(type, i - 1)">
|
||||
<rect
|
||||
x="1"
|
||||
:y="type === 'cash' ? 29 : 87"
|
||||
width="3"
|
||||
height="11"
|
||||
:fill="playerColors[auction(type, i - 1).bidder]"
|
||||
<PlayerToken
|
||||
class="bank-bidder"
|
||||
:transform="`translate(16 ${type === 'cash' ? 33 : 94})`"
|
||||
:owner="auction(type, i - 1).bidder"
|
||||
:name="owner(auction(type, i - 1).bidder)"
|
||||
:color="playerColors[auction(type, i - 1).bidder]"
|
||||
/>
|
||||
<title translate="no">{{ owner(auction(type, i - 1).bidder) }}</title>
|
||||
<text x="6" :y="type === 'cash' ? 36 : 94" font-size="12" fill="#203a45" translate="no"
|
||||
>{{ playerLabel(auction(type, i - 1).bidder, 6)
|
||||
}}<title translate="no">{{ owner(auction(type, i - 1).bidder) }}</title></text
|
||||
>
|
||||
<OffshoreCargo
|
||||
v-if="type === 'cash'"
|
||||
:pieces="escrow(auction(type, i - 1))"
|
||||
|
|
@ -78,22 +73,15 @@
|
|||
:rows="2"
|
||||
/>
|
||||
<text v-else class="bank-money bank-bid-amount" x="94" y="94" font-size="16" text-anchor="end"
|
||||
>{{ auction(type, i - 1).cash }}<title>Cash bid</title></text
|
||||
>${{ auction(type, i - 1).cash }}<title>Cash bid</title></text
|
||||
>
|
||||
</g>
|
||||
</g>
|
||||
</template>
|
||||
<Button
|
||||
v-if="canSail"
|
||||
transform="translate(0 240)"
|
||||
:width="130"
|
||||
text="Sail to bank"
|
||||
@click="emitMove({ name: names.Sail, data: 'offshoreBank' })"
|
||||
/>
|
||||
</g>
|
||||
<g class="bank-piers" pointer-events="none" transform="translate(332 680)">
|
||||
<rect width="10" height="230" fill="#c6c6b8" />
|
||||
<rect v-for="i in 6" :key="i" x="10" :y="(i - 1) * 44" width="102" height="10" fill="#c6c6b8" />
|
||||
<rect width="4" height="214" fill="#c6c6b8" />
|
||||
<rect v-for="i in 6" :key="i" x="4" :y="(i - 1) * 42" width="108" height="4" fill="#c6c6b8" />
|
||||
</g>
|
||||
<g
|
||||
v-for="({ p, i }, index) in holdings"
|
||||
|
|
@ -102,10 +90,7 @@
|
|||
class="bank-holding"
|
||||
:data-owner="i"
|
||||
>
|
||||
<rect x="0" y="-8" width="3" height="12" :fill="playerColors[i]" />
|
||||
<text x="7" y="0" font-size="12" fill="#203a45" translate="no"
|
||||
>{{ playerLabel(i) }}<title translate="no">{{ owner(i) }}: bank holding</title></text
|
||||
>
|
||||
<PlayerToken transform="translate(9 0)" :owner="i" :name="owner(i)" :color="playerColors[i]" />
|
||||
<OffshoreCargo
|
||||
:pieces="p.bankHolding || []"
|
||||
transform="translate(0 12)"
|
||||
|
|
@ -122,10 +107,12 @@
|
|||
<g v-if="bank.decision" class="bank-decision" transform="translate(470 680)">
|
||||
<text x="0" y="0" font-size="14">{{ decisionTitle }}</text>
|
||||
<template v-if="!decisionMoves.length">
|
||||
<text x="0" y="20" font-size="12" fill="#203a45" translate="no"
|
||||
>{{ playerLabel(bank.decision.player)
|
||||
}}<title translate="no">{{ owner(bank.decision.player) }}</title></text
|
||||
>
|
||||
<PlayerToken
|
||||
transform="translate(9 20)"
|
||||
:owner="bank.decision.player"
|
||||
:name="owner(bank.decision.player)"
|
||||
:color="playerColors[bank.decision.player]"
|
||||
/>
|
||||
<OffshoreCargo :pieces="pendingCargo" transform="translate(0 35)" :columns="10" :rows="8" />
|
||||
</template>
|
||||
<template v-else>
|
||||
|
|
@ -196,15 +183,16 @@
|
|||
</template>
|
||||
<script lang="ts">
|
||||
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||
import { BankAuction, BankAuctionType, GameState, ShipPosition } from 'container-engine/src/gamestate';
|
||||
import { BankAuction, BankAuctionType, GameState } from 'container-engine/src/gamestate';
|
||||
import { AvailableMoves } from 'container-engine/src/available-moves';
|
||||
import { playerColors } from 'container-engine/src/engine';
|
||||
import { Move, MoveName, Moves } from 'container-engine/src/move';
|
||||
import { legalBankAction } from '../offshore-actions';
|
||||
import Button from './buttons/Button.vue';
|
||||
import OffshoreCargo from './OffshoreCargo.vue';
|
||||
import PlayerToken from './PlayerToken.vue';
|
||||
|
||||
@Component({ components: { OffshoreCargo, Button } })
|
||||
@Component({ components: { OffshoreCargo, PlayerToken, Button } })
|
||||
export default class OffshoreBank extends Vue {
|
||||
@Prop({ required: true }) state!: GameState;
|
||||
@Prop() player?: number;
|
||||
|
|
@ -233,13 +221,6 @@ export default class OffshoreBank extends Vue {
|
|||
(i === this.player && !!this.availableMoves[MoveName.LoadBankContainer])
|
||||
);
|
||||
}
|
||||
get canSail() {
|
||||
return (
|
||||
this.canAct &&
|
||||
!!this.availableMoves[MoveName.Sail] &&
|
||||
legalBankAction(this.state, this.player, { name: MoveName.Sail, data: ShipPosition.OffshoreBank })
|
||||
);
|
||||
}
|
||||
|
||||
get bank() {
|
||||
return this.state.offshoreBank;
|
||||
|
|
@ -285,10 +266,6 @@ export default class OffshoreBank extends Vue {
|
|||
owner(index: number) {
|
||||
return this.state.players[index]?.name || String(index + 1);
|
||||
}
|
||||
playerLabel(index: number, limit = 18) {
|
||||
const name = this.owner(index);
|
||||
return name.length > limit ? name.slice(0, limit - 1) + '…' : name;
|
||||
}
|
||||
auction(type: BankAuctionType, lot: number) {
|
||||
return this.bank?.auctions.find((a) => a.type === type && a.lot === lot);
|
||||
}
|
||||
|
|
|
|||
36
viewer/src/components/PlayerToken.vue
Normal file
36
viewer/src/components/PlayerToken.vue
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<template>
|
||||
<g class="player-token" role="img" :aria-label="name" translate="no" tabindex="0">
|
||||
<title>{{ name }}</title>
|
||||
<circle r="9" :fill="color" stroke="#203a45" stroke-width="1.2" />
|
||||
<circle r="6.5" fill="none" stroke="white" stroke-opacity=".35" stroke-width=".8" />
|
||||
<g v-if="preferences.colorBlind" pointer-events="none">
|
||||
<circle r="6.5" fill="white" />
|
||||
<text y="0" text-anchor="middle" fill="#172d34" font-size="10" font-weight="bold">{{ symbol }}</text>
|
||||
</g>
|
||||
</g>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { Component, InjectReactive, Prop, Vue } from 'vue-property-decorator';
|
||||
import { playerSymbol } from '../player-colors';
|
||||
import type { Preferences } from '../types/ui-data';
|
||||
|
||||
@Component
|
||||
export default class PlayerToken extends Vue {
|
||||
@InjectReactive() readonly preferences!: Preferences;
|
||||
@Prop({ required: true }) owner!: number;
|
||||
@Prop({ required: true }) name!: string;
|
||||
@Prop({ required: true }) color!: string;
|
||||
|
||||
get symbol() {
|
||||
return playerSymbol(this.owner, this.preferences);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
.player-token:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
.player-token:focus-visible > circle:first-of-type {
|
||||
stroke-width: 2.5;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -2,6 +2,7 @@ import Calculator from '@/components/Calculator.vue';
|
|||
import Game from '@/components/Game.vue';
|
||||
import OffshoreBank from '@/components/OffshoreBank.vue';
|
||||
import OffshoreCargo from '@/components/OffshoreCargo.vue';
|
||||
import PlayerToken from '@/components/PlayerToken.vue';
|
||||
import { legalBankAction } from '@/offshore-actions';
|
||||
import { escapeJournal, offshoreJournal } from '@/offshore-journal';
|
||||
import { mount, shallowMount } from '@vue/test-utils';
|
||||
|
|
@ -66,15 +67,58 @@ describe('Offshore bank viewer', () => {
|
|||
const wrapper = render();
|
||||
expect(wrapper.findAll('.bank-lot-guide text').wrappers.map((node) => node.text())).toEqual(['I', 'II', 'III']);
|
||||
const money = wrapper.findAll('.bank-money');
|
||||
expect(money.wrappers.map((node) => node.text())).toEqual(['1', '2', '3']);
|
||||
expect(money.wrappers.map((node) => node.text())).toEqual(['$1', '$2', '$3']);
|
||||
expect(money.wrappers.every((node) => node.attributes('font-size') === '16')).toBe(true);
|
||||
expect(wrapper.find('.bank-piers').exists()).toBe(true);
|
||||
expect(wrapper.find('.bank-piers > rect').attributes('height')).toBe('214');
|
||||
expect(wrapper.find('.bank-piers > rect').attributes('width')).toBe('4');
|
||||
expect(wrapper.find('[aria-label="Sail to bank"]').exists()).toBe(false);
|
||||
expect(wrapper.text()).not.toContain('BANK HARBOR');
|
||||
expect(wrapper.findAll('.offshore-lot title').at(0).text()).toBe('Bid containers to win this cash.');
|
||||
expect(wrapper.findAll('.offshore-lot title').at(3).text()).toBe('Bid cash to win these containers.');
|
||||
wrapper.destroy();
|
||||
});
|
||||
|
||||
it('uses player tokens instead of visible bidder names for both auction types', () => {
|
||||
const { state, player, own } = fixture();
|
||||
const name = '<Trader with a long name>';
|
||||
own.name = name;
|
||||
state.offshoreBank!.auctions = [
|
||||
{ type: 'containers', lot: 0, bidder: player, cash: 3, containers: [] },
|
||||
{
|
||||
type: 'cash',
|
||||
lot: 1,
|
||||
bidder: player,
|
||||
cash: 0,
|
||||
containers: [{ container: own.containersOnFactoryStore[0], district: 'factory' }],
|
||||
},
|
||||
];
|
||||
for (const colorBlind of [false, true]) {
|
||||
const wrapper = mount(OffshoreBank, {
|
||||
provide: { __reactiveInject__: { preferences: { colorBlind } } },
|
||||
propsData: {
|
||||
state,
|
||||
player,
|
||||
availableMoves: own.availableMoves,
|
||||
playerColors: ['#123456', '#234567', '#345678'],
|
||||
},
|
||||
});
|
||||
const tokens = wrapper.findAll('.bank-bidder');
|
||||
expect(tokens.length).toBe(2);
|
||||
tokens.wrappers.forEach((token) => {
|
||||
expect(token.attributes('aria-label')).toBe(name);
|
||||
expect(token.attributes('translate')).toBe('no');
|
||||
expect(token.find('title').text()).toBe(name);
|
||||
expect(token.find('circle').attributes('fill')).toBe(['#123456', '#234567', '#345678'][player]);
|
||||
expect(token.findAll('text').wrappers.map((text) => text.text())).toEqual(
|
||||
colorBlind ? [String(player + 1)] : []
|
||||
);
|
||||
});
|
||||
expect(wrapper.findAll('.bank-board text').wrappers.some((text) => text.text().includes(name))).toBe(false);
|
||||
expect(wrapper.findAllComponents(PlayerToken).length).toBe(2);
|
||||
wrapper.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
it('selects the exact type and lot through all six SVG lots', async () => {
|
||||
const { render } = fixture();
|
||||
const wrapper = render();
|
||||
|
|
@ -285,8 +329,8 @@ describe('Offshore bank viewer', () => {
|
|||
// A 30×80 ship rotated around (15,40) spans x-25..x+55 and y+25..y+55.
|
||||
expect(ship.x - 25).toBeGreaterThanOrEqual(342);
|
||||
expect(ship.x + 55).toBeLessThanOrEqual(444);
|
||||
expect(ship.y + 25).toBe(690 + i * 44);
|
||||
expect(ship.y + 55).toBeLessThan(724 + i * 44);
|
||||
expect(ship.y + 25).toBe(685 + i * 42);
|
||||
expect(ship.y + 55).toBeLessThan(722 + i * 42);
|
||||
});
|
||||
game.destroy();
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue