From 4f50f2008f4d7c2a635f7f26861fcfc7f7504423 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 15 Nov 2026 13:45:21 +0100 Subject: Phase 3: web UI core loop (M3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Browser game UI on top of the Phase 2 protocol: server-driven, input-only clients with per-connection secret visibility. Web (Svelte 5): - Layout: TopBar (element buttons with use/imbue long-press, title, menu), MainList (character/monster/note rows), BottomBar (draw/next-round + level widget with T/H/X/C values). - CharacterRow with the secret initiative input: own value editable, server-masked values render as ??, revealed on draw. - Per-figure StatusMenu: health/max/xp/bless/curse/empower/enfeeble steppers, condition grid, turn-done — all server commands, player-gated. - Menu dialogs: select scenario, add section, add/remove character, set level/difficulty/solo/auto-level, add/remove monster, note row, action log with rollback, settings (style theme + language). - Player vs spectator UI gated on the live seat table; reconnecting banner, error toasts, connection status plumbing. - i18n: English ported, locale store with localStorage persistence. - Design tokens + the three style themes (frosthaven/gloomhaven/original). - Unit tests: level values, game logic (elements/conditions/art/stats), i18n, the reactive player store, the data client (sections keyed by scenario number), plus the existing connection/protocol/state tests. Server: - Serve the engine's data JSON at /data/ and artwork at /images/ so the client menus and rows read the same assets the engine loads. --- web/src/lib/i18n/en.ts | 138 ++++++++++++++++++++++++++++++++++++++++++++++ web/src/lib/i18n/index.ts | 73 ++++++++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 web/src/lib/i18n/en.ts create mode 100644 web/src/lib/i18n/index.ts (limited to 'web/src/lib/i18n') diff --git a/web/src/lib/i18n/en.ts b/web/src/lib/i18n/en.ts new file mode 100644 index 0000000..b7037a7 --- /dev/null +++ b/web/src/lib/i18n/en.ts @@ -0,0 +1,138 @@ +/** + * English UI strings, ported from the reference app's `app_en.arb` (the subset + * the Phase 3 core-loop UI uses). Placeholder syntax: Flutter uses `{name}`, + * which `t()` substitutes from its `vars` map. + * + * Web-only strings (no `.arb` counterpart) — the spectator model, the claim + * flow, and reconnect UX — are added here and marked `web:`. + */ +export const en: Record = { + // Menus / top bar + 'menuSetScenario': 'Set Scenario', + 'menuAddCharacter': 'Add Character', + 'menuRemoveCharacters': 'Remove Characters', + 'menuSetLevel': 'Set Level', + 'menuAddMonsters': 'Add Monsters', + 'menuRemoveMonsters': 'Remove Monsters', + 'menuSettings': 'Settings', + 'menuDocumentation': 'Documentation', + 'menuAddSection': 'Add Section', + 'menuAddNoteRow': 'Add Note Row', + 'menuActionLog': 'View Action Log', + 'currentCampaign': 'Current Campaign: {campaign}', + + // Action log + 'actionLogTitle': 'Last 20 Actions', + 'actionLogEmpty': 'No actions yet', + 'actionLogRollbackHint': 'Tap an action to roll back to it', + 'actionLogRollbackTitle': 'Roll back?', + 'actionLogRollbackBody': 'Undo back to "{action}"? This reverses {count} later action(s). You can redo them until you make a change.', + 'actionLogRollbackConfirm': 'Roll back', + + // Note rows + 'noteRowTitle': 'Note', + 'noteRowHint': 'Note text…', + 'noteRowAddFromMenu': 'Add note', + 'noteRowDelete': 'Delete note', + 'noteRowWholeGroup': 'Whole group', + 'noteRowAll': 'All', + + // Common + 'undo': 'Undo', + 'redo': 'Redo', + 'undoWithDescription': 'Undo: {description}', + 'redoWithDescription': 'Redo: {description}', + 'close': 'Close', + 'retry': 'RETRY', + 'removeAll': 'Remove All', + 'noResultsFound': 'No results found', + 'levelLegendLabel': 'level', + + // Scenario setup + 'setScenarioLevel': 'Set Scenario Level', + 'enhancedLevel': 'Enhanced: {level}', + 'soloLabel': 'Solo:', + 'automaticScenarioLevel': 'Automatic Scenario Level:', + 'difficultyLabel': 'Difficulty:', + 'allCampaigns': 'All Campaigns', + 'addMonsterLabel': 'Add Monster', + 'showMonstersFrom': 'Show monsters from:', + + // Monsters + 'setMonsterLevel': "Set {name}'s level", + 'cmdAddMonster': 'Add {name}', + 'cmdRemoveMonster': 'Remove {name}', + 'cmdRemoveAllMonsters': 'Remove all monsters', + 'addStandeeNr': 'Add Standee Nr', + + // Characters + 'addCharacterHint': 'Add Character (type name for hidden character classes)', + 'cmdAddCharacter': 'Add {id}', + 'cmdRemoveCharacter': 'Remove {id}', + 'cmdRemoveAllCharacters': 'Remove all characters', + 'cmdSetCharacterLevel': "Set {character}'s Level", + 'setLootOwner': 'Set Loot Owner:', + + // Stat changes + 'cmdChangeStat': 'Change stat', + 'cmdIncreaseHealth': "Increase {figure}'s health by {amount}", + 'cmdDecreaseHealth': "Decrease {owner}'s health by {amount}", + 'cmdIncreaseMaxHealth': "Increase {owner}'s max health", + 'cmdDecreaseMaxHealth': "Decrease {owner}'s max health", + 'cmdIncreaseXp': "Increase {figure}'s xp by {amount}", + 'cmdDecreaseXp': "Decrease {figure}'s xp by {amount}", + 'cmdAddBless': 'Add a Bless', + 'cmdRemoveBless': 'Remove a Bless', + 'cmdAddCurse': 'Add a Curse', + 'cmdRemoveCurse': 'Remove a Curse', + 'cmdAddEmpower': 'Add Empower', + 'cmdRemoveEmpower': 'Remove Empower', + 'cmdAddEnfeeble': 'Add Enfeeble', + 'cmdRemoveEnfeeble': 'Remove Enfeeble', + + // Conditions + 'cmdAddCondition': 'Add condition: {condition}', + 'cmdRemoveCondition': 'Remove condition: {condition}', + + // Elements + 'cmdUseElement': 'Use Element {element}', + 'cmdImbueElement': 'Imbue element {element}', + 'removeImbue': 'Remove Imbue', + 'imbue': 'Imbue', + 'advancedImbue': 'Advanced Imbue', + + // Turn / round + 'cmdTurnDone': "{id}'s turn done", + 'cmdDraw': 'Draw', + 'cmdNextRound': 'Next Round', + 'draw': 'Draw', + 'nextRound': 'Next Round', + 'shuffleAndDraw': 'Shuffle & Draw', + 'cmdSetInitiative': 'Set initiative of {character}', + + // Sections + 'cmdAddSection': 'Add Section', + + // Connection UX + 'connecting': 'Connecting...', + 'web:reconnecting': 'Reconnecting…', + 'web:connected': 'Connected', + 'lostConnectionToServer': 'Lost connection to server', + 'stateMismatch': 'Your state was not up to date, try again.', + 'serverOffline': 'Server Offline', + 'clientError': 'Client error: {error}', + + // Player / spectator (web-only: the reference app has no spectator role) + 'web:spectator': 'Spectating', + 'web:player': 'Playing', + 'web:unclaimed': 'Unclaimed', + 'web:claimCharacter': 'Claim this character', + 'web:claimPrompt': 'You have not claimed a character yet. Tap a character row to claim it and take control.', + 'web:yourCharacter': 'You', + 'web:secret': '??', + 'web:initiative': 'Initiative', + 'web:noScenario': 'No scenario set', + 'web:round': 'Round', + 'web:level': 'Level', + 'web:difficulty': 'Difficulty' +}; diff --git a/web/src/lib/i18n/index.ts b/web/src/lib/i18n/index.ts new file mode 100644 index 0000000..9634712 --- /dev/null +++ b/web/src/lib/i18n/index.ts @@ -0,0 +1,73 @@ +/** + * UI string i18n (Phase 3: English first, locale plumbing in place). + * + * The reference app generates its UI strings from `.arb` files (gen-l10n); + * here we port the English set as a plain object and keep the same shape so + * the other 9 locales can be dropped in later (Phase 6). `t()` falls back to + * English for any key a locale is missing. + */ + +import { get, writable, type Writable } from 'svelte/store'; + +import { en } from './en'; + +export type Locale = + | 'en' + | 'de' + | 'es' + | 'fr' + | 'ko' + | 'pl' + | 'ru' + | 'th' + | 'zh' + | 'zh_Hant'; + +/** Locale → its string table. English is the only one ported in Phase 3. */ +const tables: Record> = { en }; + +const LOCALE_KEY = 'x-haven-locale'; + +function initialLocale(): Locale { + try { + const stored = window.localStorage.getItem(LOCALE_KEY); + if (stored && tables[stored]) return stored as Locale; + } catch { + // localStorage unavailable (SSR / privacy mode) — fall through. + } + return 'en'; +} + +export const locale: Writable = writable(initialLocale()); + +locale.subscribe((value) => { + try { + window.localStorage.setItem(LOCALE_KEY, value); + } catch { + // ignore + } +}); + +/** The locales currently available in the client (for the settings picker). */ +export const availableLocales = Object.keys(tables); + +/** + * Translate a key with the active locale, falling back to English. Returns + * the key itself when it is unknown everywhere (so missing strings are + * visible rather than silently blank). + */ +export function t(key: string, vars?: Record): string { + const active = tables[get(locale)] ?? {}; + let template = active[key] ?? en[key] ?? key; + if (vars) { + for (const [name, value] of Object.entries(vars)) { + template = template.replaceAll(`{${name}}`, String(value)); + } + } + return template; +} + +/** True when [key] exists in the active locale (vs. falling back). */ +export function hasLocaleKey(key: string): boolean { + return key in (tables[get(locale)] ?? {}); +} -- cgit v1.3.1