From 4bdfc1e01a89f342145b51128b36a8c8bb16d4fd Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Tue, 27 Oct 2026 18:26:20 +0100 Subject: [PATCH] Add local queued-action prototype and simplify research choice hint --- web-client/README.md | 6 + web-client/async-preview.html | 1 + web-client/scripts/async-preview-fixture.json | 1 + web-client/src/App.svelte | 22 +++- web-client/src/AsyncPreview.svelte | 116 ++++++++++++++++++ web-client/src/ResearchTree.svelte | 2 +- web-client/src/action-queue.test.ts | 54 ++++++++ web-client/src/action-queue.ts | 68 ++++++++++ web-client/src/async-preview.ts | 3 + web-client/src/research.css | 4 - web-client/src/style.css | 26 ++++ 11 files changed, 292 insertions(+), 11 deletions(-) create mode 100644 web-client/async-preview.html create mode 100644 web-client/scripts/async-preview-fixture.json create mode 100644 web-client/src/AsyncPreview.svelte create mode 100644 web-client/src/action-queue.test.ts create mode 100644 web-client/src/action-queue.ts create mode 100644 web-client/src/async-preview.ts diff --git a/web-client/README.md b/web-client/README.md index d042baca..ead36b52 100644 --- a/web-client/README.md +++ b/web-client/README.md @@ -17,6 +17,12 @@ Open http://127.0.0.1:8643. The preview binds to loopback and saves its disposab The local preview does not modify production games, catalog records, or chat rooms. +## Action-queue prototype + +Open `/async-preview.html` on the local dev server. This isolated replacement-settler scenario uses the real board and controls: Maya plans actions while Rome chooses a city. Switch seats with the preview toolbar. The queue reuses `predictMove`, revalidates actions after Rome responds, and stops on an invalid action. End turn can be queued last; the normal Undo button removes a queued action and its payment responses together. + +This is a local, in-memory prototype, not production concurrency. Reloading resets it. It neither saves a server-side queue nor enables planning around other live-game reactions. The production viewer entry point does not import the prototype. + ## Implemented controls - Procedural 3D terrain, cities, settlers, tile selection, orbit/zoom, and a top-down view. diff --git a/web-client/async-preview.html b/web-client/async-preview.html new file mode 100644 index 00000000..c8ea4845 --- /dev/null +++ b/web-client/async-preview.html @@ -0,0 +1 @@ +Clash · Concurrent choices preview
diff --git a/web-client/scripts/async-preview-fixture.json b/web-client/scripts/async-preview-fixture.json new file mode 100644 index 00000000..855d2f71 --- /dev/null +++ b/web-client/scripts/async-preview-fixture.json @@ -0,0 +1 @@ +{"version":2,"seed":"async","state":{"Movement":{"movement_actions_left":2,"moved_units":[10]}},"players":[{"id":0,"resources":{"food":7,"wood":5,"ore":5,"ideas":3,"gold":7,"mood_tokens":9,"culture_tokens":9},"resource_limit":{"food":7,"wood":7,"ore":7,"ideas":7,"gold":7},"cities":[{"city_pieces":{"market":1},"mood_state":"Happy","activations":1,"position":"A1"},{"city_pieces":{"academy":1,"port":1},"mood_state":"Angry","activations":6,"angry_activation":true,"position":"C2","port_position":"C3"},{"mood_state":"Angry","activations":4,"angry_activation":true,"position":"B3"},{"city_pieces":{"obelisk":1,"observatory":0,"fortress":0,"temple":0},"mood_state":"Angry","position":"B1"}],"units":[{"position":"C2","unit_type":"Infantry","id":0},{"position":"C3","unit_type":"Cavalry","id":1},{"position":"C3","unit_type":"Elephant","id":2},{"position":"B3","unit_type":"Settler","id":3},{"position":"B3","unit_type":"Settler","id":4},{"position":"B3","unit_type":"Settler","id":5},{"position":"B3","unit_type":"Settler","id":6},{"position":"C3","unit_type":"Ship","id":7},{"position":"C3","unit_type":"Ship","id":8},{"position":"C3","unit_type":"Ship","id":9},{"position":"B1","unit_type":"Infantry","movement_restrictions":["Battle","Mountain"],"id":10}],"civilization":"Maya","active_leader":"Kʼinich Janaab Pakal I","advances":["Farming","FreeEconomy","Mining","Storage","Tactics","Voting"],"incident_tokens":2,"wonder_cards":["GreatGardens"],"next_unit_id":11},{"id":1,"resources":{"food":2,"wood":5,"ore":5,"ideas":5,"gold":5,"mood_tokens":9,"culture_tokens":9},"resource_limit":{"food":2,"wood":7,"ore":7,"ideas":7,"gold":7},"cities":[{"mood_state":"Angry","activations":2,"position":"C1"},{"city_pieces":{"port":1},"mood_state":"Neutral","position":"B2","port_position":"C3"}],"units":[{"position":"C1","unit_type":"Infantry","id":0},{"position":"C1","unit_type":"Infantry","id":1}],"civilization":"Rome","available_leaders":[],"advances":["Farming","Mining"],"incident_tokens":3,"next_unit_id":2},{"id":2,"civilization":"Barbarians","next_unit_id":0},{"id":3,"civilization":"Pirates","next_unit_id":0}],"map":{"tiles":[["A1","Fertile"],["A2","Water"],["A3",{"Exhausted":"Forest"}],["A4","Mountain"],["B1","Mountain"],["B2","Forest"],["B3","Fertile"],["B4","Fertile"],["B5","Fertile"],["B6","Fertile"],["C1","Barren"],["C2","Forest"],["C3","Water"],["C4","Water"],["C5","Water"],["D1","Fertile"],["D2","Water"],["E2","Fertile"]]},"starting_player_index":0,"current_player_index":0,"log":[{"age":0,"rounds":[{"round":0,"turns":[{"turn_type":{"Setup":{"player":0,"civilization":"Maya"}},"actions":[{"action":"StartTurn","player":0,"items":[{"player":0,"Resources":{"resources":{"food":2},"balance":"Gain"},"origin":{"Ability":"Setup"}},{"player":0,"Advance":{"advance":"Farming","incident_token":"NoChange","balance":"Gain"},"origin":{"Ability":"Setup"}},{"player":0,"Advance":{"advance":"Mining","incident_token":"NoChange","balance":"Gain"},"origin":{"Ability":"Setup"}},{"player":0,"HandCard":{"card":{"ActionCard":21},"from":"DrawPile","to":{"Hand":0}},"origin":{"Ability":"Setup"}},{"player":0,"HandCard":{"card":{"ObjectiveCard":26},"from":"DrawPile","to":{"Hand":0}},"origin":{"Ability":"Setup"}},{"player":0,"Structure":{"structure":"CityCenter","balance":"Gain","position":"D2","port_position":null},"origin":{"Ability":"Setup"}},{"player":0,"MoodChange":{"city":"D2","mood":"Happy"},"origin":{"Ability":"Setup"}},{"player":0,"Units":{"units":{"settlers":1},"balance":"Gain","position":"D2"},"origin":{"Ability":"Setup"}}]}]},{"turn_type":{"Setup":{"player":1,"civilization":"Carthage"}},"actions":[{"action":"StartTurn","player":1,"items":[{"player":1,"Resources":{"resources":{"food":2},"balance":"Gain"},"origin":{"Ability":"Setup"}},{"player":1,"Advance":{"advance":"Farming","incident_token":"NoChange","balance":"Gain"},"origin":{"Ability":"Setup"}},{"player":1,"Advance":{"advance":"Mining","incident_token":"NoChange","balance":"Gain"},"origin":{"Ability":"Setup"}},{"player":1,"HandCard":{"card":{"ActionCard":33},"from":"DrawPile","to":{"Hand":1}},"origin":{"Ability":"Setup"}},{"player":1,"HandCard":{"card":{"ObjectiveCard":33},"from":"DrawPile","to":{"Hand":1}},"origin":{"Ability":"Setup"}},{"player":1,"Structure":{"structure":"CityCenter","balance":"Gain","position":"D7","port_position":null},"origin":{"Ability":"Setup"}},{"player":1,"MoodChange":{"city":"D7","mood":"Happy"},"origin":{"Ability":"Setup"}},{"player":1,"Units":{"units":{"settlers":1},"balance":"Gain","position":"D7"},"origin":{"Ability":"Setup"}}]}]}]}]},{"age":1,"rounds":[{"round":1,"turns":[{"turn_type":{"Player":0}}]}]}],"log_index":0,"undo_limit":0,"actions_left":2,"round":2,"age":1,"messages":["Age 1 has started"],"rng":"187377510744160874215923636426395457826","wonders_left":["GreatLighthouse","Pyramids","GreatMausoleum","GreatWall","GreatStatue","Colosseum","GreatGardens","GreatLibrary"],"action_cards_left":[8,23,36,27,20,13,26,32,42,29,12,16,17,1,39,41,25,28,5,40,38,18,37,34,14,22,7,9,6,24,15,2,30,10,19,31,4,35,3,11],"objective_cards_left":[9,2,7,23,1,28,27,10,14,36,20,38,8,25,35,18,6,19,31,22,34,3,5,16,29,15,21,11,12,24,37,4,17,32,13,30],"incidents_left":[17,5,15,42,33,49,45,13,20,43,39,30,51,11,46,47,14,6,40,8,4,32,28,23,41,36,35,25,22,29,52,54,56,31,37,9,18,16,26,44,53,58,3,50,55,10,12,24,38,34,1,48,7,27,57,2,21,19],"options":{},"events":[{"event_type":{"CombatEnd":{"round":1,"battleground":"CityWithFortress","attacker":{"position":"A1","player":0,"present":{"leaders":1}},"defender":{"position":"B1","player":1},"result":"AttackerWins"}},"players_used":[0],"player":1,"last_priority_used":102,"handler":{"priority":102,"request":{"SelectPositions":{"choices":["B2","C1"],"needed":{"start":1,"end":1},"description":"Select a city to place the free Settler Unit"}},"origin":{"Ability":"Place Settler"}}}]} \ No newline at end of file diff --git a/web-client/src/App.svelte b/web-client/src/App.svelte index 18c01d8a..f2faf7df 100644 --- a/web-client/src/App.svelte +++ b/web-client/src/App.svelte @@ -127,8 +127,9 @@ import { sinceLastTurn } from './playback'; import { ageCount, ageLabel } from './game-length'; import { roundProgress, personalRoundLabel } from './round-progress'; - let { controller }: { controller: Controller } = $props(); + let { controller, concurrentPreview }: { controller: Controller; concurrentPreview?: { pending: boolean; waiting: boolean; seat: number; other: string; queued: number; ended: boolean; onUndo: () => void; onWait: () => void } } = $props(); const session = $derived(controller.session); + const planningQueue = $derived(!!concurrentPreview?.pending && concurrentPreview.seat === 0); let earlyPanel = $state<'cities' | 'abilities' | 'first' | null>(null); const earlyOffers = $derived(!$session.playback ? $session.view?.earlyChoices ?? [] : []); const earlyAdvance = $derived(earlyOffers.find(o => o.key.endsWith('/advance'))); @@ -265,7 +266,7 @@ const activePlayers = $derived( $session.game?.state === 'Finished' || $session.playback ? [] - : ($session.view?.activePlayers ?? ($session.view ? [$session.view.activePlayer] : [])), + : concurrentPreview?.pending ? (concurrentPreview.waiting ? [1] : [0, 1]) : ($session.view?.activePlayers ?? ($session.view ? [$session.view.activePlayer] : [])), ); const choosingPlayer = $derived( !!$session.view?.civilizationDraft || !!$session.game?.events?.length || ($session.game?.round ?? 0) > 3, @@ -937,7 +938,7 @@
{#each playerTurns as { player, order, status }} {@const turnLabel = activePlayers.includes(player.index) - ? choosingPlayer + ? (concurrentPreview?.pending ? player.index === 1 : choosingPlayer) ? 'Choosing' : player.index === $session.seat ? 'Your turn' @@ -1292,7 +1293,7 @@ class="turn-light" >{/if}
- {actionTitle} + {concurrentPreview?.pending && concurrentPreview.seat === 0 && !concurrentPreview.waiting ? 'Planning ahead' : actionTitle} {#if waiting}{waiting.action}{waiting.source ? ` · ${printedCardName(waiting.source)}` : ''}{/if} @@ -1463,8 +1464,11 @@ aria-hidden="true" />{/if} - controller.submit(action)}/> + { + if (planningQueue && action === 'Undo') concurrentPreview!.onUndo(); + else controller.submit(action); + }}/> + {#if concurrentPreview?.pending && !concurrentPreview.waiting && concurrentPreview.seat === 0} +
+ {concurrentPreview.other} · Placing a settler{#if concurrentPreview.queued}
{concurrentPreview.queued} queued{concurrentPreview.ended ? ' · End turn queued' : ''}{/if}
+ +
+ {/if} {#if !$session.playback}{/if}