Keep extra collection tiles selected while resolving capacity
This commit is contained in:
parent
d633b0543e
commit
691dc72811
6 changed files with 44 additions and 6 deletions
|
|
@ -427,3 +427,5 @@ Verified with 846 frontend/engine tests, 54 incident/tactics Rust tests, 16 loca
|
|||
Viewer 0.1.152 renders transported units as individual 3D pieces alongside their ships, with spacing for mixed stacks. Nested and flattened passenger records are deduplicated. Removed the forced passenger badge; normal badge preferences still apply. Verified in a browser with two ships and two passengers, plus 847 frontend tests, locale validation, type checking and production build. Engine remains 0.4.105.
|
||||
|
||||
Viewer 0.1.153 prefers an eligible free collection when opening Collect from a city or terrain shortcut, including Free Economy and Acamapichtli's Tributes. City-specific eligibility prevents selecting Tributes outside his city. When all available tiles fit collection capacity, single-choice tiles are preselected while multiple-choice tiles such as Ports remain open for the player's resource choice. Verified with 849 frontend/engine tests, including both controller regressions, locale validation, type checking and production build. Engine remains 0.4.105.
|
||||
|
||||
Viewer 0.1.154 keeps an additional collection tile visibly selected when it exceeds capacity. Collect stays disabled until the player removes a selection; invalid quotes also clear stale action previews while retaining the draft. Bonus and storage forecasts continue to consider only legal additions. Verified with 850 frontend/engine tests, including over-selection and recovery, locale validation, type checking and production build. Engine remains 0.4.105.
|
||||
|
|
|
|||
4
web-client/package-lock.json
generated
4
web-client/package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.153",
|
||||
"version": "0.1.154",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.153",
|
||||
"version": "0.1.154",
|
||||
"dependencies": {
|
||||
"@boardgamers/protocol": "0.9.0",
|
||||
"lucide-svelte": "^0.577.0",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@boardgamers/clash-web-client",
|
||||
"version": "0.1.153",
|
||||
"version": "0.1.154",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ export function nextCollectionSelection(
|
|||
selection: Selection[],
|
||||
city: CityView,
|
||||
extraCapacity = 0,
|
||||
allowOverCapacity = false,
|
||||
) {
|
||||
const selected = selection.find((c) => sameCollection(c, choice));
|
||||
const sameTile = selection.find((c) => c.position === choice.position);
|
||||
|
|
@ -75,7 +76,7 @@ export function nextCollectionSelection(
|
|||
? selection.map((c) => (c === sameTile ? { ...choice, times: 1 } : c))
|
||||
: [...selection, { ...choice, times: 1 }];
|
||||
const nextIsValid =
|
||||
next.reduce((sum, c) => sum + c.times, 0) <= capacity &&
|
||||
(allowOverCapacity || next.reduce((sum, c) => sum + c.times, 0) <= capacity) &&
|
||||
next.filter((c) => c.position === choice.position).reduce((sum, c) => sum + c.times, 0) <=
|
||||
city.maxPerTile;
|
||||
return nextIsValid ? next : null;
|
||||
|
|
|
|||
|
|
@ -2839,3 +2839,34 @@ test('forced collection preselects single-choice tiles while leaving Port resour
|
|||
assert.deepEqual(app.sent, []);
|
||||
} finally { app.close(); }
|
||||
});
|
||||
|
||||
test('an extra collection tile remains selected until the player resolves the capacity warning', async () => {
|
||||
const app = paymentController(), c = app.controller;
|
||||
try {
|
||||
const raw = await engine.init(2, [], {}, 'collect-all-tiles', {});
|
||||
const seat = engine.currentPlayer(raw);
|
||||
c.setPlayer(seat);
|
||||
await c.load(engine.stripSecret(raw, seat));
|
||||
const city = app.session().view!.cities[0];
|
||||
const choices = [...new Map(city.choices.map(choice => [choice.position, choice])).values()];
|
||||
assert(choices.length > city.capacity);
|
||||
c.beginCollect(city.position);
|
||||
for (const choice of choices.slice(0, city.capacity)) c.toggleChoice(choice);
|
||||
assert(app.session().preview?.action);
|
||||
const extra = choices[city.capacity];
|
||||
c.toggleChoice(extra);
|
||||
assert(app.session().selection.some(choice => choice.position === extra.position));
|
||||
assert.equal(app.session().selection.length, city.capacity + 1);
|
||||
assert.equal(app.session().preview, null);
|
||||
assert.match(app.session().error, /Remove a selection/);
|
||||
c.collect();
|
||||
assert.deepEqual(app.sent, []);
|
||||
c.toggleChoice(choices[0]);
|
||||
assert.equal(app.session().selection.length, city.capacity);
|
||||
assert(app.session().selection.some(choice => choice.position === extra.position));
|
||||
assert.equal(app.session().error, '');
|
||||
assert(app.session().preview?.action);
|
||||
c.collect();
|
||||
assert.equal(app.sent.length, 1);
|
||||
} finally { app.close(); }
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1782,13 +1782,17 @@ export class Controller {
|
|||
const city = s.view.cities.find((c) => c.position === s.city)!;
|
||||
const extraCapacity = Number(!!s.ballcourts && !!city.ballcourts);
|
||||
const capacity = city.capacity + extraCapacity;
|
||||
const selection = nextCollectionSelection(choice, s.selection, city, extraCapacity);
|
||||
const selection = nextCollectionSelection(choice, s.selection, city, extraCapacity, true);
|
||||
if (!selection) {
|
||||
this.patch({
|
||||
error: `Choose up to ${capacity} ${capacity === 1 ? 'tile' : 'tiles'} total. Remove a selection first.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (selection.reduce((sum, tile) => sum + tile.times, 0) > capacity) {
|
||||
this.patch({ selection, preview: null, error: `Choose up to ${capacity} ${capacity === 1 ? 'tile' : 'tiles'} total. Remove a selection to collect.` });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const preview = selection.length
|
||||
? this.query<NonNullable<Session['preview']>>({
|
||||
|
|
@ -1801,7 +1805,7 @@ export class Controller {
|
|||
: null;
|
||||
this.patch({ selection, preview, error: '' });
|
||||
} catch (error) {
|
||||
this.patch({ error: String(error) });
|
||||
this.patch({ selection, preview: null, error: String(error) });
|
||||
}
|
||||
}
|
||||
startInfluence(move: Move, actionPayment: Pile, rangePayment: Pile) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue