summaryrefslogtreecommitdiff
path: root/web/src/App.svelte
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-19 08:53:51 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-19 08:53:51 +0100
commitb884441ba0d10bdd3559748507a0991888f66194 (patch)
tree074321d353c1153e8d95191eecf5a61b2eec1096 /web/src/App.svelte
parentd64cf3514e5ff1ddb1c7f3ddac9a769db3e7dde0 (diff)
Phase 6: settings, saves, localization parity (M6)
Diffstat (limited to 'web/src/App.svelte')
-rw-r--r--web/src/App.svelte74
1 files changed, 72 insertions, 2 deletions
diff --git a/web/src/App.svelte b/web/src/App.svelte
index 0defd74..bdeb998 100644
--- a/web/src/App.svelte
+++ b/web/src/App.svelte
@@ -11,8 +11,9 @@
-->
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
+ import { get } from 'svelte/store';
import { GameSession } from '$lib/state/session';
- import { styleTheme } from '$lib/settings';
+ import { clientSettings, styleTheme } from '$lib/settings';
import { gameData, type CampaignData, type MonsterData } from '$lib/data/gameData';
import {
isMonster,
@@ -63,11 +64,75 @@
const error = session.lastError;
const status = session.status;
- // The style theme (client-only) styles <html> via app.css [data-style].
+ // The style theme (server-driven, Phase 6) styles <html> via app.css
+ // [data-style].
$effect(() => {
document.documentElement.dataset.style = $styleTheme;
});
+ // Scaling (the reference `scaling.dart`, web-adapted): the main list
+ // width is `400px * mainListScaling` (capped at the viewport; the
+ // reference uses a 740px baseline on full-screen mobile), and the top
+ // bar scales its whole content by `barScaling` (the reference constrains
+ // the bar content to `screenWidth / userScalingBars`; the web applies the
+ // factor directly via CSS `zoom`).
+ //
+ // Power mode "reduce" (the reference `reducePowerEnabled`): card shadows
+ // are dropped (app.css `[data-power='reduce']`).
+ $effect(() => {
+ const root = document.documentElement;
+ root.style.setProperty('--list-scale', String($clientSettings.mainListScaling));
+ root.style.setProperty('--bar-scale', String($clientSettings.barScaling));
+ if ($clientSettings.powerMode === 'reducePower') root.dataset.power = 'reduce';
+ else delete root.dataset.power;
+ });
+
+ // The idle dimmer (the reference `IdleDimmer`, Phase 6): after 15 s
+ // without input and with power mode "dim when idle", a 0.65 black scrim
+ // fades in over 1.2 s; any input (or a tap on the scrim) wakes it. The
+ // scrim sits above everything so the waking tap cannot also land on the
+ // board.
+ const IDLE_DIM_DELAY_MS = 15_000;
+ let dimmed = $state(false);
+ let dimTimer: ReturnType<typeof setTimeout> | null = null;
+
+ function armDimTimer() {
+ if (dimTimer) {
+ clearTimeout(dimTimer);
+ dimTimer = null;
+ }
+ if (get(clientSettings).powerMode !== 'dimWhenIdle') return;
+ dimTimer = setTimeout(() => (dimmed = true), IDLE_DIM_DELAY_MS);
+ }
+ function wake() {
+ dimmed = false;
+ armDimTimer();
+ }
+ $effect(() => {
+ // Power-mode changes wake the screen (the reference restarts or
+ // cancels the timer on change).
+ const mode = $clientSettings.powerMode;
+ if (mode !== 'dimWhenIdle') dimmed = false;
+ armDimTimer();
+ });
+ onMount(() => {
+ armDimTimer();
+ const events = ['pointerdown', 'keydown', 'wheel', 'touchstart'] as const;
+ for (const ev of events) window.addEventListener(ev, wake, { passive: true });
+ // Backgrounding counts as waking: the reference never lands back on a
+ // dim screen when the app is resumed.
+ const onVisibility = () => {
+ dimmed = false;
+ armDimTimer();
+ };
+ document.addEventListener('visibilitychange', onVisibility);
+ return () => {
+ for (const ev of events) window.removeEventListener(ev, wake);
+ document.removeEventListener('visibilitychange', onVisibility);
+ if (dimTimer) clearTimeout(dimTimer);
+ };
+ });
+
// --- UI state ----------------------------------------------------------
let drawerOpen = $state(false);
@@ -357,6 +422,11 @@
<ConnectionBanner status={$status} />
<Toast message={toast} />
+{#if dimmed}
+ <!-- The idle dimmer scrim (Phase 6 power mode): tap to wake. -->
+ <div class="dimmer" onpointerdown={wake} onclick={wake} aria-hidden="true"></div>
+{/if}
+
<MainMenu {session} bind:open={drawerOpen} onOpenMenu={openMenu} />
{#if menu === 'scenario'}