Preview destination dice totals on mobile

This commit is contained in:
coyotte508 2026-09-11 19:49:36 +02:00
commit 22d10fdc6e
4 changed files with 54 additions and 2 deletions

View file

@ -628,6 +628,7 @@
state={store.scene ?? s}
{seat}
{reserved}
previewTotals={s.phase === "planning" && !!me && !me.ready && !s.pending && !tool}
selectedLocations={tool ? tilePicks : []}
selectionReasons={binocularReasons}
selected={s.phase === "setup" ? "" : tool ? (tilePicks.at(-1) ?? "") : (currentRoute.at(-1) ?? "")}

View file

@ -1,5 +1,14 @@
<script lang="ts">
import { terrain, cell, distance, threatened, CHARACTER_COLORS, requirementLabel, type View } from "fuji-engine";
import {
terrain,
total,
cell,
distance,
threatened,
CHARACTER_COLORS,
requirementLabel,
type View,
} from "fuji-engine";
import PlayerMarker from "./PlayerMarker.svelte";
import TravelGuide from "./TravelGuide.svelte";
import RequirementSymbols from "./RequirementSymbols.svelte";
@ -14,6 +23,7 @@
selectedLocations = [],
selectionReasons,
reachable = [],
previewTotals = false,
onclick,
oninspect,
}: {
@ -26,6 +36,7 @@
selectedLocations?: string[];
selectionReasons?: Record<string, string>;
reachable?: string[];
previewTotals?: boolean;
onclick: (id: string) => void;
oninspect: (id: string) => void;
} = $props();
@ -196,6 +207,14 @@
rx="4"
fill="#112820e6"
/><RequirementSymbols requirement={data.requirement} x={x(c.id)} y={y(c.id) + 25} {colorblind} />{/if}
{#if previewTotals && seat !== undefined && reachable.includes(c.id) && !reserved[c.id] && !c.lava}
{@const value = total(state.players[seat]!, c.terrain) + state.players[seat]!.bonus}
<g class="dice-preview" data-location={c.id} aria-label={`Your current dice total: ${value}`}>
<title>Your current matching dice total, including bonuses. Rerolls may change it.</title>
<rect x={x(c.id) - 20} y={y(c.id) - 13} width="40" height="26" rx="6" />
<text x={x(c.id)} y={y(c.id) + 6}>{value}</text>
</g>
{/if}
{#if data.reroll && !c.lava}<text x={x(c.id) - 34} y={y(c.id) + (c.eruption ? 9 : -16)} class="reroll-mark"
>↻</text
>{/if}
@ -299,6 +318,27 @@
</div>
<style>
.dice-preview {
display: none;
pointer-events: none;
}
.dice-preview rect {
fill: #102d27;
stroke: #efdb9c;
stroke-width: 1.5;
}
.dice-preview text {
fill: #fff0bd;
font-size: 21px;
font-weight: 700;
text-anchor: middle;
}
@media (max-width: 650px), (pointer: coarse) {
.dice-preview {
display: block;
}
}
.landscape {
position: relative;
overflow: hidden;

View file

@ -1,7 +1,11 @@
import { fileURLToPath } from "node:url";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [svelte()],
resolve: {
alias: [{ find: /^fuji-engine$/, replacement: fileURLToPath(new URL("../engine/index.ts", import.meta.url)) }],
},
build: {
cssCodeSplit: false,
lib: { entry: "src/viewer.ts", name: "fuji", formats: ["iife"], fileName: () => "fuji-viewer.iife.js" },

View file

@ -1,7 +1,7 @@
import { chromium } from "playwright";
import assert from "node:assert/strict";
const root = process.cwd() + "/";
const { initGame, applyMove, stripSecret } = await import(root + "packages/engine/dist/index.js");
const { initGame, applyMove, stripSecret, total, cell } = await import(root + "packages/engine/dist/index.js");
let state = initGame(3, { skillAssignment: "fixed" }, "mobile-readiness");
for (let i = 0; i < 3; i++)
if (!state.players[i].setupDone)
@ -28,6 +28,13 @@ await page.evaluate(
},
stripSecret(state, 0)
);
const previews = page.locator(".dice-preview");
await previews.first().waitFor({ state: "visible" });
for (const preview of await previews.all()) {
const tileId = await preview.getAttribute("data-location");
const value = Number(await preview.locator("text").textContent());
assert.equal(value, total(state.players[0], cell(state, tileId).terrain) + state.players[0].bonus);
}
await page.locator(".teammate-status").first().click();
assert.deepEqual(await page.evaluate(() => events), []);
await page.locator(".teammate-name").first().click();