Focus bank cargo bidding on board pieces and cancel zero cash drafts locally

This commit is contained in:
coyotte508 2026-11-18 23:29:02 +00:00
commit bfa8389a99
5 changed files with 144 additions and 50 deletions

View file

@ -103,6 +103,22 @@ try {
);
assert.ok(bounds.x >= 0 && bounds.x + bounds.width <= width + 1, 'complete draft visible horizontally');
};
// Zero cancels this bank draft only, by either mouse or keyboard.
for (const keyboard of [false, true]) {
const zeroCalculator = page.locator('[data-tutorial="bank-bid"]');
assert.equal(
await page.locator('.bank-draft').getByRole('button', { name: 'Cancel', exact: true }).count(),
0
);
if (keyboard) {
await zeroCalculator.focus();
await zeroCalculator.press('0');
await zeroCalculator.press('Enter');
} else await zeroCalculator.getByRole('button', { name: 'Bid', exact: true }).click();
assert.equal(await page.locator('.bank-draft, .offshore-lot.selected').count(), 0);
assert.equal(await page.evaluate(() => moves.length), 0);
await page.locator('.offshore-lot[data-type="containers"][data-lot="2"]').click();
}
await checkDraft('containers', 2);
const calculator = page.locator('[data-tutorial="bank-bid"]');
await calculator.focus();
@ -147,9 +163,36 @@ try {
state.players[player].containersOnWarehouseStore.push({ piece: second, price: 3, moved: false });
await push();
await page.locator('.offshore-lot[data-type="cash"][data-lot="1"]').click();
await page.locator(`.bank-draft [data-piece-id="${offered.id}"]`).click();
await page.locator(`.bank-draft [data-piece-id="${second.id}"]`).click();
await page.locator(`.piece.bid-eligible[data-piece-id="${offered.id}"]`).click();
await page.locator(`.piece.bid-eligible[data-piece-id="${second.id}"]`).click();
assert.equal(await page.evaluate(() => moves.length), 0, 'selection never auto-submits');
assert.equal(await page.locator('.piece.canDrag, .loan.canDrag, .offshore-lot.legal').count(), 0);
assert.equal(await page.locator('.piece.bid-selected').count(), 2);
assert.equal(
await page.locator('rect[stroke="blue"]').count(),
1,
'only draft frame remains, no ordinary action outlines'
);
const selectedPiece = page.locator(`.piece[data-piece-id="${second.id}"]`);
await selectedPiece.focus();
await selectedPiece.press('Space');
assert.equal(await selectedPiece.getAttribute('aria-pressed'), 'false');
await selectedPiece.press('Enter');
assert.equal(await selectedPiece.getAttribute('aria-pressed'), 'true');
if (width < 600) await page.locator('.player-board-tab').nth(player).click();
await page.screenshot({ path: `/tmp/container-offshore-cargo-focus-${width}.png`, fullPage: true });
await page.getByRole('button', { name: 'Cancel', exact: true }).click();
assert.equal(await page.locator('.bid-eligible, .bid-selected, .bank-draft').count(), 0);
assert.ok((await page.locator('.piece.canDrag').count()) > 0, 'cancel restores ordinary actions');
assert.equal(await page.evaluate(() => moves.length), 0);
await page.locator('.offshore-lot[data-type="cash"][data-lot="1"]').click();
await page.locator(`.piece.bid-eligible[data-piece-id="${offered.id}"]`).click();
await page.locator(`.piece.bid-eligible[data-piece-id="${second.id}"]`).click();
if (width < 600) {
await page.getByRole('button', { name: 'Bid (2)', exact: true }).click();
assert.equal(await page.locator('.piece.bid-selected').count(), 2, 'navigation preserves draft');
}
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();

View file

@ -45,6 +45,7 @@
><span class="player-board-name" :data-bgs-player="i">{{ i === player ? 'You' : p.name }}</span>
</button>
<button v-if="G.options.offshoreIsland" @click="viewBank()">Bank</button>
<button v-if="bankCashOffer" @click="viewBank(true)">Bid ({{ offshoreContainers.size }})</button>
</div>
<div v-if="!ui.selected && mobileOffers.length" class="mobile-trade" aria-label="Containers for sale">
<span>Buy from {{ G.players[mobilePlayer].name }}</span>
@ -243,6 +244,9 @@
rotate: container.rotate,
}"
:canDrag="canDragContainer(container)"
:bidEligible="bankContainerHighlights.includes(container.id)"
:bidSelected="offshoreContainers.has(container.id)"
@bid-select="toggleBankContainer(container.id)"
:color="container.color"
:owner="container.owner"
:state="container.state"
@ -386,9 +390,10 @@
:aria-label="bankDraft.type === 'cash' ? 'Offer cargo' : 'Offer cash'"
>
<rect
v-if="bankDraft.type === 'cash' || !preferences.disableHelp"
x="-5"
y="-5"
:width="bankDraft.type === 'cash' ? 194 : 180"
:width="bankDraft.type === 'cash' ? 194 : 140"
:height="bankDraft.type === 'cash' ? bankCargoActionsY + 40 : 220"
fill="transparent"
stroke="blue"
@ -407,14 +412,7 @@
@bid="bankBid"
/>
<template v-else>
<OffshoreCargo
:pieces="bankBidCargo"
:columns="8"
:rows="8"
:selectable="bankContainerHighlights"
:selected="Array.from(offshoreContainers)"
@select="toggleBankContainer"
/>
<text x="0" y="12" font-size="14">{{ offshoreContainers.size }}</text>
<Button
:transform="`translate(0 ${bankCargoActionsY})`"
:width="88"
@ -435,10 +433,9 @@
Invalid offer
</text>
<Button
:transform="
bankDraft.type === 'cash' ? `translate(96 ${bankCargoActionsY})` : 'translate(140 180)'
"
:width="bankDraft.type === 'cash' ? 88 : 30"
v-if="bankDraft.type === 'cash'"
:transform="`translate(96 ${bankCargoActionsY})`"
:width="88"
text="Cancel"
icon="cancel"
@click="resetBankDraft"
@ -462,22 +459,7 @@
/>
</template>
<template v-if="!preferences.disableHelp && canMove">
<g v-for="pieceId in bankContainerHighlights" :key="'bank-cargo-' + pieceId">
<rect
v-for="piece in containers.filter((p) => p.id === pieceId)"
:key="piece.id"
:x="piece.x - 2"
:y="piece.y - 2"
width="24"
height="14"
fill="none"
stroke="blue"
stroke-width="2"
/>
</g>
</template>
<template v-if="!preferences.disableHelp">
<template v-if="!preferences.disableHelp && !bankCashOffer">
<template v-if="ui.dragged == null && ui.selected == null">
<rect
v-if="canBuyFactory('orange')"
@ -846,7 +828,6 @@
<script lang="ts">
import InlineLog from './InlineLog.vue';
import OffshoreBank from './OffshoreBank.vue';
import OffshoreCargo from './OffshoreCargo.vue';
import { legalBankAction } from '../offshore-actions';
import { islandValue } from '../island-value';
import ColorBlindButton from './buttons/ColorBlindButton.vue';
@ -878,7 +859,6 @@ import { GameEventName, LogMove } from 'container-engine/src/log';
components: {
InlineLog,
OffshoreBank,
OffshoreCargo,
PlayerBoard,
Container,
Factory,
@ -1332,7 +1312,10 @@ export default class Game extends Vue {
this.mobilePlayer = index;
this.$nextTick(() => {
const board = this.$refs.boardScroll as HTMLElement;
board.scrollTo({ left: (index * 250 * board.scrollWidth) / 1250, behavior: 'smooth' });
board?.scrollTo?.({
left: (index * 250 * board.scrollWidth) / 1250,
behavior: this.bankCashOffer ? 'auto' : 'smooth',
});
});
}
@ -1382,6 +1365,7 @@ export default class Game extends Vue {
}
onPieceDrop(e: PieceComponent, d: any) {
if (this.bankCashOffer) return;
this.ui.selected = null;
const currentPlayer = this.G!.currentPlayers[0];
switch (e.pieceType) {
@ -1647,9 +1631,16 @@ export default class Game extends Vue {
)
return;
this.resetBankDraft();
this.ui.selected = null;
(this.ui.dragged as PieceComponent | null)?.cancelDrag();
this.bankDraft = { ...offer };
this.draftsVersion++;
this.viewBank(true);
if (offer.type === 'cash') {
this.viewPlayerBoard(this.player!);
this.$nextTick(() =>
this.$el.querySelector('.bid-eligible')?.scrollIntoView?.({ block: 'nearest', inline: 'nearest' })
);
} else this.viewBank(true);
}
sendBankMove(action: Move) {
if (this.canMove && this.G && legalBankAction(this.G, this.player, action)) {
@ -1672,14 +1663,16 @@ export default class Game extends Vue {
}
bankBid(cash: number) {
if (this.bankDraft?.type !== 'containers') return;
if (cash === 0) {
this.resetBankDraft();
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)
);
return 25;
}
get bankBidCargo() {
if (!this.canMove) return [];
const p = this.G!.players[this.player!];
@ -1733,6 +1726,7 @@ export default class Game extends Vue {
}
sendMove(move: Move) {
if (this.bankCashOffer) return;
if (
[
MoveName.CallBank,
@ -1785,7 +1779,7 @@ export default class Game extends Vue {
}
canDragContainer(container: Piece) {
if (!this.canMove) return false;
if (!this.canMove || this.bankCashOffer) return false;
const currentPlayer = this.G!.players[this.player!];
const availableMoves = currentPlayer.availableMoves!;
@ -1830,7 +1824,7 @@ export default class Game extends Vue {
}
canDragFactory(factory: Piece) {
if (!this.canMove) return false;
if (!this.canMove || this.bankCashOffer) return false;
const currentPlayer = this.G!.players[this.player!];
const availableMoves = currentPlayer.availableMoves!;
@ -1842,7 +1836,7 @@ export default class Game extends Vue {
}
canDragWarehouse(warehouse: Piece) {
if (!this.canMove) return false;
if (!this.canMove || this.bankCashOffer) return false;
const currentPlayer = this.G!.players[this.player!];
const availableMoves = currentPlayer.availableMoves!;
@ -1853,7 +1847,7 @@ export default class Game extends Vue {
}
canDragLoan(loanCard: Piece) {
if (!this.canMove) return false;
if (!this.canMove || this.bankCashOffer) return false;
const currentPlayer = this.G!.players[this.player!];
const availableMoves = currentPlayer.availableMoves!;
@ -1868,7 +1862,7 @@ export default class Game extends Vue {
}
canDragShip(ship: Piece) {
if (!this.canMove) return false;
if (!this.canMove || this.bankCashOffer) return false;
const currentPlayer = this.G!.players[this.player!];
const availableMoves = currentPlayer.availableMoves!;
@ -1877,7 +1871,7 @@ export default class Game extends Vue {
}
canPass() {
if (!this.canMove) return false;
if (!this.canMove || this.bankCashOffer) return false;
const currentPlayer = this.G!.players[this.player!];
const availableMoves = currentPlayer.availableMoves!;

View file

@ -19,7 +19,7 @@
<rect
class="offshore-lot"
:class="{
legal: offer(type, i - 1),
legal: selectedOffer?.type !== 'cash' && offer(type, i - 1),
selected: !bank.decision && selectedOffer?.type === type && selectedOffer?.lot === i - 1,
destination:
bank.decision?.kind === 'distribute' &&

View file

@ -1,7 +1,15 @@
<template>
<g
:id="elId"
:class="['piece', { dragging, canDrag }]"
:class="['piece', { dragging, canDrag, 'bid-eligible': bidEligible, 'bid-selected': bidSelected }]"
:data-piece-id="pieceId"
:role="bidEligible ? 'button' : undefined"
:tabindex="bidEligible ? 0 : undefined"
:aria-label="bidEligible ? `${color} container` : undefined"
:aria-pressed="bidEligible ? String(bidSelected) : undefined"
@click.stop="selectBid"
@keydown.enter.prevent="selectBid"
@keydown.space.prevent="selectBid"
:transform="`translate(${currentX}, ${currentY}) rotate(${rotate}, 10, 5)`"
>
<rect width="20" height="10" rx=".8" :fill="color" stroke="#21343b" />
@ -25,6 +33,16 @@ import ColorMark from '../ColorMark.vue';
},
})
export default class Container extends Mixins(Piece) {
@Prop({ default: false })
bidEligible!: boolean;
@Prop({ default: false })
bidSelected!: boolean;
selectBid() {
if (this.bidEligible) this.$emit('bid-select');
}
@Prop()
color?: string;
@ -35,3 +53,22 @@ export default class Container extends Mixins(Piece) {
state?: ContainerState;
}
</script>
<style scoped>
.bid-eligible {
cursor: pointer;
}
.bid-eligible > rect {
stroke: blue;
stroke-width: 1.5;
}
.bid-selected > rect {
stroke: #ffe154;
stroke-width: 2.5;
filter: drop-shadow(0 0 1px #142f69);
}
.bid-eligible:focus-visible {
outline: 2px solid blue;
outline-offset: 3px;
}
</style>

View file

@ -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 Container from '@/components/pieces/Container.vue';
import PlayerToken from '@/components/PlayerToken.vue';
import { legalBankAction } from '@/offshore-actions';
import { escapeJournal, offshoreJournal } from '@/offshore-journal';
@ -184,13 +185,30 @@ describe('Offshore bank viewer', () => {
wrapper.destroy();
});
it('cancels a bank cash draft locally with Bid 0', async () => {
const { wrapper, submitted } = gameFixture();
wrapper.findComponent(OffshoreBank).vm.$emit('choose-offer', { type: 'containers', lot: 2 });
await wrapper.vm.$nextTick();
expect(wrapper.find('.bank-draft').findAllComponents({ name: 'Button' }).length).toBe(0);
wrapper.findComponent(Calculator).vm.$emit('bid', 0);
await wrapper.vm.$nextTick();
expect(submitted).toEqual([]);
expect(wrapper.find('.bank-draft').exists()).toBe(false);
expect(wrapper.findComponent(OffshoreBank).props('selectedOffer')).toBe(null);
wrapper.destroy();
});
it('requires explicit confirmation for multiple cargo pieces and supports cancel', async () => {
const { wrapper, submitted, factory, warehouse } = gameFixture();
wrapper.findComponent(OffshoreBank).vm.$emit('choose-offer', { type: 'cash', lot: 1 });
await wrapper.vm.$nextTick();
const cargo = wrapper.find('.bank-draft').findComponent(OffshoreCargo);
cargo.vm.$emit('select', factory.id);
cargo.vm.$emit('select', warehouse.id);
const pieces = wrapper.findAllComponents(Container);
expect(pieces.wrappers.every((piece) => !piece.props('canDrag'))).toBe(true);
for (const id of [factory.id, warehouse.id]) {
const piece = pieces.wrappers.find((piece) => piece.props('pieceId') === id)!;
expect(piece.props('bidEligible')).toBe(true);
piece.vm.$emit('bid-select');
}
await wrapper.vm.$nextTick();
expect(submitted.length).toBe(0);
const buttons = wrapper.find('.bank-draft').findAllComponents({ name: 'Button' });
@ -206,12 +224,14 @@ describe('Offshore bank viewer', () => {
it('cancels a draft without submitting and paginates large cargo without losing access', async () => {
const { wrapper, submitted } = gameFixture();
const before = wrapper.findAllComponents(Container).wrappers.map((p) => !!p.props('canDrag'));
wrapper.findComponent(OffshoreBank).vm.$emit('choose-offer', { type: 'cash', lot: 0 });
await wrapper.vm.$nextTick();
wrapper.find('.bank-draft').findAllComponents({ name: 'Button' }).at(1).vm.$emit('click');
await wrapper.vm.$nextTick();
expect(wrapper.find('.bank-draft').exists()).toBe(false);
expect(submitted.length).toBe(0);
expect(wrapper.findAllComponents(Container).wrappers.map((p) => !!p.props('canDrag'))).toEqual(before);
wrapper.destroy();
const pieces = Array.from({ length: 103 }, (_, i) => ({ id: `large-${i}`, color: 'orange' }));
const cargo = mount(OffshoreCargo, {