summaryrefslogtreecommitdiff
path: root/web/src/lib/game/line/buildAbility.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/game/line/buildAbility.ts')
-rw-r--r--web/src/lib/game/line/buildAbility.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/web/src/lib/game/line/buildAbility.ts b/web/src/lib/game/line/buildAbility.ts
new file mode 100644
index 0000000..45c6e7a
--- /dev/null
+++ b/web/src/lib/game/line/buildAbility.ts
@@ -0,0 +1,87 @@
+/**
+ * The ability-card rendering pipeline (PORTING.md §8b): pre-translate the
+ * card's lines with the in-game `t()`, run them through {@link parseLines}
+ * (expand → convert → per-line stat application → layout), and return the
+ * structured tree the Svelte renderer walks. Also builds the {@link
+ * StatMonster} the stat applier needs from the monster model + live standees.
+ */
+
+import { gt } from '$lib/i18n/gameI18n';
+import { parseLines } from './lineParser';
+import type { MonsterAbilityCard, MonsterType } from '$lib/protocol/types';
+import type { MonsterData } from '$lib/data/gameData';
+import type { ColumnNode } from './types';
+import type { StatBlock, StatLevel, StatMonster } from './statApplier';
+
+export interface AbilityRenderOptions {
+ /** Frosthaven style (icon-only tokens, sub-line boxes). */
+ fh: boolean;
+ /** Left-aligned boss stat card layout. */
+ left?: boolean;
+ /** Resolve stats per line (the reference's `!noCalculation`). */
+ applyStats?: boolean;
+ /** Force the elite/normal split (the reference's `calculateAll`). */
+ applyAll?: boolean;
+ scale?: number;
+ /** The monster is a flyer (move token → flying graphic). */
+ flying?: boolean;
+}
+
+type StatSource = {
+ health?: number | string;
+ move?: number | string;
+ attack?: number | string;
+ range?: number;
+ attributes?: string[];
+};
+
+function toBlock(source: StatSource | undefined): StatBlock | undefined {
+ if (!source) return undefined;
+ return {
+ health: source.health,
+ move: source.move,
+ attack: source.attack,
+ range: source.range,
+ attributes: source.attributes
+ };
+}
+
+/**
+ * The stat-applier view of a monster at [level], for the standees currently
+ * in play. Built from the edition's level stats + the live standee types.
+ */
+export function statMonsterFor(
+ monster: MonsterData,
+ level: number,
+ standeeTypes: MonsterType[],
+ isActive: boolean
+): StatMonster {
+ const raw = monster.levels.find((l) => l.level === level) ?? monster.levels[0];
+ const statLevel: StatLevel = {
+ normal: toBlock(raw?.normal as StatSource | undefined),
+ elite: toBlock(raw?.elite as StatSource | undefined),
+ boss: toBlock(raw?.boss as StatSource | undefined)
+ };
+ return { level: statLevel, standeeTypes, isActive };
+}
+
+/** The full ability-card line tree (lines pre-translated, then parsed). */
+export function buildAbilityCardTree(
+ card: MonsterAbilityCard,
+ stat: StatMonster | null,
+ opts: AbilityRenderOptions
+): ColumnNode {
+ const lines = card.lines.map(gt);
+ return parseLines(lines, {
+ left: opts.left ?? false,
+ applyStats: opts.applyStats ?? false,
+ applyAll: opts.applyAll ?? false,
+ align: opts.left ? 'left' : 'center',
+ frosthavenStyle: opts.fh,
+ scale: opts.scale ?? 1,
+ monster: stat,
+ flying: opts.flying ?? false,
+ bossStatCard: opts.left ?? false,
+ translate: gt
+ });
+}