From 3fcbcfd51c468b86572879967d6fa301fc9b4623 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 22 Aug 2026 17:41:58 +0200 Subject: [PATCH] Bestitaire --- data/src/db | 2 +- setup/core/creature-timing.typ | 31 ++++++++++++++ setup/core/macros.typ | 5 +++ setup/generation/creature-data.typ | 5 ++- setup/models/creature.typ | 66 ++++++++++++++++++++++++------ 5 files changed, 94 insertions(+), 15 deletions(-) create mode 100644 setup/core/creature-timing.typ diff --git a/data/src/db b/data/src/db index d666cdb..f0f4599 160000 --- a/data/src/db +++ b/data/src/db @@ -1 +1 @@ -Subproject commit d666cdbde5d13fc78d6b7dbd47209639938cc222 +Subproject commit f0f459978b862ad90ebd688109396d175854820d diff --git a/setup/core/creature-timing.typ b/setup/core/creature-timing.typ new file mode 100644 index 0000000..efb0b56 --- /dev/null +++ b/setup/core/creature-timing.typ @@ -0,0 +1,31 @@ +// Native creature initiative/timing notation. +// Database values use backend-neutral tokens such as `AInto(2,1)`; only this +// module owns their visual representation. + +#let initiative(stage) = math.equation(block: false, $i_(#stage)$) +#let AFrom(stage) = math.equation(block: false, $i_(arrow.l #stage)$) +#let AInto(from, to) = math.equation(block: false, $i_(#from arrow.r #to)$) +#let ALing(stage) = { + let stage = if stage == "all" { $forall$ } else { stage } + math.equation(block: false, $i_(#stage)^(arrow.r infinity)$) +} +#let AOnly(stage) = math.equation(block: false, $i_(#stage)^"!"$) + +#let _argument(value, prefix) = value.replace(prefix + "(", "").replace(")", "") +#let _stage(value) = if value == "all" { $forall$ } else { value } + +#let parse-timing(value) = { + let source = if value == none { "" } else { str(value).trim() } + if source.starts-with("AFrom(") and source.ends-with(")") { + AFrom(_stage(_argument(source, "AFrom"))) + } else if source.starts-with("AInto(") and source.ends-with(")") { + let args = _argument(source, "AInto").split(",").map(it => it.trim()) + if args.len() == 2 { AInto(_stage(args.first()), _stage(args.last())) } else { source } + } else if source.starts-with("ALing(") and source.ends-with(")") { + ALing(_stage(_argument(source, "ALing"))) + } else if source.starts-with("AOnly(") and source.ends-with(")") { + AOnly(_stage(_argument(source, "AOnly"))) + } else { + source + } +} diff --git a/setup/core/macros.typ b/setup/core/macros.typ index ccfd18c..82f972b 100644 --- a/setup/core/macros.typ +++ b/setup/core/macros.typ @@ -2,6 +2,7 @@ #import "../theme/variables.typ": theme, theme-var #import "../theme/symbols.typ" as symbols #import "limits.typ": hunbal +#import "creature-timing.typ": AFrom, AInto, ALing, AOnly #import "@preview/glossarium:0.5.10": gls //----- The ubiquitous ddlvl macro ----- @@ -238,4 +239,8 @@ mecaniquejeu: mecaniquejeu, kw: kw, symbols: symbols, + AFrom: AFrom, + AInto: AInto, + ALing: ALing, + AOnly: AOnly, ) diff --git a/setup/generation/creature-data.typ b/setup/generation/creature-data.typ index 813cbc5..acf2bac 100644 --- a/setup/generation/creature-data.typ +++ b/setup/generation/creature-data.typ @@ -5,6 +5,7 @@ // database access, relational composition, and presentation stay independent. #import "@preview/typsqlite:0.1.0": sqlite +#import "../core/creature-timing.typ": initiative #let db = sqlite(read("/data/src/db/monsters.db", encoding: none)) @@ -95,7 +96,7 @@ let p2-actions = _csv(stats.p2_actions) let count = calc.max(p1-values.len(), p2-values.len(), p1-actions.len(), p2-actions.len()) range(count).map(index => ( - name: "i" + str(index + 1), + name: initiative(index + 1), p1-value: p1-values.at(index, default: ""), p1-actions: p1-actions.at(index, default: ""), p2-value: p2-values.at(index, default: ""), @@ -136,7 +137,7 @@ let damage = (_text(row.damage_regular), _text(row.success)).filter(_present).join(" ") let extra-effects = ( if row.armor_break != none { "Bris d'armure " + str(row.armor_break) } else { "" }, - if row.antimaterial != none { "Antimatériel " + str(row.antimaterial) } else { "" }, + if row.antimaterial != none { "@rl_am " + str(row.antimaterial) } else { "" }, if row.armor_pierce != none { "Perce-armure " + str(row.armor_pierce) } else { "" }, _text(row.effects), ).filter(_present).join(" · ") diff --git a/setup/models/creature.typ b/setup/models/creature.typ index 7d09d75..7aaa041 100644 --- a/setup/models/creature.typ +++ b/setup/models/creature.typ @@ -5,6 +5,9 @@ // the mock record later. #import "../theme/variables.typ": theme +#import "../core/macros.typ" as macros +#import "../generation/glossary.typ": glossary +#import "@preview/glossarium:0.5.10": gls #let label-fill = ( ATK: rgb("#c95f5f"), MVT: rgb("#658db5"), DEF: rgb("#73a16f"), @@ -40,6 +43,45 @@ inset: 0pt, image(path), ) + +#let rich-text(value) = { + if type(value) == str { + let entries = (:) + for entry in glossary { entries.insert(entry.key, entry) } + let db-gls(key, short: false) = { + let entry = entries.at(key, default: none) + if entry == none { + "@" + key + } else if short { + gls(key, display: entry.short, link: false) + } else { + gls(key, link: false) + } + } + let references-to-calls(source) = { + let found = source.match(regex("@([A-Za-z][A-Za-z0-9_]*)(:short)?")) + if found == none { return source } + let key = found.captures.first() + let short = found.captures.at(1, default: none) != none + ( + source.slice(0, found.start) + + "#db-gls(\"" + + key + + "\"" + + (if short { ", short: true)" } else { ")" }) + + references-to-calls(source.slice(found.end)) + ) + } + let markup = references-to-calls(value) + eval( + markup, + mode: "markup", + scope: macros.bigscope + (db-gls: db-gls), + ) + } else { + value + } +} #let section-title(title) = block( width: 100%, inset: (x: 5pt, y: 3pt), @@ -64,7 +106,7 @@ ).filter(pair => present(pair.at(1))) let rows = fields.map(pair => ( table.cell(align: left, text(weight: "bold", pair.at(0))), - table.cell(align: left, pair.at(1)), + table.cell(align: left, rich-text(pair.at(1))), )).flatten() table( @@ -78,18 +120,18 @@ #let lore-and-rewards(creature) = { section-title("Description") - text(size: 9pt, creature.description) + text(size: 9pt, rich-text(creature.description)) v(0.5em) section-title("Annotations") - text(size: 9pt, creature.annotations) + text(size: 9pt, rich-text(creature.annotations)) v(0.5em) section-title("Récompenses") let reward-rows = creature.rewards.map(reward => ( reward.name, reward.category, - reward.cost, - reward.effect, + rich-text(reward.cost), + rich-text(reward.effect), )).flatten() table( columns: (1.1fr, 0.8fr, 0.55fr, 2.4fr), @@ -128,7 +170,7 @@ ..rows, table.hline(stroke: 0.5pt + theme.border), table.cell(colspan: 9)[*Notes*], - table.cell(colspan: 9, text(size: 8pt, creature.master-notes)), + table.cell(colspan: 9, text(size: 8pt, rich-text(creature.master-notes))), table.hline(stroke: 0.5pt + theme.border), ) } @@ -231,23 +273,23 @@ for attack in group.attacks { contents += ( table.cell(fill: group-color)[], - cell(attack.name), cell(attack.type), cell(attack.timing), cell(attack.target), - cell(attack.fatigue-cost), cell(attack.action-cost), cell(attack.element), - cell(attack.fatigue-damage), cell(attack.damage), cell(attack.effects), + rich-text(attack.name), cell(attack.type), rich-text(attack.timing), rich-text(attack.target), + rich-text(attack.fatigue-cost), rich-text(attack.action-cost), rich-text(attack.element), + rich-text(attack.fatigue-damage), rich-text(attack.damage), rich-text(attack.effects), cell(attack.parry), cell(attack.dodge), ) } if present(group.description) { contents += ( table.cell(fill: group-color)[], - table.cell(colspan: 12, inset: 4pt, text(size: 8pt, group.description)), + table.cell(colspan: 12, inset: 4pt, text(size: 8pt, rich-text(group.description))), ) } contents.push(table.hline(stroke: 0.35pt + theme.border.lighten(35%))) } } table( - columns: (1%, 15%, 5%, 9%, 5%, 4%, 4%, 7%, 5%, 7%, 28%, 5%, 5%), + columns: (0.5em, 8em, 3em, 4em, 1em, 2em, 2em, 3em, 2em, 3em, 1fr, 1em, 1em), inset: (x: 2pt, y: 2.5pt), align: (x, _) => if x == 1 or x == 10 { left } else { center }, stroke: none, @@ -287,7 +329,7 @@ pagebreak() section-title("Plan de combat") - block(inset: 8pt, text(size: 9pt, creature.battle-plan)) + block(inset: 8pt, text(size: 9pt, rich-text(creature.battle-plan))) if present(creature.intent-graph) { v(1em) section-title("Graphique d'intentions")