summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-16 22:19:39 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-16 22:19:39 +0100
commit94e2850fb73005f3fb30af8489905e5cdfb6fac5 (patch)
tree1aea8e7e6683af770f0c57c0fb654003778c9f16 /server
parent4f50f2008f4d7c2a635f7f26861fcfc7f7504423 (diff)
Phase 4: cards and decks (M4)
Full card play in the browser: ability-line rendering, monster ability decks, the full modifier-deck (AMD) suite, and the loot deck — all server commands, faithful to the reference flows and layout. Web (Svelte 5): - Line renderer + in-game translations: $lib/game/line/ renders the reference line_builder output (emphasis, range markers, element styling); gameI18n.ts loads the /i18n/ in-game ability-text tables (the client-side TranslationService equivalent) - Card components: stat cards, monster ability cards (OG + FH styles, rendered lines, element/flying tokens), modifier cards (gfx resolver incl. P<n> perk graphics), loot cards (party-size value rules, owner, enhancements) - Monster ability decks: AbilityCardSlot in each monster row (front of the current card while active in playTurns, else the back with the draw-pile count); AbilityCardsMenu (reveal top cards, draw extra, extra shuffle, activate/inactivate, drag-reorder, remove); card zoom - Modifier decks: ModifierDeckWidget (tap to draw, face-up revealed top card, empty-box class icon for the current character's own deck, discard stack); ModifierDeckHeader (bad omen, corrosive spew, ±1/−2/+0, imbue 1/2, reveal with the Cassandra 8-button cap, save/don't-save revealed cards, removed count, Hail perk, CS sanctuary/party cards, faction icons, bless/curse and the empower/enfeeble counters); ModifierDeckMenu (draw-pile drag-reorder + send-to-bottom/shuffle/remove, discard remove/return-top, removed pile with return, faction grid with gray-out, perks menu with the Frosthaven opt-in); card zoom - Loot deck: LootDeckWidget (player-gated draw, current-character icon, discard stack, hidden when both piles empty); LootCardsMenu (set owner, per-character loot totals, add card, enhance with the reference material/herb/coin splits, special cards 1418/1419, return top/bottom) - Bottom DeckArea: loot deck left; the Character Decks toggle with the reference open-state cycling (oneOpen/allOpen/noOpen per round state; one-deck view for the current character during playTurns); ally deck behind shouldShowAlliesDeck; global deck - Pure helper modules ported from the reference: rules.ts (FH card styling, inactive-for-rule, ally-deck gate, deck resolution), modifierDeck.ts (pile derivations, faction cards), perks.ts (active perk set, card-text tokens, descriptions, add/remove gating), cards/lootCard.ts (values + per-character totals) - App wiring: campaign data loaded on currentCampaign change (guarded against out-of-order fetches); ability/AMD/loot menus and zooms driven by live-derived state so open menus track pile changes; Escape closes every dialog Server: - /i18n/ static mount: the in-game ability-text translation files the card renderer resolves (the reference TranslationService data) - Loot deck JSON gains pools (pool card ids per pool — the client derives card gfx from pool key + index and reads the enhancements map; ids only, since pool cards are the same live instances that mutate in the piles) - Modifier deck JSON gains removables (the counter totals the header reads) plus load-time round-trip for saves written before the field existed Docs: - PLAN.md: Phase 3 and Phase 4 marked complete (corrected the 'character ability decks' mislabel — ability decks are monster-only), progress log entries for M3 and M4 svelte-check 0 errors; web tests 177/177; build OK; dart analyze 0 errors; dart test 592/592; scripts/ci.sh green.
Diffstat (limited to 'server')
-rw-r--r--server/bin/main.dart2
-rw-r--r--server/lib/core/state/loot_deck_state.dart16
-rw-r--r--server/lib/core/state/modifier_deck.dart15
-rw-r--r--server/lib/net/app.dart11
4 files changed, 43 insertions, 1 deletions
diff --git a/server/bin/main.dart b/server/bin/main.dart
index f864828..7be16e2 100644
--- a/server/bin/main.dart
+++ b/server/bin/main.dart
@@ -43,6 +43,8 @@ Future<void> main(List<String> args) async {
// The client's menus and artwork read the same assets the engine loads.
dataDir: 'assets/data/',
imageDir: 'assets/images/',
+ // In-game ability-text translations for the client's card renderer.
+ i18nDir: 'assets/i18n/',
);
stdout
..writeln('X-Haven server listening on http://localhost:${server.port}')
diff --git a/server/lib/core/state/loot_deck_state.dart b/server/lib/core/state/loot_deck_state.dart
index 31c6df7..ccd1003 100644
--- a/server/lib/core/state/loot_deck_state.dart
+++ b/server/lib/core/state/loot_deck_state.dart
@@ -566,6 +566,22 @@ class LootDeck {
'enhancements': _enhancements,
'1418': _hasCard1418,
'1419': _hasCard1419,
+ // Pool card ids only: pool cards are the same live instances that enter
+ // the draw/discard piles (and mutate with them), so their full JSON would
+ // leak those mutations into the static pool. The enhancement menu needs
+ // the ids plus the `enhancements` map (card id → level).
+ 'pools': {
+ 'coin': _coinPool.map((c) => c.id).toList(),
+ 'lumber': _lumberPool.map((c) => c.id).toList(),
+ 'hide': _hidePool.map((c) => c.id).toList(),
+ 'metal': _metalPool.map((c) => c.id).toList(),
+ 'corpsecap': _corpsecapPool.map((c) => c.id).toList(),
+ 'arrowvine': _arrowvinePool.map((c) => c.id).toList(),
+ 'flamefruit': _flamefruitPool.map((c) => c.id).toList(),
+ 'axenut': _axenutPool.map((c) => c.id).toList(),
+ 'rockroot': _rockrootPool.map((c) => c.id).toList(),
+ 'snowthistle': _snowthistlePool.map((c) => c.id).toList(),
+ },
};
@override
diff --git a/server/lib/core/state/modifier_deck.dart b/server/lib/core/state/modifier_deck.dart
index 6575e01..b7c00f1 100644
--- a/server/lib/core/state/modifier_deck.dart
+++ b/server/lib/core/state/modifier_deck.dart
@@ -68,6 +68,10 @@ class ModifierDeck {
int get revealedCount => _revealedCount;
bool get cassandraSpecial => _cassandraSpecial;
+ /// The removable-card counter totals (bless / curse / empower / enfeeble
+ /// variants) — the client's deck-header counters read these.
+ Map<String, int> get removables => Map.unmodifiable(_removables);
+
ModifierDeck(this.name) {
//build deck
_initDeck();
@@ -141,6 +145,16 @@ class ModifierDeck {
_addedMinusOnes = modifierDeckData.containsKey('addedMinusOnes')
? modifierDeckData["addedMinusOnes"] as int
: 0;
+
+ // The counter totals are the source of truth; the physical-card rebuild
+ // above already re-derived them for saves written before `removables`
+ // existed on the wire.
+ if (modifierDeckData.containsKey('removables')) {
+ final saved = modifierDeckData['removables'] as Map<String, dynamic>;
+ for (final key in _removables.keys) {
+ _removables[key] = (saved[key] as int?) ?? _removables[key]!;
+ }
+ }
}
void setRemovableValue(_StateModifier _, String id, int value) {
@@ -551,6 +565,7 @@ class ModifierDeck {
'corrosiveSpew': _corrosiveSpew,
'revealed': _revealedCount,
'cassandra': _cassandraSpecial,
+ 'removables': _removables,
'drawPile': _drawPile.getList().map((c) => c.toJson()).toList(),
'removedPile': _removedPile.getList().map((c) => c.toJson()).toList(),
'discardPile': _discardPile.getList().map((c) => c.toJson()).toList(),
diff --git a/server/lib/net/app.dart b/server/lib/net/app.dart
index a38d5c0..8936104 100644
--- a/server/lib/net/app.dart
+++ b/server/lib/net/app.dart
@@ -24,12 +24,16 @@ final _log = Logger('server');
/// non-null: the client's menus read the campaign/scenario/character/section
/// JSON from it (the same files the engine loads). [imageDir] (e.g.
/// `assets/images/`) is served at `/images/` when non-null — character and
-/// monster artwork for the main list.
+/// monster artwork for the main list. [i18nDir] (e.g. `assets/i18n/`) is
+/// served at `/i18n/` when non-null — the in-game ability-text translations
+/// the client's card renderer resolves (the reference app's
+/// `TranslationService`, PLAN.md Phase 4).
Handler createHandler({
required String staticDir,
required GameServer gameServer,
String? dataDir,
String? imageDir,
+ String? i18nDir,
}) {
final router = Router();
router.get('/ws', createWebSocketUpgradeHandler(gameServer));
@@ -43,6 +47,9 @@ Handler createHandler({
if (imageDir != null) {
router.mount('/images/', _createStaticHandler(imageDir, plain: true));
}
+ if (i18nDir != null) {
+ router.mount('/i18n/', _createStaticHandler(i18nDir, plain: true));
+ }
// Session endpoint (PLAN.md section 3.3): returns the caller's persistent
// session id, setting the `x-haven-session` cookie when the caller has
// none yet. Browsers then carry the cookie on every same-origin request,
@@ -72,6 +79,7 @@ Future<HttpServer> startServer({
required GameServer gameServer,
String? dataDir,
String? imageDir,
+ String? i18nDir,
}) {
return shelf_io.serve(
createHandler(
@@ -79,6 +87,7 @@ Future<HttpServer> startServer({
gameServer: gameServer,
dataDir: dataDir,
imageDir: imageDir,
+ i18nDir: i18nDir,
),
'0.0.0.0',
port,