Compact bank bidding controls and highlight selected lots

This commit is contained in:
coyotte508 2026-11-18 22:28:16 +00:00
commit e7b9c48c09
4 changed files with 149 additions and 39 deletions

View file

@ -79,10 +79,31 @@ try {
assert.ok(pierBounds.x - lotBounds.x - lotBounds.width < 12, 'harbor joins the bank, not a distant area');
assert.equal(await page.getByText('BANK HARBOR', { exact: true }).count(), 0);
await page.locator('.offshore-lot[data-type="containers"][data-lot="2"]').click();
assert.equal(
(await page.locator('.bank-bid-guidance').textContent()).trim(),
'Bid cash to win these containers.'
);
const checkDraft = async (type, lot) => {
const selected = page.locator('.offshore-lot.selected');
assert.equal(await selected.count(), 1);
assert.equal(await selected.getAttribute('data-type'), type);
assert.equal(await selected.getAttribute('data-lot'), String(lot));
assert.equal(await selected.getAttribute('aria-pressed'), 'true');
assert.equal(await selected.evaluate((el) => getComputedStyle(el).stroke), 'rgb(0, 0, 255)');
assert.equal(await page.locator('.bank-bid-guidance').count(), 0);
const draft = page.locator('.bank-draft');
await draft.scrollIntoViewIfNeeded();
const bounds = await draft.boundingBox();
const svg = await draft.evaluate((el) => {
const r = el.ownerSVGElement.getBoundingClientRect();
return { x: r.x, y: r.y, right: r.right, bottom: r.bottom };
});
assert.ok(
bounds.x >= svg.x &&
bounds.y >= svg.y &&
bounds.x + bounds.width <= svg.right + 1 &&
bounds.y + bounds.height <= svg.bottom + 1,
'draft within SVG'
);
assert.ok(bounds.x >= 0 && bounds.x + bounds.width <= width + 1, 'complete draft visible horizontally');
};
await checkDraft('containers', 2);
const calculator = page.locator('[data-tutorial="bank-bid"]');
await calculator.focus();
await calculator.press('9');
@ -100,6 +121,13 @@ try {
await push();
assert.match(await page.locator('.bank-bid-amount').textContent(), /^\$2/);
assert.equal(await page.locator('.bank-bid-amount').getAttribute('font-size'), '16');
const tokenBounds = await page.locator('.bank-bidder circle').first().boundingBox();
const amountBounds = await page.locator('.bank-bid-amount').boundingBox();
assert.ok(amountBounds.x > tokenBounds.x + tokenBounds.width, 'cash bid is beside, not below, the token');
assert.ok(
Math.abs(amountBounds.y + amountBounds.height / 2 - tokenBounds.y - tokenBounds.height / 2) < 8,
'cash bid and token are aligned'
);
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);
@ -122,6 +150,11 @@ try {
await page.locator(`.bank-draft [data-piece-id="${offered.id}"]`).click();
await page.locator(`.bank-draft [data-piece-id="${second.id}"]`).click();
assert.equal(await page.evaluate(() => moves.length), 0, 'selection never auto-submits');
await checkDraft('cash', 1);
await page.screenshot({ path: `/tmp/container-offshore-cargo-draft-${width}.png`, fullPage: true });
const confirmBounds = await page.getByRole('button', { name: 'Confirm offer', exact: true }).boundingBox();
const cancelBounds = await page.getByRole('button', { name: 'Cancel', exact: true }).boundingBox();
assert.equal(confirmBounds.y, cancelBounds.y, 'cargo actions share one row');
await page.getByRole('button', { name: 'Confirm offer', exact: true }).click();
const cargoBid = await page.evaluate(() => moves.at(-1));
assert.equal(cargoBid.at(-1).name, 'callBank');
@ -203,6 +236,9 @@ try {
.locator('.piece')
.filter({ hasText: `${state.players[player].name}'s Ship` })
.click();
assert.equal(await page.locator('.bank-harbor').count(), 5);
assert.equal(await page.locator('.bank-harbor.showDrop').count(), 1);
assert.equal(await page.locator('.bank-harbor.canClick').getAttribute('data-berth'), String(player));
await page.locator('.bank-harbor.canClick').click();
const sailing = await page.evaluate(() => moves.at(-1));
assert.deepEqual(sailing.at(-1), { name: 'sail', data: 'offshoreBank' });

View file

@ -195,6 +195,7 @@
<g v-if="G && G.options.offshoreIsland">
<OffshoreBank
:selectedOffer="bankDraft"
:state="G"
:player="player"
:player-colors="playerColors"
@ -203,17 +204,21 @@
@choose-offer="chooseBankOffer"
/>
</g>
<DropZone
v-if="G && G.options.offshoreIsland"
class="bank-harbor"
transform="translate(336 684)"
:width="108"
:height="210"
:enabled="true"
:accepts="'ship'"
:data="{ type: 'offshoreBank' }"
:available-moves="getCurrentPlayerMoves()"
/>
<template v-if="G && G.options.offshoreIsland">
<DropZone
v-for="berth in 5"
:key="'bank-berth-' + berth"
class="bank-harbor"
:data-berth="berth - 1"
:transform="`translate(336 ${684 + (berth - 1) * 42})`"
:width="108"
:height="38"
:enabled="canMove && player === berth - 1"
:accepts="'ship'"
:data="{ type: 'offshoreBank' }"
:available-moves="getCurrentPlayerMoves()"
/>
</template>
<Ship
v-for="ship in ships"
:key="ship.id"
@ -373,18 +378,23 @@
</template>
</template>
<g v-if="bankDraft && canMove" class="bank-draft" transform="translate(470 700)">
<text x="0" y="-26" font-size="12">
{{ bankDraft.type === 'cash' ? 'Offer cargo' : 'Offer cash' }} · Lot
{{ ['I', 'II', 'III'][bankDraft.lot] }}
</text>
<text class="bank-bid-guidance" x="0" y="-9" font-size="12" fill="#45585b">
{{
bankDraft.type === 'cash'
? 'Bid containers to win this cash.'
: 'Bid cash to win these containers.'
}}
</text>
<g
v-if="bankDraft && canMove"
class="bank-draft"
transform="translate(470 680)"
role="group"
:aria-label="bankDraft.type === 'cash' ? 'Offer cargo' : 'Offer cash'"
>
<rect
x="-5"
y="-5"
:width="bankDraft.type === 'cash' ? 194 : 180"
:height="bankDraft.type === 'cash' ? bankCargoActionsY + 40 : 220"
fill="transparent"
stroke="blue"
stroke-width="2"
rx="2"
/>
<Calculator
v-if="bankDraft.type === 'containers'"
:key="bankDraft.lot + ':' + draftsVersion"
@ -406,15 +416,33 @@
@select="toggleBankContainer"
/>
<Button
transform="translate(0 155)"
:width="130"
text="Confirm offer"
:transform="`translate(0 ${bankCargoActionsY})`"
:width="88"
text="Bid"
tooltip="Confirm offer"
:enabled="validContainerBid"
@click="confirmBankContainers"
/>
</template>
<text v-if="bankBidError" x="0" y="215" font-size="11" fill="#9b2424">Invalid offer</text>
<Button transform="translate(0 220)" :width="130" text="Cancel" @click="resetBankDraft" />
<text
v-if="bankBidError"
x="0"
:y="bankDraft.type === 'cash' ? bankCargoActionsY + 49 : 232"
font-size="11"
fill="#9b2424"
role="alert"
>
Invalid offer
</text>
<Button
:transform="
bankDraft.type === 'cash' ? `translate(96 ${bankCargoActionsY})` : 'translate(140 180)'
"
:width="bankDraft.type === 'cash' ? 88 : 30"
text="Cancel"
icon="cancel"
@click="resetBankDraft"
/>
</g>
<Button
@ -1605,7 +1633,7 @@ export default class Game extends Vue {
const target = this.$el.querySelector(
action ? '.bank-draft' : this.G?.offshoreBank?.decision ? '.bank-decision' : '.bank-board'
);
target?.scrollIntoView?.({ block: 'nearest', inline: 'start', behavior: 'auto' });
target?.scrollIntoView?.({ block: 'nearest', inline: 'nearest', behavior: 'auto' });
});
}
chooseBankOffer(offer: { type: 'cash' | 'containers'; lot: number }) {
@ -1642,6 +1670,12 @@ export default class Game extends Vue {
if (this.bankDraft?.type !== 'containers') return;
this.sendBankMove({ name: MoveName.CallBank, data: { ...this.bankDraft }, extraData: { cash } });
}
get bankCargoActionsY() {
return (
Math.min(8, Math.max(1, Math.ceil(this.bankBidCargo.length / 8))) * 13 +
(this.bankBidCargo.length > 64 ? 26 : 12)
);
}
get bankBidCargo() {
if (!this.canMove) return [];
const p = this.G!.players[this.player!];

View file

@ -18,7 +18,15 @@
>
<rect
class="offshore-lot"
:class="{ legal: offer(type, i - 1) }"
:class="{
legal: offer(type, i - 1),
selected: selectedOffer?.type === type && selectedOffer?.lot === i - 1,
}"
:aria-pressed="
offer(type, i - 1)
? selectedOffer?.type === type && selectedOffer?.lot === i - 1
: undefined
"
:data-type="type"
:data-lot="i - 1"
width="100"
@ -60,7 +68,7 @@
<g v-if="auction(type, i - 1)">
<PlayerToken
class="bank-bidder"
:transform="`translate(16 ${type === 'cash' ? 33 : 94})`"
:transform="`translate(16 ${type === 'cash' ? 52 : 86})`"
:owner="auction(type, i - 1).bidder"
:name="owner(auction(type, i - 1).bidder)"
:color="playerColors[auction(type, i - 1).bidder]"
@ -68,11 +76,11 @@
<OffshoreCargo
v-if="type === 'cash'"
:pieces="escrow(auction(type, i - 1))"
transform="translate(6 44)"
:columns="3"
transform="translate(32 47)"
:columns="2"
:rows="2"
/>
<text v-else class="bank-money bank-bid-amount" x="94" y="94" font-size="16" text-anchor="end"
<text v-else class="bank-money bank-bid-amount" x="32" y="86" font-size="16" text-anchor="start"
>${{ auction(type, i - 1).cash }}<title>Cash bid</title></text
>
</g>
@ -196,6 +204,7 @@ import PlayerToken from './PlayerToken.vue';
export default class OffshoreBank extends Vue {
@Prop({ required: true }) state!: GameState;
@Prop() player?: number;
@Prop() selectedOffer?: { type: BankAuctionType; lot: number };
@Prop({ default: () => ({}) }) availableMoves!: AvailableMoves;
@Prop({ default: () => playerColors }) playerColors!: string[];
names = MoveName;
@ -280,10 +289,15 @@ export default class OffshoreBank extends Vue {
</script>
<style scoped>
.offshore-lot.legal {
stroke: #1b6c87;
stroke: blue;
stroke-width: 2;
cursor: pointer;
}
.offshore-lot.selected {
fill: #d6e4ff;
stroke: blue;
stroke-width: 3;
}
.offshore-lot[role='button']:hover,
.offshore-lot[role='button']:focus-visible,
[role='button']:focus-visible > rect {

View file

@ -104,6 +104,20 @@ describe('Offshore bank viewer', () => {
});
const tokens = wrapper.findAll('.bank-bidder');
expect(tokens.length).toBe(2);
expect(tokens.wrappers.map((t) => t.attributes('transform'))).toEqual([
'translate(16 52)',
'translate(16 86)',
]);
tokens.wrappers.forEach((t) => expect(t.find('circle').attributes('r')).toBe('9'));
const amount = wrapper.find('.bank-bid-amount');
expect(amount.attributes('x')).toBe('32');
expect(amount.attributes('y')).toBe('86');
expect(amount.attributes('text-anchor')).toBe('start');
const escrow = wrapper
.findAllComponents(OffshoreCargo)
.wrappers.find((c) => c.attributes('transform') === 'translate(32 47)')!;
expect(escrow.props('columns')).toBe(2);
expect(escrow.props('rows')).toBe(2);
tokens.wrappers.forEach((token) => {
expect(token.attributes('aria-label')).toBe(name);
expect(token.attributes('translate')).toBe('no');
@ -123,6 +137,10 @@ describe('Offshore bank viewer', () => {
const { render } = fixture();
const wrapper = render();
expect(wrapper.findAll('.offshore-lot').length).toBe(6);
await wrapper.setProps({ selectedOffer: { type: 'cash', lot: 1 } });
expect(wrapper.findAll('.offshore-lot.selected').length).toBe(1);
expect(wrapper.find('.offshore-lot.selected').attributes('data-lot')).toBe('1');
expect(wrapper.find('.offshore-lot.selected').attributes('aria-pressed')).toBe('true');
for (const type of ['cash', 'containers'])
for (let lot = 0; lot < 3; lot++) {
await wrapper.find(`[data-type="${type}"][data-lot="${lot}"]`).trigger('click');
@ -322,6 +340,14 @@ describe('Offshore bank viewer', () => {
preferences: { sound: false },
},
});
const berths = game.findAll('.bank-harbor');
expect(berths.length).toBe(5);
berths.wrappers.forEach((berth, i) => {
expect(berth.attributes('transform')).toBe(`translate(336 ${684 + i * 42})`);
expect(berth.props('width')).toBe(108);
expect(berth.props('height')).toBe(38);
expect(berth.props('enabled')).toBe(i === state.currentPlayers[0]);
});
const ships = (game.vm as any).ships;
expect(ships).toHaveLength(5);
ships.forEach((ship, i) => {