summaryrefslogtreecommitdiff
path: root/web/test/levelValues.test.ts
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-15 13:45:21 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-15 13:45:21 +0100
commit4f50f2008f4d7c2a635f7f26861fcfc7f7504423 (patch)
tree94e6286e7e22e0467a61b99c18b9ab582fbbe656 /web/test/levelValues.test.ts
parent3ebbdf6ffa16f751c82e3bd2e74294f4fe843155 (diff)
Phase 3: web UI core loop (M3)
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.
Diffstat (limited to 'web/test/levelValues.test.ts')
-rw-r--r--web/test/levelValues.test.ts62
1 files changed, 62 insertions, 0 deletions
diff --git a/web/test/levelValues.test.ts b/web/test/levelValues.test.ts
new file mode 100644
index 0000000..bdcb08c
--- /dev/null
+++ b/web/test/levelValues.test.ts
@@ -0,0 +1,62 @@
+import { describe, it, expect } from 'vitest';
+import {
+ coinValue,
+ hazardValue,
+ recommendedLevel,
+ trapValue,
+ xpValue
+} from '$lib/game/levelValues';
+
+describe('level values (GameMethods port)', () => {
+ it('trap = 2 + level', () => {
+ expect(trapValue(1)).toBe(3);
+ expect(trapValue(10)).toBe(12);
+ });
+
+ it('hazard = 1 + ceil(level / 3)', () => {
+ expect(hazardValue(1, false, false)).toBe(2);
+ expect(hazardValue(3, false, false)).toBe(2);
+ expect(hazardValue(4, false, false)).toBe(3);
+ });
+
+ it('OGGloom hazard halves the trap value by default', () => {
+ // floor((2 + level) / 2)
+ expect(hazardValue(1, true, false)).toBe(1);
+ expect(hazardValue(5, true, false)).toBe(3);
+ });
+
+ it('OGGloom with the FH setting uses the regular formula', () => {
+ expect(hazardValue(5, true, true)).toBe(3); // 1 + ceil(5/3)
+ expect(hazardValue(4, true, true)).toBe(3); // 1 + ceil(4/3)
+ });
+
+ it('xp = 4 + 2 * level', () => {
+ expect(xpValue(1)).toBe(6);
+ expect(xpValue(4)).toBe(12);
+ });
+
+ it('coin = 2 + floor(level / 2), capped at 6 on level 7', () => {
+ expect(coinValue(1)).toBe(2);
+ expect(coinValue(2)).toBe(3);
+ expect(coinValue(6)).toBe(5);
+ expect(coinValue(7)).toBe(6);
+ expect(coinValue(8)).toBe(6); // 2 + floor(8/2) = 6, same
+ });
+});
+
+describe('recommendedLevel (GameMethods port)', () => {
+ it('defaults to 1 with no characters', () => {
+ expect(recommendedLevel([], false)).toBe(1);
+ });
+
+ it('party: average level divided by 2, rounded up', () => {
+ expect(recommendedLevel([2, 2, 2, 2], false)).toBe(1);
+ expect(recommendedLevel([4, 4, 4, 4], false)).toBe(2);
+ expect(recommendedLevel([3, 3, 3, 3], false)).toBe(2);
+ });
+
+ it('solo: (average + 1) / 2, rounded up', () => {
+ expect(recommendedLevel([1], true)).toBe(1);
+ expect(recommendedLevel([4], true)).toBe(3);
+ });
+});