Preserve mixed token amounts in Uprising payments

This commit is contained in:
coyotte508 2026-10-16 00:26:26 +02:00
commit 48055942cd
8 changed files with 34 additions and 5 deletions

View file

@ -188,7 +188,8 @@ fn resource_field(
.unique()
.collect::<Vec<_>>();
json!({"name":name,"optional":optional,"resources":types,"initial":if reward {cost.default_payment()} else {cost.first_valid_payment(available).unwrap_or_default()},"cost":cost.default_payment(),
"choices":payment_choices(cost, stock, reward, optional)})
"choices":payment_choices(cost, stock, reward, optional),
"variableAmount":cost.conversions.iter().any(|c| c.to.is_empty() && matches!(c.payment_conversion_type, crate::payment::PaymentConversionType::MayOverpay(_)))})
}
// Present complete, engine-validated payments. Large choice spaces use direct

View file

@ -375,3 +375,5 @@ Viewer 0.1.127 / engine 0.4.91 counts Mercenaries targets by distinct Barbarian
Viewer 0.1.128 / engine 0.4.92 prefers human-city trade routes over Barbarian routes for Celts with Currency, after maximizing route count. This preserves food/gold options in actual rewards and prevents false unavoidable-food-waste forecasts.
Viewer 0.1.129 names publicly completed objectives in replay and live action captions, including existing recorded frames, without duplicating their completion effect.
Viewer 0.1.130 / engine 0.4.93 preserves mixed mood/culture allocations for variable token payments such as Uprising, while ordinary costs still remove unnecessary resources.

View file

@ -1,12 +1,12 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.129",
"version": "0.1.130",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@boardgamers/clash-web-client",
"version": "0.1.129",
"version": "0.1.130",
"dependencies": {
"@boardgamers/protocol": "0.9.0",
"lucide-svelte": "^0.577.0",

View file

@ -1,6 +1,6 @@
{
"name": "@boardgamers/clash-web-client",
"version": "0.1.129",
"version": "0.1.130",
"private": true,
"type": "module",
"scripts": {

View file

@ -355,6 +355,7 @@
pending={$session.pending}
optional={field.optional}
reward={decision.reward}
variableAmount={field.variableAmount}
label={field.name}
/>
{/if}
@ -372,6 +373,7 @@
pending={$session.pending}
optional={field.optional}
reward={decision.reward}
variableAmount={field.variableAmount}
label={field.name}
/>
{:else}

View file

@ -12,6 +12,7 @@
pending = false,
optional = false,
reward = false,
variableAmount = false,
label = 'Payment',
}: {
options: { payment: Pile; disabled?: boolean }[];
@ -21,6 +22,7 @@
pending?: boolean;
optional?: boolean;
reward?: boolean;
variableAmount?: boolean;
label?: string;
} = $props();
const icons = {
@ -80,7 +82,7 @@
resource,
amount,
reward ? 'food' : 'gold',
!reward,
!reward && !variableAmount,
),
);
}

View file

@ -726,6 +726,7 @@ export interface Decision {
initial: Pile;
cost: Pile;
choices?: Pile[] | null;
variableAmount?: boolean;
}[];
}
export const resourceNames: Record<Resource, string> = {

View file

@ -2,6 +2,7 @@ import { test } from 'node:test';
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import { readFileSync } from 'node:fs';
import { paymentWithAmount } from './payment-options.ts';
import type { Pile, View } from './types.ts';
const engine = createRequire(import.meta.url)('../.engine/server.js');
@ -82,3 +83,23 @@ test('Uprising allows every affordable mood/culture mix totaling 1–4, never ze
])
assert.throws(() => quote(rich, payment), /valid payment/);
});
test('Uprising UI keeps mixed token payments and adjusts only when exceeding four', () => {
const state = pending({ mood_tokens: 4, culture_tokens: 4 });
const field = view(state).decision!.fields[0];
assert.equal(field.variableAmount, true);
const choose = (current: Pile, resource: 'mood_tokens' | 'culture_tokens', amount: number) =>
paymentWithAmount(field.choices!, current, resource, amount, 'gold', !field.variableAmount);
let selected = choose({ mood_tokens: 2 }, 'culture_tokens', 2);
assert.equal(selected.mood_tokens, 2);
assert.equal(selected.culture_tokens, 2);
const after = engine.tryMove(state, JSON.stringify(quote(state, selected).action), 0);
assert.equal(view(after).players[0].score - view(state).players[0].score, 2);
selected = choose(selected, 'culture_tokens', 3);
assert.equal(selected.mood_tokens, 1);
assert.equal(selected.culture_tokens, 3);
selected = choose(selected, 'culture_tokens', 1);
assert.equal(selected.mood_tokens, 1);
assert.equal(selected.culture_tokens, 1);
});