fix(viewer): show federation token artwork in choices

This commit is contained in:
coyotte508 2026-10-03 18:11:13 +02:00
commit 479da2ac00
7 changed files with 27 additions and 12 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@gaia-project/viewer",
"version": "5.20.46",
"version": "5.20.47",
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
"contributors": [
"coyotte508",

View file

@ -258,9 +258,12 @@ describe("Commands", () => {
await fireEvent.click(buttonWithText("Location 1")!);
await Vue.nextTick();
const labels = visibleButtons().map((button) => button.textContent?.trim() ?? "");
expect(labels.some((label) => label.includes("8vp,q"))).to.equal(true);
expect(labels.some((label) => label.includes("8vp,8c"))).to.equal(true);
for (const reward of ["8vp,q", "8vp,8c"]) {
const button = visibleButtons().find((button) => button.getAttribute("aria-label")?.includes(reward));
expect(button).to.not.equal(undefined);
expect(button.querySelector(".federationTile")).to.not.equal(null);
expect(button.textContent).not.to.include("Federation");
}
} finally {
(window as any).matchMedia = previousMatchMedia;
}
@ -309,7 +312,7 @@ describe("Commands", () => {
expect(okButton, "the confirmation must identify the tapped location").to.not.equal(undefined);
await okButton!.trigger("click");
await Vue.nextTick();
await buttonWithText("7vp,2o")!.trigger("click");
await wrapper.find('button[aria-label*="7vp,2o"]').trigger("click");
await Vue.nextTick();
const emitted = wrapper.emitted("command");
@ -389,7 +392,7 @@ describe("Commands", () => {
.wrappers.find((entry) => entry.isVisible() && entry.text().includes(text))!;
await button("End Selection").trigger("click");
await Vue.nextTick();
await button("7vp,2o").trigger("click");
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 {

View file

@ -8,7 +8,7 @@
@mouseenter="hover"
@mouseleave="leave"
:title="button.tooltip || (button.mobileIcon ? button.label : undefined)"
:aria-label="button.mobileIcon ? button.label : undefined"
:aria-label="button.ariaLabel || (button.mobileIcon ? button.label : undefined)"
v-b-tooltip.html="{ boundary: 'viewport' }"
>
<template>
@ -23,7 +23,7 @@
split
right
:title="button.tooltip || (button.mobileIcon ? button.label : undefined)"
:aria-label="button.mobileIcon ? button.label : undefined"
:aria-label="button.ariaLabel || (button.mobileIcon ? button.label : undefined)"
v-b-tooltip.html="{ boundary: 'viewport' }"
@click="handleRangeClick(button.times[0])"
>

View file

@ -37,6 +37,7 @@
:type="c.spaceshipAction.type"
/>
<ArtifactIcon v-else-if="c.artifactToken != null" :key="i" :artifact="c.artifactToken" :size="48" />
<FederationTile v-else-if="c.federation" :key="i" :federation="c.federation" />
<FederationTile
v-else-if="c.spaceshipFederation"
:key="i"

View file

@ -45,6 +45,7 @@ export interface ButtonData {
| "booster"
| "swap-PI";
label?: string;
ariaLabel?: string;
richText?: RichText;
longLabel?: string;
command?: string;

View file

@ -4,6 +4,7 @@ import {
Booster,
Building,
Faction,
Federation,
Planet,
Reward,
SpaceshipFederation,
@ -30,6 +31,7 @@ export type RichTextElement = {
planet?: Planet;
spaceshipAction?: { ship: Spaceship; type: SpaceshipActionType };
artifactToken?: ArtifactToken;
federation?: Federation;
spaceshipFederation?: SpaceshipFederation;
deepSpaceTile?: { choice: string; position: number };
};

View file

@ -11,10 +11,15 @@ import Engine, {
import { sortBy } from "lodash";
import type { ButtonData, HighlightHex, HighlightHexData } from "../../data";
import type { FederationChoice } from "../../data/federations";
import { federationChoiceDescription, federationChoiceRewards, federationChoiceShortcut } from "../../data/federations";
import {
federationChoiceDescription,
federationChoiceRewards,
federationChoiceShortcut,
isSpaceshipFederation,
} from "../../data/federations";
import { tooltipWithShortcut } from "./shortcuts";
import type { CommandController } from "./types";
import { customHexSelection, textButton } from "./utils";
import { customHexSelection, symbolButton, textButton } from "./utils";
import { buttonWarnings, commonButtonWarning, resourceWasteWarning, translateWarnings } from "./warnings";
type Cycler = {
@ -26,9 +31,12 @@ type Cycler = {
export function federationTypeButtons(federations: FederationChoice[], player: Player) {
return federations.map((fed, i) => {
const rewards = federationChoiceRewards(fed);
return textButton({
const label = `Federation ${i + 1}: ${federationChoiceDescription(fed)}`;
return symbolButton({
command: fed,
label: `Federation ${i + 1}: ${federationChoiceDescription(fed)}`,
label,
ariaLabel: label,
richText: [isSpaceshipFederation(fed) ? { spaceshipFederation: fed } : { federation: fed }],
shortcuts: [federationChoiceShortcut(fed)],
warning: resourceWasteWarning(player, rewards),
});