feat: show BGS Supporter badges in both viewers

This commit is contained in:
coyotte508 2026-10-01 23:59:25 +02:00
commit fa7a6a1217
12 changed files with 101 additions and 17 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@gaia-project/old-ui",
"version": "1.0.15",
"version": "1.0.16",
"scripts": {
"serve": "vite --port 5193",
"build": "vite build",

View file

@ -184,7 +184,7 @@ describe("old UI move compatibility", () => {
await fireEvent.click(buttonWithText("Choose Tinkering Tile")!);
await Vue.nextTick();
await fireEvent.click(buttonWithText("Charge 4 Power")!);
await fireEvent.click(buttons().find((button) => button.querySelector('.specialAction [event=">4pw"]'))!);
await Vue.nextTick();
expect(labels().filter((label) => label.includes("Income 4pw"))).to.have.length(2);

View file

@ -7,8 +7,15 @@
@click="playerClick(player)"
:class="['player-name', { dropped: player.dropped }]"
role="button"
>{{ name }}</span
>
>{{ name }}
<img
v-if="$store.state.supporterSeats[player.player] && $store.state.supporterBadge"
class="supporter-badge"
:src="$store.state.supporterBadge.url"
:alt="$store.state.supporterBadge.label"
:title="$store.state.supporterBadge.label"
/>
</span>
<div class="board mt-2">
<svg :viewBox="`-0.2 -0.5 38.5 ${height}`" class="player-board" :style="`background-color: ${factionColor}`">
<rect x="-1" y="-1" width="50" height="50" fill="#ffffff44"></rect>
@ -218,6 +225,13 @@ import TechTile from "./TechTile.vue";
export default class PlayerInfo extends CurrentPlayerInfo {}
</script>
<style scoped>
.supporter-badge {
width: 1rem;
height: 1rem;
margin-left: 0.25rem;
vertical-align: middle;
}
.player-board {
width: 100%;
height: auto;

View file

@ -1,5 +1,4 @@
import Engine from "@gaia-project/engine";
import Vue from "vue";
import { loadScenarioEngine, selfContainedScenarios } from "../../viewer/src/self-contained-scenarios";
import launch from "./launcher";
@ -12,8 +11,12 @@ describe("old UI on the current engine", () => {
};
vi.stubGlobal("IntersectionObserver", Observer);
vi.stubGlobal("ResizeObserver", Observer);
Object.defineProperty(HTMLElement.prototype, "checkVisibility", { configurable: true, value: () => true });
});
afterAll(() => {
vi.unstubAllGlobals();
delete HTMLElement.prototype.checkVisibility;
});
afterAll(() => vi.unstubAllGlobals());
for (const id of ["base", ...selfContainedScenarios.map((s) => s.id)]) {
it(`renders the actual old player/map components and current controls for ${id}`, async () => {
const host = document.createElement("div");
@ -28,7 +31,7 @@ describe("old UI on the current engine", () => {
viewer.emit("state", JSON.parse(JSON.stringify(engine)));
viewer.emit("chat:state", { canSend: true });
viewer.emit("chat:messages", [{ type: "text", author: "Teammate", text: "Ready to explore" }]);
await Vue.nextTick();
await vi.waitFor(() => expect(viewer.app.$el.querySelector(".old-map-canvas")).not.toBeNull());
expect(viewer.app.$el.querySelector(".old-ui-game")).not.toBeNull();
expect(viewer.app.$el.querySelector(".old-map-canvas")).not.toBeNull();
expect(viewer.app.$el.querySelector(".old-building")).not.toBeNull();

10
pnpm-lock.yaml generated
View file

@ -173,8 +173,8 @@ importers:
viewer:
dependencies:
'@boardgamers/protocol':
specifier: 0.6.2
version: 0.6.2
specifier: 0.8.1
version: 0.8.1
'@gaia-project/engine':
specifier: workspace:../engine
version: link:../engine
@ -433,8 +433,8 @@ packages:
resolution: {integrity: sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==}
engines: {node: '>=18'}
'@boardgamers/protocol@0.6.2':
resolution: {integrity: sha512-6FKgLsB4guCzNww1rkanhrsLHIdQVajDs1B4qNsYcgtUobTBRM2VPt9T4mlc8ZDX4JDQltvJVHuK7XDZ1J556A==}
'@boardgamers/protocol@0.8.1':
resolution: {integrity: sha512-BZNj+wof1aR1nSybRMqmQ+yAVNR3ZZy+mczIz2KbXSLXMLL3Jv21yi50CRbJ2ipdkPiPatcSP0nJj+xJbFgIfQ==}
'@bramus/specificity@2.4.2':
resolution: {integrity: sha512-ctxtJ/eA+t+6q2++vj5j7FYX3nRu311q1wfYH3xjlLOsczhlhxAg2FWNUXhpGvAw3BWo1xBcvOV6/YLc2r5FJw==}
@ -7084,7 +7084,7 @@ snapshots:
'@bcoe/v8-coverage@1.0.2': {}
'@boardgamers/protocol@0.6.2':
'@boardgamers/protocol@0.8.1':
dependencies:
zod: 4.6.2

View file

@ -15,4 +15,4 @@ allowBuilds:
nodent-runtime: true
yorkie: true
minimumReleaseAgeExclude:
- "@boardgamers/protocol@0.2.2 || 0.3.3 || 0.3.4 || 0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.6.2"
- "@boardgamers/protocol@0.2.2 || 0.3.3 || 0.3.4 || 0.4.0 || 0.4.2 || 0.5.0 || 0.6.0 || 0.6.1 || 0.6.2 || 0.8.1"

View file

@ -1,6 +1,6 @@
{
"name": "@gaia-project/viewer",
"version": "5.20.43",
"version": "5.20.44",
"description": "Functions to visualize the map and boards for gaia project inside html canvas",
"contributors": [
"coyotte508",
@ -42,7 +42,7 @@
"dist/package/*.jpg"
],
"dependencies": {
"@boardgamers/protocol": "0.6.2",
"@boardgamers/protocol": "0.8.1",
"@gaia-project/engine": "workspace:../engine",
"bootstrap": "^4.4.1",
"bootstrap-vue": "^2.12.0",

View file

@ -34,6 +34,18 @@
<!-- Presence indicator (PROGRESS.md Gaia 9) - top-left of the token, only when a caller passes
a status (TurnOrder.vue does; other PlayerCircle usages - the solo "current player"
placeholder, charts - leave it unset and render exactly as before). -->
<image
v-if="
portrait && profilePlayer && $store.state.supporterSeats?.[profilePlayer.player] && $store.state.supporterBadge
"
:href="$store.state.supporterBadge.url"
:aria-label="$store.state.supporterBadge.label"
x=".46"
y="-1.06"
width=".6"
height=".6"
><title>{{ $store.state.supporterBadge.label }}</title></image
>
<circle v-if="presenceStatus" :cx="-0.75" :cy="-0.75" :r="0.28" :class="['presence-dot', presenceStatus]" />
</g>
</template>

View file

@ -9,7 +9,16 @@
tabindex="0"
:data-bgs-player="player.player"
>
<img class="player-avatar" :alt="`${name}'s avatar`" :src="avatar" />
<span class="player-portrait">
<img class="player-avatar" :alt="`${name}'s avatar`" :src="avatar" />
<img
v-if="$store.state.supporterSeats?.[player.player] && $store.state.supporterBadge"
class="player-supporter-badge"
:src="$store.state.supporterBadge.url"
:alt="$store.state.supporterBadge.label"
:title="$store.state.supporterBadge.label"
/>
</span>
<span :class="['player-name', { dropped: player.dropped }]" role="button">{{ name }}</span>
</div>
<a
@ -685,12 +694,26 @@ export default class PlayerInfo extends Vue {
0 0 0 4px var(--recent);
}
.player-portrait {
position: relative;
display: inline-flex;
flex-shrink: 0;
margin-right: 0.25rem;
}
.player-avatar {
width: 2.25rem;
height: 2.25rem;
border-radius: 50%;
border: 1px solid var(--ui-border-strong);
margin-right: 0.25rem;
}
.player-supporter-badge {
position: absolute;
top: -3px;
left: -3px;
width: 15px;
height: 15px;
}
.player-token {

View file

@ -35,6 +35,24 @@ describe("launcher's store-to-emitter bridge", () => {
container.remove();
});
it("receives and clears optional Supporter seats without adding faction colour overrides", () => {
const container = document.createElement("div");
container.id = "launcher-supporters";
document.body.appendChild(container);
const item = launch("#launcher-supporters", Vue.extend({ render: (h) => h("div") }));
const supporterBadge = { url: "https://boardgamers.space/custom-badge.svg", label: "Supporter" };
item.emit("preferences", {
bgs: { players: [{ pro: false }, { pro: true }], supporterBadge, playerColors: ["#123456"] },
});
expect(item.store.state.supporterBadge).to.deep.equal(supporterBadge);
expect(item.store.state.supporterSeats).to.deep.equal([false, true]);
item.emit("preferences", {});
expect(item.store.state.supporterSeats).to.deep.equal([]);
expect(item.store.state.supporterBadge).to.equal(null);
item.app.$destroy();
container.remove();
});
it("sends a premove plan as an ordinary protocol move", () => {
const container = document.createElement("div");
container.id = "launcher-premove";

View file

@ -120,9 +120,13 @@ function launch(selector: string, component: VueConstructor<Vue> = Game) {
store.commit("playerSettings", data);
},
async onPreferences(data) {
const bgs = data.bgs;
store.commit("supporterSeats", Array.isArray(bgs?.players) ? bgs.players.map((p) => p.pro === true) : []);
store.commit("supporterBadge", bgs?.supporterBadge ?? null);
if (!(await localization.setLocale(data.locale))) {
return;
}
store.commit("preferences", data);
},
onPlayer(data) {

View file

@ -70,6 +70,8 @@ export type State = {
preferences: {
[key in Preference]: boolean | string;
};
supporterSeats?: boolean[];
supporterBadge?: { url: string; label: string } | null;
player: { index?: number; auth?: string } | null;
/** Tutorials mark this move with the normal gold markers. Null keeps the hosted opponent recap;
* an empty string marks nothing in a chapter's initial teaching position. */
@ -186,6 +188,8 @@ const gaiaViewer = {
player: null,
highlightedMove: null,
avatars: [] as string[],
supporterSeats: [] as boolean[],
supporterBadge: null as { url: string; label: string } | null,
hosted: false,
playerSettings: null,
pendingPlan: null,
@ -315,6 +319,12 @@ const gaiaViewer = {
state.player = data;
},
supporterSeats(state, data: boolean[]) {
state.supporterSeats = data;
},
supporterBadge(state, data: { url: string; label: string } | null) {
state.supporterBadge = data;
},
avatars(state, data) {
state.avatars = data;
},