fix(viewer): keep custom federation selection editable in planning
This commit is contained in:
parent
3c4b4d3173
commit
facf787d03
6 changed files with 148 additions and 36 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/old-ui",
|
||||
"version": "1.2.28",
|
||||
"version": "1.2.29",
|
||||
"scripts": {
|
||||
"serve": "vite --port 5193",
|
||||
"build": "vite build",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gaia-project/viewer",
|
||||
"version": "5.22.28",
|
||||
"version": "5.22.29",
|
||||
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
|
||||
"contributors": [
|
||||
"coyotte508",
|
||||
|
|
|
|||
|
|
@ -324,6 +324,40 @@ describe("Commands", () => {
|
|||
}
|
||||
});
|
||||
|
||||
it.each([false, true])("selects a custom-only federation's hexes and tile (analysis=%s)", async (analysisMode) => {
|
||||
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: "", analysisMode }, store });
|
||||
const button = (text: string) =>
|
||||
wrapper.findAll("button.move-button").wrappers.find((entry) => entry.isVisible() && entry.text().includes(text))!;
|
||||
const selected = () => [...store.state.context.highlighted.hexes.hexes.keys()].map((hex) => hex.toString());
|
||||
try {
|
||||
await button("Form federation").trigger("click");
|
||||
await button("Custom location").trigger("click");
|
||||
expect(button("End Selection").attributes("disabled")).to.equal(undefined);
|
||||
expect(wrapper.emitted("command")).to.equal(undefined);
|
||||
for (const coord of ["1A9", "6A6", "1A9"]) {
|
||||
await store.dispatch("hexClick", { hex: engine.map.getS(coord) });
|
||||
await Vue.nextTick();
|
||||
}
|
||||
expect(selected()).to.deep.equal(["6A6"]);
|
||||
await button("End Selection").trigger("click");
|
||||
await Vue.nextTick();
|
||||
await wrapper.find('button[aria-label*="7vp,2o"]').trigger("click");
|
||||
expect(wrapper.emitted("command")![0][0]).to.equal("terrans federation 6A6 fed4");
|
||||
} finally {
|
||||
wrapper.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
it("backs out of a custom-only federation without reopening the selection", async () => {
|
||||
const engine = createLostFleetRoundMoveEngine();
|
||||
engine.availableCommands = [
|
||||
|
|
@ -365,40 +399,43 @@ describe("Commands", () => {
|
|||
}
|
||||
});
|
||||
|
||||
it("opens an editable custom federation with a prefilled 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 options = { propsData: { currentMove: "" }, store };
|
||||
const wrapper = mount(Commands, options);
|
||||
try {
|
||||
await store.dispatch("selectFederation", "1A9,6A6");
|
||||
await Vue.nextTick();
|
||||
const selected = () => [...store.state.context.highlighted.hexes.hexes.keys()].map((hex) => hex.toString());
|
||||
expect(selected()).to.deep.equal(["1A9", "6A6"]);
|
||||
await store.dispatch("hexClick", { hex: engine.map.getS("6A6") });
|
||||
await Vue.nextTick();
|
||||
expect(selected()).to.deep.equal(["1A9"]);
|
||||
const button = (text: string) =>
|
||||
wrapper
|
||||
.findAll("button.move-button")
|
||||
.wrappers.find((entry) => entry.isVisible() && entry.text().includes(text))!;
|
||||
await button("End Selection").trigger("click");
|
||||
await Vue.nextTick();
|
||||
await wrapper.find('button[aria-label*="7vp,2o"]').trigger("click");
|
||||
await Vue.nextTick();
|
||||
expect(wrapper.emitted("command")![0][0]).to.equal("terrans federation 1A9 fed4");
|
||||
} finally {
|
||||
wrapper.destroy();
|
||||
it.each([false, true])(
|
||||
"opens an editable custom federation with a prefilled selection (analysis=%s)",
|
||||
async (analysisMode) => {
|
||||
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 options = { propsData: { currentMove: "", analysisMode }, store };
|
||||
const wrapper = mount(Commands, options);
|
||||
try {
|
||||
await store.dispatch("selectFederation", "1A9,6A6");
|
||||
await Vue.nextTick();
|
||||
const selected = () => [...store.state.context.highlighted.hexes.hexes.keys()].map((hex) => hex.toString());
|
||||
expect(selected()).to.deep.equal(["1A9", "6A6"]);
|
||||
await store.dispatch("hexClick", { hex: engine.map.getS("6A6") });
|
||||
await Vue.nextTick();
|
||||
expect(selected()).to.deep.equal(["1A9"]);
|
||||
const button = (text: string) =>
|
||||
wrapper
|
||||
.findAll("button.move-button")
|
||||
.wrappers.find((entry) => entry.isVisible() && entry.text().includes(text))!;
|
||||
await button("End Selection").trigger("click");
|
||||
await Vue.nextTick();
|
||||
await wrapper.find('button[aria-label*="7vp,2o"]').trigger("click");
|
||||
await Vue.nextTick();
|
||||
expect(wrapper.emitted("command")![0][0]).to.equal("terrans federation 1A9 fed4");
|
||||
} finally {
|
||||
wrapper.destroy();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
it("renders Lost Fleet ship tech choices in the normal tech-pick command", async () => {
|
||||
const engine = loadScenarioEngine("lost-fleet-ship-tech-claim");
|
||||
|
|
|
|||
|
|
@ -552,6 +552,65 @@ describe("Game", () => {
|
|||
return vm;
|
||||
}
|
||||
|
||||
it("forms a custom federation through planning's map and tile controls without changing the live game", async () => {
|
||||
const engine = researchGame();
|
||||
const player = engine.players[0];
|
||||
const buildings = [Building.PlanetaryInstitute, Building.Academy1];
|
||||
player.data.occupied.forEach((hex, index) => {
|
||||
hex.data.building = buildings[index];
|
||||
player.data.buildings[buildings[index]] = 1;
|
||||
});
|
||||
player.data.buildings[Building.Mine] = 0;
|
||||
const extra = [...engine.map.grid.values()].find(
|
||||
(hex) =>
|
||||
hex.hasPlanet() && !hex.occupied() && hex.data.planet !== Planet.Transdim && hex.data.planet !== Planet.Gaia
|
||||
)!;
|
||||
extra.data.player = PlayerEnum.Player1;
|
||||
extra.data.building = Building.TradingStation;
|
||||
player.data.occupied.push(extra);
|
||||
player.data.buildings[Building.TradingStation] = 1;
|
||||
player.data.power.area1 = 30;
|
||||
engine.clearAvailableCommands();
|
||||
engine.generateAvailableCommands();
|
||||
const location = engine.findAvailableCommand(PlayerEnum.Player1, Command.FormFederation)!.data.federations[0]
|
||||
.hexes;
|
||||
const liveBefore = JSON.stringify(engine);
|
||||
const vm = mountAsSeat(0, engine);
|
||||
const clickButton = async (text: string) => {
|
||||
const button = (Array.from(vm.$el.querySelectorAll("button.move-button")) as HTMLElement[]).find(
|
||||
(el) => !el.parentElement.classList.contains("d-none") && el.textContent.includes(text)
|
||||
);
|
||||
expect(button, text).to.not.equal(undefined);
|
||||
await fireEvent.click(button!);
|
||||
await Vue.nextTick();
|
||||
};
|
||||
try {
|
||||
await fireEvent.click(vm.$el.querySelector(".planning-entry"));
|
||||
await Vue.nextTick();
|
||||
expect(vm.analysisMode).to.equal(true);
|
||||
await clickButton("Form federation");
|
||||
await clickButton("Custom location");
|
||||
expect(vm.analysisEntries).to.deep.equal([]);
|
||||
for (const coord of location.split(",")) {
|
||||
await fireEvent.click(vm.$el.querySelector(`.space-hex-cell[id="${coord}"] > use`));
|
||||
await Vue.nextTick();
|
||||
}
|
||||
expect([...vm.$store.state.context.highlighted.hexes.hexes.keys()].map((hex) => hex.toString())).to.deep.equal(
|
||||
location.split(",")
|
||||
);
|
||||
await clickButton("End Selection");
|
||||
await fireEvent.click(vm.$el.querySelector('button[aria-label*="7vp,2o"]'));
|
||||
await Vue.nextTick();
|
||||
expect(vm.currentMove).to.contain(`terrans federation ${location} fed4`);
|
||||
await clickButton("End Turn");
|
||||
expect(vm.analysisEntries).to.deep.equal([{ kind: "move", move: `terrans federation ${location} fed4.` }]);
|
||||
expect(JSON.stringify(engine)).to.equal(liveBefore);
|
||||
} finally {
|
||||
vm.$el.remove();
|
||||
vm.$destroy();
|
||||
}
|
||||
});
|
||||
|
||||
function spyDispatch(vm: any): any[] {
|
||||
const dispatched: any[] = [];
|
||||
const originalDispatch = vm.$store.dispatch.bind(vm.$store);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,20 @@ describe("checkAutoClick", () => {
|
|||
expect(armed(button)).to.equal(true);
|
||||
});
|
||||
|
||||
it("does not auto-finish a selection with further choices, even nested in analysis mode", () => {
|
||||
const selection: ButtonData = {
|
||||
label: "End Selection",
|
||||
needConfirm: true,
|
||||
buttons: [{ command: "fed4" }],
|
||||
};
|
||||
const parent: ButtonData = { label: "Custom location", buttons: [selection] };
|
||||
|
||||
checkAutoClick(controllerStub(true), [parent], strategy);
|
||||
|
||||
expect(armed(selection)).to.equal(false);
|
||||
expect(selection.disabled).to.not.equal(true);
|
||||
});
|
||||
|
||||
it("leaves the confirmation alone in ordinary play", () => {
|
||||
const button: ButtonData = { label: "Confirm Mine", command: "", needConfirm: true };
|
||||
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ export function checkAutoClick(controller: CommandController, buttons: ButtonDat
|
|||
// itself is auto-clicked, and only when it is the lone remaining button with no warning on it -
|
||||
// ordinary single-option buttons still obey the player's own auto-click preference below, so
|
||||
// opening a menu never fires a move by itself.
|
||||
if (controller.analysisMode && buttons[0].needConfirm) {
|
||||
// Intermediate confirmations still collect input: federation's End Selection must wait for
|
||||
// map clicks before advancing to its tile choices. Only a leaf confirms a fully composed move.
|
||||
if (controller.analysisMode && buttons[0].needConfirm && !buttons[0].buttons?.length) {
|
||||
setAutoClick(controller, buttons[0]);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue