From b7908c20c66aa6509fa41fa397f8316512c66146 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Fri, 25 Sep 2026 10:40:26 +0200 Subject: [PATCH] Fix Back getting stuck in custom federation selection --- viewer/package.json | 2 +- viewer/src/components/Commands.spec.ts | 42 ++++++++++++++++++ viewer/src/logic/buttons/federation.ts | 60 ++++++++++++-------------- 3 files changed, 70 insertions(+), 34 deletions(-) diff --git a/viewer/package.json b/viewer/package.json index b3346ea8..e8e36213 100644 --- a/viewer/package.json +++ b/viewer/package.json @@ -1,6 +1,6 @@ { "name": "@gaia-project/viewer", - "version": "5.20.24", + "version": "5.20.25", "description": "Functions to visualize the map and boards for gaia project inside html canvas", "contributors": [ "coyotte508", diff --git a/viewer/src/components/Commands.spec.ts b/viewer/src/components/Commands.spec.ts index ef7a4d6b..1be88637 100644 --- a/viewer/src/components/Commands.spec.ts +++ b/viewer/src/components/Commands.spec.ts @@ -16,6 +16,7 @@ import { mount } from "@vue/test-utils"; import BootstrapVue from "bootstrap-vue"; import { expect } from "chai"; import Vue from "vue"; +import { ExecuteBack } from "../logic/buttons/types"; import { loadScenarioEngine } from "../self-contained-scenarios"; import { makeStore } from "../store"; import Commands from "./Commands.vue"; @@ -325,6 +326,47 @@ describe("Commands", () => { } }); + it("backs out of a custom-only federation without reopening the selection", async () => { + const engine = createLostFleetRoundMoveEngine(); + engine.availableCommands = [ + { + name: Command.FormFederation, + player: PlayerEnum.Player1, + data: { tiles: [Federation.Fed4], federations: [], claimableFederations: [] }, + }, + ]; + const store = makeStore(); + store.commit("receiveData", engine); + const wrapper = mount(Commands, { propsData: { currentMove: "" }, store }); + const button = (text: string) => + wrapper.findAll("button.move-button").wrappers.find((entry) => entry.isVisible() && entry.text().includes(text)); + const back = async () => { + const request = new ExecuteBack(); + await store.dispatch("back", request); + await Vue.nextTick(); + expect(request.performed).to.equal(true); + }; + try { + await button("Form federation")!.trigger("click"); + await button("Custom location")!.trigger("click"); + expect(button("End Selection")).to.not.equal(undefined); + await store.dispatch("hexClick", { hex: engine.map.getS("1A9") }); + expect(store.state.context.highlighted.hexes.hexes.size).to.equal(1); + + await back(); + expect(button("Custom location"), "Back must return to the federation locations").to.not.equal(undefined); + expect(button("End Selection")).to.equal(undefined); + expect(store.state.context.highlighted.hexes).to.equal(null); + + await back(); + expect(button("Form federation")).to.not.equal(undefined); + expect(store.state.context.hasCommandChain).to.equal(false); + expect(wrapper.emitted("command")).to.equal(undefined); + } finally { + wrapper.destroy(); + } + }); + it("opens an editable custom federation with a prefilled selection", async () => { const engine = createLostFleetRoundMoveEngine(); engine.availableCommands = [ diff --git a/viewer/src/logic/buttons/federation.ts b/viewer/src/logic/buttons/federation.ts index e4040a5a..6570bffa 100644 --- a/viewer/src/logic/buttons/federation.ts +++ b/viewer/src/logic/buttons/federation.ts @@ -14,7 +14,7 @@ import type { FederationChoice } from "../../data/federations"; import { federationChoiceDescription, federationChoiceRewards, federationChoiceShortcut } from "../../data/federations"; import { tooltipWithShortcut } from "./shortcuts"; import type { CommandController } from "./types"; -import { autoClickButton, customHexSelection, textButton } from "./utils"; +import { customHexSelection, textButton } from "./utils"; import { buttonWarnings, commonButtonWarning, resourceWasteWarning, translateWarnings } from "./warnings"; type Cycler = { @@ -50,41 +50,35 @@ function customFederationButton( ) { return { label: "Custom location", + longLabel: "Select planets and empty space to be included in the federation", shortcuts: ["c"], buttons: [ - autoClickButton({ - label: "Select planets and empty space to be included in the federation", - buttons: [ - textButton({ - label: "End Selection", - needConfirm: true, - keepContext: true, - onShow: (button) => { - controller.subscribeHexClick(button, (hex) => { - const highlighted = controller.getHighlightedHexes().hexes; + textButton({ + label: "End Selection", + needConfirm: true, + keepContext: true, + onShow: (button) => { + controller.subscribeHexClick(button, (hex) => { + const highlighted = controller.getHighlightedHexes().hexes; - if (highlighted.has(hex)) { - highlighted.delete(hex); - } else { - highlighted.set(hex, {}); - } + if (highlighted.has(hex)) { + highlighted.delete(hex); + } else { + highlighted.set(hex, {}); + } - const keys: GaiaHex[] = Array.from(highlighted.keys()); - controller.highlightHexes(customHexSelection(new Map([...keys.map((key) => [key, {}])] as any))); - }); - controller.highlightHexes( - customHexSelection(new Map(initialHexes.map((hex) => [hex, {}]))) - ); - }, - onClick: (button) => { - button.command = [...controller.getHighlightedHexes().hexes.keys()] - .map((hex) => hex.toString()) - .join(","); - controller.emitButtonCommand(button); - }, - buttons: fedTypeButtons, - }), - ], + const keys: GaiaHex[] = Array.from(highlighted.keys()); + controller.highlightHexes(customHexSelection(new Map([...keys.map((key) => [key, {}])] as any))); + }); + controller.highlightHexes( + customHexSelection(new Map(initialHexes.map((hex) => [hex, {}]))) + ); + }, + onClick: (button) => { + button.command = [...controller.getHighlightedHexes().hexes.keys()].map((hex) => hex.toString()).join(","); + controller.emitButtonCommand(button); + }, + buttons: fedTypeButtons, }), ], }; @@ -99,7 +93,7 @@ export function selectCustomFederation(engine: Engine, controller: CommandContro const custom = customFederationButton(controller, buttons, hexes); controller.handleCommand(Command.FormFederation, { label: "Custom federation: select planets and empty space", - buttons: custom.buttons[0].buttons, + buttons: custom.buttons, }); }