From dcef9e0b586049f70839815a1983da461ab25004 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 22 Aug 2026 18:16:25 +0200 Subject: [PATCH] Bestiairy formatting --- data/config/build.yaml | 6 + data/src/db | 2 +- master_handbook.typ | 22 ++- setup/build_config.typ | 10 + setup/generation/creature-data.typ | 11 +- setup/models/creature.typ | 287 ++++++++++++++++++++++------- setup/models/document.typ | 3 +- setup/setup.typ | 10 +- tools/check_creature_eval.sh | 36 ++++ 9 files changed, 308 insertions(+), 79 deletions(-) create mode 100755 tools/check_creature_eval.sh diff --git a/data/config/build.yaml b/data/config/build.yaml index aa3016a..880b39d 100644 --- a/data/config/build.yaml +++ b/data/config/build.yaml @@ -22,6 +22,12 @@ build: origin: "" school: "" + # Compile only one creature in the master bestiary while diagnosing trusted + # database markup/glossary evaluation. Leave empty for the complete book. + # Command-line example: + # typst compile --input preset=master-handbook --input creature_id=3 master_handbook.typ + creature_id: "" + # Always excluded, in addition to the exclusions from the selected preset. disabled_chapters: [] diff --git a/data/src/db b/data/src/db index f0f4599..a01cb08 160000 --- a/data/src/db +++ b/data/src/db @@ -1 +1 @@ -Subproject commit f0f459978b862ad90ebd688109396d175854820d +Subproject commit a01cb08fcfe2a2b2edbd92cba9dcadca7224fadd diff --git a/master_handbook.typ b/master_handbook.typ index 99414e8..4b3be20 100644 --- a/master_handbook.typ +++ b/master_handbook.typ @@ -1,6 +1,9 @@ // Master-facing handbook entry point, adapted from the former LaTeX master. #import "/setup/setup.typ": config_main, disable-warnings, build-config, theme -#show: config_main +#show: document => config_main( + document, + master-only: true, +) #if not build-config.warnings { disable-warnings() } @@ -144,7 +147,22 @@ Le seuil donné tient toujours compte du malus de -2 imposé lorsque l'on vise u #import "/setup/models/creature.typ": render-master-creature #import "/setup/generation/creature-data.typ": master-creatures -#for creature in master-creatures { +#let selected-master-creatures = if build-config.creature-id == none { + master-creatures +} else { + master-creatures.filter(creature => creature.id == build-config.creature-id) +} + +#assert( + build-config.creature-id == none or selected-master-creatures.len() == 1, + message: if build-config.creature-id == none { + "Invalid master creature filter" + } else { + "No master-visible creature with id " + str(build-config.creature-id) + }, +) + +#for creature in selected-master-creatures { render-master-creature(creature) } diff --git a/setup/build_config.typ b/setup/build_config.typ index c881152..f8abbf0 100644 --- a/setup/build_config.typ +++ b/setup/build_config.typ @@ -11,6 +11,15 @@ #assert(selected-preset in presets, message: "Unknown build preset: " + selected-preset) #let selected-origin = sys.inputs.at("origin", default: raw-build-config.origin) #let selected-school = sys.inputs.at("school", default: raw-build-config.school) +#let selected-creature-id = sys.inputs.at( + "creature_id", + default: raw-build-config.at("creature_id", default: ""), +) +#let selected-creature-id = if selected-creature-id == "" { + none +} else { + int(selected-creature-id) +} #let preset-disabled-chapters = presets.at(selected-preset).disabled_chapters #let preset-master-only = presets.at(selected-preset).at("master_only", default: false) @@ -25,6 +34,7 @@ master-only: preset-master-only, origin: selected-origin, school: selected-school, + creature-id: selected-creature-id, disabled-chapters: disabled-chapters, ) diff --git a/setup/generation/creature-data.typ b/setup/generation/creature-data.typ index acf2bac..813f80d 100644 --- a/setup/generation/creature-data.typ +++ b/setup/generation/creature-data.typ @@ -134,9 +134,16 @@ ) #let _ability(row) = { - let damage = (_text(row.damage_regular), _text(row.success)).filter(_present).join(" ") + let damage = ( + _text(row.damage_regular), + _text(row.success), + if row.armor_break != none { + "@rl_arbreak:short " + str(row.armor_break) + } else { + "" + }, + ).filter(_present).join(" ") let extra-effects = ( - if row.armor_break != none { "Bris d'armure " + str(row.armor_break) } 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), diff --git a/setup/models/creature.typ b/setup/models/creature.typ index 7aaa041..0d7c7b0 100644 --- a/setup/models/creature.typ +++ b/setup/models/creature.typ @@ -10,20 +10,40 @@ #import "@preview/glossarium:0.5.10": gls #let label-fill = ( - ATK: rgb("#c95f5f"), MVT: rgb("#658db5"), DEF: rgb("#73a16f"), - PAS: rgb("#a9c89c"), REV: rgb("#73a16f"), CLM: rgb("#496b4a"), - TRA: rgb("#d79555"), ASE: rgb("#c95f5f"), STA: rgb("#f7f5ef"), - CMB: rgb("#c95f5f"), FLR: rgb("#c95f5f"), GRB: rgb("#c95f5f"), - MXU: rgb("#c95f5f"), ADF: rgb("#c95f5f"), BYP: rgb("#873b3b"), - TBU: rgb("#873b3b"), TBZ: rgb("#873b3b"), TSH: rgb("#873b3b"), - CLV: rgb("#c95f5f"), AOE: rgb("#c95f5f"), WID: rgb("#c95f5f"), - WIP: rgb("#873b3b"), SZO: rgb("#f7f5ef"), SIT: rgb("#f7f5ef"), - SRG: rgb("#8d6799"), HRG: rgb("#8d6799"), BAD: rgb("#d79555"), + ATK: rgb("#c95f5f"), + MVT: rgb("#658db5"), + DEF: rgb("#73a16f"), + PAS: rgb("#a9c89c"), + REV: rgb("#73a16f"), + CLM: rgb("#496b4a"), + TRA: rgb("#d79555"), + ASE: rgb("#c95f5f"), + STA: rgb("#f7f5ef"), + CMB: rgb("#c95f5f"), + FLR: rgb("#c95f5f"), + GRB: rgb("#c95f5f"), + MXU: rgb("#c95f5f"), + ADF: rgb("#c95f5f"), + BYP: rgb("#873b3b"), + TBU: rgb("#873b3b"), + TBZ: rgb("#873b3b"), + TSH: rgb("#873b3b"), + CLV: rgb("#c95f5f"), + AOE: rgb("#c95f5f"), + WID: rgb("#c95f5f"), + WIP: rgb("#873b3b"), + SZO: rgb("#f7f5ef"), + SIT: rgb("#f7f5ef"), + SRG: rgb("#8d6799"), + HRG: rgb("#8d6799"), + BAD: rgb("#d79555"), BIS: rgb("#873b3b"), ) #let present(value) = value != none and value != "" and value != () -#let cell(value, size: none) = if size == none { [#value] } else { text(size: size, value) } +#let cell(value, size: none) = if size == none { [#value] } else { + text(size: size, value) +} #let threshold(value) = [ $#value.base$ #text(weight: "light", size: 0.6em)[$(#value.modifier)$] @@ -31,11 +51,9 @@ #let protection(value) = $#value.base [#value.armor]$ #let small-value(value) = text(weight: "light", size: 0.6em, $#value$) #let resistance(value) = { - if value == "++" { $++$ } - else if value == "+" { $+$ } - else if value == "--" { $--$ } - else if value == "-" { $-$ } - else { $ $ } + if value == "++" { $++$ } else if value == "+" { $+$ } else if value == "--" { + $--$ + } else if value == "-" { $-$ } else { $$ } } #let element-icon(path, height: 0.75em, baseline: 1.1pt) = box( height: height, @@ -48,35 +66,30 @@ if type(value) == str { let entries = (:) for entry in glossary { entries.insert(entry.key, entry) } - let db-gls(key, short: false) = { + let db-gls-short(key) = { let entry = entries.at(key, default: none) if entry == none { - "@" + key - } else if short { - gls(key, display: entry.short, link: false) + "@" + key + ":short" } else { - gls(key, link: false) + gls(key, display: entry.short) } } - let references-to-calls(source) = { - let found = source.match(regex("@([A-Za-z][A-Za-z0-9_]*)(:short)?")) + let short-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(\"" + + "#db-gls-short(\"" + key - + "\"" - + (if short { ", short: true)" } else { ")" }) - + references-to-calls(source.slice(found.end)) + + "\")" + + short-references-to-calls(source.slice(found.end)) ) } - let markup = references-to-calls(value) eval( - markup, + short-references-to-calls(value), mode: "markup", - scope: macros.bigscope + (db-gls: db-gls), + scope: macros.bigscope + (db-gls-short: db-gls-short), ) } else { value @@ -104,10 +117,12 @@ ("Traces", creature.traces), ("Mœurs", creature.habits), ).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, rich-text(pair.at(1))), - )).flatten() + let rows = fields + .map(pair => ( + table.cell(align: left, text(weight: "bold", pair.at(0))), + table.cell(align: left, rich-text(pair.at(1))), + )) + .flatten() table( columns: 2, @@ -127,28 +142,43 @@ v(0.5em) section-title("Récompenses") - let reward-rows = creature.rewards.map(reward => ( - reward.name, - reward.category, - rich-text(reward.cost), - rich-text(reward.effect), - )).flatten() + let reward-rows = creature + .rewards + .map(reward => ( + reward.name, + reward.category, + rich-text(reward.cost), + rich-text(reward.effect), + )) + .flatten() table( columns: (1.1fr, 0.8fr, 0.55fr, 2.4fr), inset: (x: 4pt, y: 3pt), stroke: none, table.header([*Nom*], [*Catégorie*], [*Coût*], [*Effet*]), - [Sang], [Base / combat / dépeçage], [], [#creature.blood.base / #creature.blood.battle / #creature.blood.carve], + [Sang], + [Base / combat / dépeçage], + [], + [#creature.blood.base / #creature.blood.battle / #creature.blood.carve], ..reward-rows, ) } #let body-table(creature) = { - let rows = creature.body-parts.map(part => ( - text(size: 8pt, part.name), - threshold(part.p1.threshold), protection(part.p1.protection), small-value(part.p1.integrity), small-value(part.p1.life), - threshold(part.p2.threshold), protection(part.p2.protection), small-value(part.p2.integrity), small-value(part.p2.life), - )).flatten() + let rows = creature + .body-parts + .map(part => ( + text(size: 8pt, part.name), + threshold(part.p1.threshold), + protection(part.p1.protection), + small-value(part.p1.integrity), + small-value(part.p1.life), + threshold(part.p2.threshold), + protection(part.p2.protection), + small-value(part.p2.integrity), + small-value(part.p2.life), + )) + .flatten() table( columns: (2fr, auto, auto, 1.5fr, 1.5fr, auto, auto, 1.5fr, 1.5fr), rows: (1.5em, 1.5em) + (2.5em,) * creature.body-parts.len() + (auto, auto), @@ -163,8 +193,18 @@ stroke: none, table.vline(x: 5, start: 1, stroke: 0.5pt + theme.border), table.header( - [], table.cell(colspan: 4, align: center)[P1], table.cell(colspan: 4, align: center)[P2], - [], [Seuil], [Prot], [Intégrité], [PV], [Seuil], [Prot], [Intégrité], [PV], + [], + table.cell(colspan: 4, align: center)[P1], + table.cell(colspan: 4, align: center)[P2], + [], + [Seuil], + [Prot], + [Intégrité], + [PV], + [Seuil], + [Prot], + [Intégrité], + [PV], ), table.hline(stroke: 0.5pt + theme.border), ..rows, @@ -180,7 +220,11 @@ [Res], element-icon("/images/icons/slash.svg", height: 0.65em, baseline: 0.5pt), element-icon("/images/icons/pierce.svg", height: 0.7em, baseline: 0.7pt), - element-icon("/images/icons/gavel-solid-full.svg", height: 0.7em, baseline: 0.5pt), + element-icon( + "/images/icons/gavel-solid-full.svg", + height: 0.7em, + baseline: 0.5pt, + ), element-icon("/images/icons/sun-solid-full.svg"), element-icon("/images/icons/fire-flame-curved-solid-full.svg"), element-icon("/images/icons/mountain-solid-full.svg"), @@ -192,11 +236,17 @@ element-icon("/images/icons/icicles-solid-full.svg"), element-icon("/images/icons/lightning-fill.svg"), ) - let rows = creature.body-parts.map(part => ( - smallcaps(part.name), ..part.resistances.map(resistance), - )).flatten() + let rows = creature + .body-parts + .map(part => ( + smallcaps(part.name), + ..part.resistances.map(resistance), + )) + .flatten() [ - #show table.cell: it => if it.y > 0 { text(size: 9pt, it) } else { text(size: 12pt, it) } + #show table.cell: it => if it.y > 0 { text(size: 9pt, it) } else { + text(size: 12pt, it) + } #table( columns: (25%,) + (75% / 13,) * 13, row-gutter: 1.5pt, @@ -214,12 +264,32 @@ let s = creature.stats let rows = () for (index, init) in creature.initiatives.enumerate() { - rows += (cell(init.name), cell(init.p1-value), cell(init.p1-actions), cell(init.p2-value), cell(init.p2-actions)) + rows += ( + cell(init.name), + cell(init.p1-value), + cell(init.p1-actions), + cell(init.p2-value), + cell(init.p2-actions), + ) if index == 0 { rows += ( - [], cell(s.strength), cell(s.perception), cell(s.willpower), cell(s.alteration-resistance), cell(s.torque), cell(s.awareness), cell(s.fatigue), - [], cell(s.movement.walk), cell(s.movement.trot), cell(s.movement.run), cell(s.movement.flight), - [], cell(s.transcendental-resistance), cell(s.physical-bonus), cell(s.elemental-bonus), + [], + cell(s.strength), + cell(s.perception), + cell(s.willpower), + cell(s.alteration-resistance), + cell(s.torque), + cell(s.awareness), + cell(s.fatigue), + [], + cell(s.movement.walk), + cell(s.movement.trot), + cell(s.movement.run), + cell(s.movement.flight), + [], + cell(s.transcendental-resistance), + cell(s.physical-bonus), + cell(s.elemental-bonus), ) } else { rows += ([],) * 17 @@ -235,18 +305,38 @@ #table( columns: (100% / 22,) * 22, inset: (x: 1.5pt, y: 2pt), - align: (x, y) => if y == 1 { right + horizon } else { center + horizon }, + align: (x, y) => if y == 1 { right + horizon } else { + center + horizon + }, stroke: none, table.header( [], table.cell(colspan: 2)[P1], table.cell(colspan: 2)[P2], [], - table.cell(colspan: 7)[Stats], [], table.cell(colspan: 4)[Mouvement], [], table.cell(colspan: 3)[Extra], + table.cell(colspan: 7)[Stats], + [], + table.cell(colspan: 4)[Mouvement], + [], + table.cell(colspan: 3)[Extra], table.hline(start: 1, end: 5, stroke: 0.5pt + theme.border), table.hline(start: 6, end: 13, stroke: 0.5pt + theme.border), table.hline(start: 14, end: 18, stroke: 0.5pt + theme.border), table.hline(start: 19, end: 22, stroke: 0.5pt + theme.border), [Initiative], [Valeur], [Action], [Valeur], [Actions], [], - [Force], [Perception], [Volonté], [Rés. Alt.], [Torque], [Vigilance], [Fatigue], [], - [Marche], [Trot], [Course], [Vol], [], [Rés. Trans.], [Bon. Phy.], [Bon. Élém.], + [Force], + [Perception], + [Volonté], + [Rés. Alt.], + [Torque], + [Vigilance], + [Fatigue], + [], + [Marche], + [Trot], + [Course], + [Vol], + [], + [Rés. Trans.], + [Bon. Phy.], + [Bon. Élém.], ), ..rows, ) @@ -257,7 +347,11 @@ #let attack-table(creature) = { let contents = () for phase in creature.phases { - contents.push(table.cell(colspan: 13, fill: theme.dark-gold, text(fill: white, weight: "bold", phase.name))) + contents.push(table.cell(colspan: 13, fill: theme.dark-gold, text( + fill: white, + weight: "bold", + phase.name, + ))) for group in phase.groups { // Colour belongs to the complete skill group, not to an individual row: // multi-line attacks and their explanation therefore read as one unit. @@ -273,28 +367,75 @@ for attack in group.attacks { contents += ( table.cell(fill: group-color)[], - 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), + 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, rich-text(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: (0.5em, 8em, 3em, 4em, 1em, 2em, 2em, 3em, 2em, 3em, 1fr, 1em, 1em), + columns: ( + 0.5em, + 8em, + 3em, + 4em, + 1em, + 2em, + 2em, + 1em, + 2em, + 4em, + 1fr, + 1em, + 1em, + ), inset: (x: 2pt, y: 2.5pt), align: (x, _) => if x == 1 or x == 10 { left } else { center }, stroke: none, - [], [], [], [], [], table.cell(colspan: 2)[Coûts], [], table.cell(colspan: 2)[Dégâts], [], table.cell(colspan: 2)[Seuils], - table.header([], [], [Type], [Timing], [Ciblage], [Fatigue], [Action], [Élément], [Fatigue], [Normaux], [Effets], [Parade], [Esquive]), + [], + [], + [], + [], + [], + table.cell(colspan: 2)[Coûts], + [], + table.cell(colspan: 2)[Dégâts], + [], + table.cell(colspan: 2)[Seuils], + table.header( + [], + [], + [Type], + [Timing], + [Ciblage], + [Fatigue], + [Action], + [Élément], + [Fatigue], + [Normaux], + [Effets], + [Parade], + [Esquive], + ), ..contents, ) } @@ -321,7 +462,11 @@ pagebreak() [ #show table.cell: it => if it.y == 1 { - text(size: 6pt, align(center + bottom, rotate(-90deg, it, reflow: true))) + text(size: 6pt, align(center + bottom, rotate( + -90deg, + it, + reflow: true, + ))) } else { text(size: 8pt, it) } #attack-table(creature) ] diff --git a/setup/models/document.typ b/setup/models/document.typ index 9a120b8..9a9dd80 100644 --- a/setup/models/document.typ +++ b/setup/models/document.typ @@ -22,6 +22,7 @@ body, theme, theme-var, + include-master-glossary: build-config.master-only, ) = { //----- PDF METADATA ----- @@ -507,7 +508,7 @@ let master-only = ( custom != none and custom.at("master_only", default: false) == true ) - build-config.master-only or not master-only + include-master-glossary or not master-only }) print-glossary( visible-glossary, diff --git a/setup/setup.typ b/setup/setup.typ index bfaf923..c0366e8 100644 --- a/setup/setup.typ +++ b/setup/setup.typ @@ -61,6 +61,12 @@ #let enable-warnings = uwarn.enable-warnings.with(ns) //----- Apply the Ravenous model to the main document ----- -#let config_main(variables: ravenous, document) = { - show: model.model(ravenous, document, theme, theme-var) +#let config_main(document, variables: ravenous, master-only: build-config.master-only) = { + show: model.model( + ravenous, + document, + theme, + theme-var, + include-master-glossary: master-only, + ) } diff --git a/tools/check_creature_eval.sh b/tools/check_creature_eval.sh new file mode 100755 index 0000000..1f7a5c3 --- /dev/null +++ b/tools/check_creature_eval.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +set -euo pipefail + +project_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) +database="$project_root/data/src/db/monsters.db" +output_dir="${TMPDIR:-/tmp}/ravenous-creature-eval" + +mkdir -p "$output_dir" + +if (($# > 1)); then + echo "usage: $0 [creature_id]" >&2 + exit 2 +fi + +if (($# == 1)); then + creature_ids=$1 +else + creature_ids=$(sqlite3 "$database" \ + "SELECT id FROM creature WHERE show_to_master = 1 ORDER BY id;") +fi + +for creature_id in $creature_ids; do + echo "checking creature_id=$creature_id" + if ! typst compile \ + --root "$project_root" \ + --input preset=master-handbook \ + --input creature_id="$creature_id" \ + "$project_root/master_handbook.typ" \ + "$output_dir/creature-$creature_id.pdf" + then + echo "FAILED creature_id=$creature_id" >&2 + exit 1 + fi +done + +echo "All selected creature entries passed eval."