Prefill pending bids and retain confirmation when revising auction additions

This commit is contained in:
coyotte508 2026-10-05 16:26:09 +02:00
commit 76ea16358e
9 changed files with 130 additions and 16 deletions

View file

@ -1,6 +1,6 @@
{
"name": "container-viewer",
"version": "2.0.14",
"version": "2.0.15",
"repository": {
"type": "git",
"url": "git+https://github.com/boardgamers/container.git",

View file

@ -61,17 +61,26 @@
</g>
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator';
import { Vue, Component, Prop } from 'vue-property-decorator';
@Component
@Component({
created(this: Calculator) {
this.value = this.initialValue ?? 0;
this.replaceFirstDigit = this.initialValue !== undefined;
},
})
export default class Calculator extends Vue {
@Prop() initialValue?: number;
value: number = 0;
replaceFirstDigit = false;
add(number) {
this.value = Math.min(999, this.value * 10 + number);
this.value = Math.min(999, (this.replaceFirstDigit ? 0 : this.value) * 10 + number);
this.replaceFirstDigit = false;
}
del() {
this.replaceFirstDigit = false;
this.value = Math.floor(this.value / 10);
}

View file

@ -19,7 +19,7 @@
<script lang="ts">
import { Vue, Component, Prop, Watch, Inject, InjectReactive } from 'vue-property-decorator';
import { ContainerState, DropZoneType, PieceType, UIData, Preferences } from '../types/ui-data';
import { EventEmitter, Listener } from 'events';
import { EventEmitter } from 'events';
import Piece from './pieces/Piece.vue';
import { Ship, Container, LoanCard } from './pieces';
import { ShipPosition } from 'container-engine/src/gamestate';
@ -57,7 +57,7 @@ export default class DropZone extends Vue {
@Prop()
availableMoves?: any;
listener?: Listener;
listener?: (...args: any[]) => void;
overlapping = false;
updateOverlapping(piece: Piece) {

View file

@ -324,12 +324,19 @@
stroke-width="2px"
rx="2px"
/>
<Calculator data-tutorial="bid" transform="translate(140, 430)" @bid="bid($event)" />
<Calculator
:key="changingBid ? editingBid : 'new-bid'"
:initialValue="changingBid ? submittedBid : undefined"
data-tutorial="bid"
transform="translate(140, 430)"
@bid="bid($event)"
/>
<Button
v-if="changingBid"
transform="translate(140, 650)"
:width="130"
text="Cancel"
icon="cancel"
@click="editingBid = null"
/>
</template>
@ -340,6 +347,7 @@
transform="translate(140, 430)"
:width="130"
text="Change bid"
icon="edit"
@click="editingBid = revisableBid"
/>
<template v-if="G && gameEnded(G)">
@ -1371,26 +1379,36 @@ export default class Game extends Vue {
get changingBid() {
return !!this.editingBid && this.editingBid === this.revisableBid;
}
get submittedBid(): number {
const player = this.G!.players[this.player!];
return this.G!.highestBidders.length ? player.additionalBid : player.bid;
}
bid(event) {
if (this.changingBid) {
this.sendMove({ name: MoveName.Bid, data: true, extraData: { price: event }, revision: this.editingBid! });
this.editingBid = null;
} else if (this.G!.highestBidders.length > 0) {
if (this.G!.highestBidders.length > 0) {
this.confirmBidVisible = true;
this.totalBid = this.G!.players[this.player!].bid + event;
this.confirmBidRevision = this.changingBid ? this.editingBid : null;
} else if (this.changingBid) {
this.sendMove({ name: MoveName.Bid, data: true, extraData: { price: event }, revision: this.editingBid! });
this.editingBid = null;
} else {
this.sendMove({ name: MoveName.Bid, data: true, extraData: { price: event } });
}
}
confirmBidRevision: string | null = null;
confirmBid() {
this.confirmBidVisible = false;
if (this.confirmBidRevision && this.confirmBidRevision !== this.revisableBid) return;
this.sendMove({
name: MoveName.Bid,
data: true,
extraData: { price: this.totalBid - this.G!.players[this.player!].bid },
...(this.confirmBidRevision ? { revision: this.confirmBidRevision } : {}),
});
this.totalBid = 0;
if (this.confirmBidRevision) this.editingBid = null;
this.confirmBidRevision = null;
}
confirmSail() {
@ -1756,7 +1774,7 @@ export default class Game extends Vue {
return (
this.ui &&
(this.ui.dragged || this.ui.selected) != null &&
(this.ui.dragged || this.ui.selected).pieceType == pieceType
(this.ui.dragged || this.ui.selected)?.pieceType == pieceType
);
}
@ -1764,7 +1782,7 @@ export default class Game extends Vue {
if (
this.ui &&
(this.ui.dragged || this.ui.selected) != null &&
(this.ui.dragged || this.ui.selected).pieceType == 'container'
(this.ui.dragged || this.ui.selected)?.pieceType == 'container'
) {
const container = (this.ui.dragged || this.ui.selected) as Container;

View file

@ -1,7 +1,26 @@
<template>
<g :class="['button', { enabled }]" @click="enabled && $emit('click')">
<g
:class="['button', { enabled }]"
role="button"
:aria-label="tooltip || text"
:aria-disabled="!enabled"
:tabindex="enabled ? 0 : -1"
@click="enabled && $emit('click')"
@keydown.enter.prevent="enabled && $emit('click')"
@keydown.space.prevent="enabled && $emit('click')"
>
<rect :width="width" height="30" fill="gainsboro" stroke="black" rx="2" />
<text text-anchor="middle" fill="black" :x="width / 2" y="16">{{ getText() }}</text>
<path
v-if="icon"
:d="icon === 'edit' ? 'M2 11L12 1L16 5L6 15L1 16Z M10 3L14 7' : 'M2 2L16 16 M16 2L2 16'"
:transform="`translate(${width / 2 - 9}, 6)`"
fill="none"
stroke="black"
stroke-width="1.8"
stroke-linecap="round"
aria-hidden="true"
/>
<text v-else text-anchor="middle" fill="black" :x="width / 2" y="16">{{ getText() }}</text>
<title>{{ tooltip || text }}</title>
</g>
</template>
@ -10,6 +29,8 @@ import { Vue, Component, Prop } from 'vue-property-decorator';
@Component
export default class Button extends Vue {
@Prop() icon?: 'edit' | 'cancel';
@Prop()
text?: string;

View file

@ -18,6 +18,7 @@ export function playerTextColor(color = ''): string {
return luminance[0] * 0.2126 + luminance[1] * 0.7152 + luminance[2] * 0.0722 > 0.179 ? '#111' : '#fff';
}
export function playerSymbol(index: number, preferences: { bgs?: { playerSymbols?: string[] } }): string {
export function playerSymbol(index: number | undefined, preferences: { bgs?: { playerSymbols?: string[] } }): string {
if (index === undefined) return '';
return playerSymbolGlyph(preferences.bgs?.playerSymbols?.[index], String(index + 1));
}

View file

@ -0,0 +1,38 @@
import { expect } from 'chai';
import Game from '@/components/Game.vue';
const options = (Game as any).options;
describe('bid revision controls', () => {
it('prefills the additional amount during a tied auction', () => {
const context = { player: 0, G: { highestBidders: [0, 1], players: [{ bid: 5, additionalBid: 2 }] } };
expect(options.computed.submittedBid.get.call(context)).to.equal(2);
});
it('keeps the total-bid confirmation when revising an additional bid', () => {
const sent: any[] = [];
const context: any = {
player: 0,
G: { highestBidders: [0, 1], players: [{ bid: 5 }] },
changingBid: true,
editingBid: 'tie-1',
revisableBid: 'tie-1',
sendMove: (move: any) => sent.push(move),
};
options.methods.bid.call(context, 3);
expect(context.confirmBidVisible).to.equal(true);
expect(context.totalBid).to.equal(8);
expect(sent).to.have.length(0);
options.methods.confirmBid.call(context);
expect(sent[0]).to.include({ revision: 'tie-1' });
expect(sent[0].extraData.price).to.equal(3);
expect(context.editingBid).to.equal(null);
});
it('does not send a revision if the auction changes during confirmation', () => {
const context = {
confirmBidRevision: 'old',
revisableBid: 'new',
sendMove: () => {
throw new Error('stale revision');
},
};
options.methods.confirmBid.call(context);
});
});

View file

@ -18,4 +18,25 @@ describe('Calculator.vue', () => {
expect(wrapper.emitted().bid![0]).to.deep.equal([1]);
expect(vm.value).to.equal(0);
});
it('prefills a revision and replaces it when entering a new amount', () => {
const wrapper = shallowMount(Calculator, { propsData: { initialValue: 12 } });
const vm = wrapper.vm as any;
expect(vm.value).to.equal(12);
vm.add(8);
expect(vm.value).to.equal(8);
vm.add(5);
vm.bid();
expect(wrapper.emitted().bid![0]).to.deep.equal([85]);
wrapper.destroy();
});
it('can submit the unchanged bid or backspace the prefilled value', () => {
const wrapper = shallowMount(Calculator, { propsData: { initialValue: 12 } });
const vm = wrapper.vm as any;
vm.del();
expect(vm.value).to.equal(1);
vm.add(3);
vm.bid();
expect(wrapper.emitted().bid![0]).to.deep.equal([13]);
wrapper.destroy();
});
});

View file

@ -12,6 +12,12 @@ module.exports = {
disableHostCheck: true,
},
chainWebpack: (config) => {
if (config.plugins.has('fork-ts-checker')) {
config.plugin('fork-ts-checker').tap((args) => {
args[0].vue.compiler = 'vue-template-compiler';
return args;
});
}
// App and library builds use different Vue import transforms.
for (const name of ['js', 'ts', 'tsx', 'vue']) {
const rule = config.module.rule(name);