Fix Back getting stuck in custom federation selection

This commit is contained in:
coyotte508 2026-09-25 10:40:26 +02:00
commit b7908c20c6
3 changed files with 72 additions and 36 deletions

View file

@ -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",

View file

@ -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 = [

View file

@ -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<GaiaHex, HighlightHex>(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<GaiaHex, HighlightHex>(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,
});
}