feat: render Ravenous references in exports
Roll20 Sheet Build Successful The Ravenous Roll20 sheet was generated and validated successfully.
Ravenous/ravenous_roll20/pipeline/head This commit looks good
Details
Roll20 Sheet Build Successful The Ravenous Roll20 sheet was generated and validated successfully.
Ravenous/ravenous_roll20/pipeline/head This commit looks good
Details
This commit is contained in:
parent
7ac98f8d14
commit
5ed908ab69
|
|
@ -28,6 +28,17 @@ class BuildTests(unittest.TestCase):
|
|||
self.assertGreater(info["techniques"], 100)
|
||||
self.assertGreater(info["skills"], 10)
|
||||
|
||||
def test_typst_references_and_difficulties_are_rendered(self):
|
||||
from tools.build import difficulty_stars, read_glossary_labels, translate_typst
|
||||
|
||||
glossary = read_glossary_labels()
|
||||
self.assertEqual("Concussif", translate_typst("@al_concussif", glossary))
|
||||
self.assertEqual("★ ★★ ★★★ 4★ -★ -4★ 0★", " ".join(
|
||||
difficulty_stars(value) for value in ("1", "2", "3", "4", "-1", "-4", "0")
|
||||
))
|
||||
self.assertEqual("Concussif (★★)",
|
||||
translate_typst("@al_concussif (#ddlvl(2))", glossary))
|
||||
|
||||
def test_roll20_constraints(self):
|
||||
sheet = (ROOT / "build/ravenous.html").read_text()
|
||||
self.assertNotIn("{{SKILL_ROWS}}", sheet)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import re
|
||||
import sqlite3
|
||||
import unittest
|
||||
|
||||
|
|
@ -36,6 +37,10 @@ class MonsterExportTests(unittest.TestCase):
|
|||
for name in attrs) +
|
||||
sum(name.endswith("_description") and name.startswith("repeating_powers_")
|
||||
for name in attrs))
|
||||
rendered = "\n".join(value for name, value in attrs.items()
|
||||
if name.endswith(("_notes", "_description")))
|
||||
self.assertIsNone(re.search(r"@[A-Za-z_]", rendered))
|
||||
self.assertNotIn("#ddlvl", rendered)
|
||||
for ability in source["abilities"]:
|
||||
if not ability["damage_regular"]:
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -86,12 +86,24 @@ def _replace_balanced_calls(text: str, macro: str, renderer) -> str:
|
|||
return text
|
||||
|
||||
|
||||
def difficulty_stars(value: str) -> str:
|
||||
"""Render a Typst difficulty level with compact Unicode stars."""
|
||||
raw = value.strip()
|
||||
try:
|
||||
level = int(raw)
|
||||
except ValueError:
|
||||
return raw
|
||||
magnitude = abs(level)
|
||||
rendered = "★" * magnitude if 0 < magnitude <= 3 else f"{magnitude}★"
|
||||
return ("-" if level < 0 else "") + rendered
|
||||
|
||||
|
||||
def translate_typst(text: str, glossary: dict[str, str]) -> str:
|
||||
"""Turn the subset of Typst markup used by school TSVs into chat-safe text."""
|
||||
characteristics = {"force": "Force", "agi": "Agilité", "per": "Perception", "int": "Intelligence", "vol": "Volonté", "psy": "Psy", "chance": "Chance", "cha": "Charisme"}
|
||||
text = re.sub(r"#inline_help\[([^]]*)]", r"Note : \1", text)
|
||||
text = re.sub(r"#footnote\[([^]]*)]", r"(Note : \1)", text)
|
||||
text = _replace_balanced_calls(text, "ddlvl", lambda args: "DD " + args.split(",", 1)[0].strip())
|
||||
text = _replace_balanced_calls(text, "ddlvl", lambda args: difficulty_stars(args.split(",", 1)[0]))
|
||||
text = _replace_balanced_calls(text, "resist", lambda args: "Résistance " + args.split(",", 1)[0].strip())
|
||||
text = _replace_balanced_calls(text, "marques", lambda args: "Marque " + args.replace("[", "").replace("]", ""))
|
||||
text = _replace_balanced_calls(text, "gls", lambda args: (re.search(r'display\s*:\s*"([^"]+)"', args) or re.search(r'"([^"]+)"', args)).group(1))
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ import re
|
|||
import sqlite3
|
||||
from pathlib import Path
|
||||
|
||||
if __package__:
|
||||
from tools.build import read_glossary_labels, translate_typst
|
||||
else: # Support the documented ``python tools/export_monsters.py`` invocation.
|
||||
from build import read_glossary_labels, translate_typst
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DEFAULT_DB = ROOT / "ravenous_typst/data/src/db/monsters.db"
|
||||
|
||||
|
|
@ -42,6 +47,7 @@ def convert(db: sqlite3.Connection, creature_id: int) -> dict:
|
|||
parts = rows(db, "creature_body_parts", creature_id)
|
||||
abilities = rows(db, "creature_abilities", creature_id)
|
||||
rewards = rows(db, "creature_rewards", creature_id)
|
||||
glossary = read_glossary_labels()
|
||||
attrs: dict[str, dict] = {}
|
||||
|
||||
def add(name: str, value: object, maximum: object = "") -> None:
|
||||
|
|
@ -69,13 +75,13 @@ def convert(db: sqlite3.Connection, creature_id: int) -> dict:
|
|||
|
||||
for ability in abilities:
|
||||
ident = f"dbability{ability['attack_id']}"
|
||||
description = "\n".join(filter(None, [
|
||||
description = translate_typst("\n".join(filter(None, [
|
||||
f"Phase: {text(ability['phase'])}",
|
||||
f"Type: {text(ability['attack_type'])}",
|
||||
f"Dégâts: {text(ability['damage_regular'])}",
|
||||
f"Succès: {text(ability['success'])}",
|
||||
text(ability["description_all"]), text(ability["effects"]),
|
||||
]))
|
||||
])), glossary)
|
||||
if ability["damage_regular"]:
|
||||
prefix = f"repeating_attacks_{ident}_"
|
||||
successes = fixed_successes(ability["success"])
|
||||
|
|
@ -102,7 +108,7 @@ def convert(db: sqlite3.Connection, creature_id: int) -> dict:
|
|||
"stats": stats, "body_parts": parts, "abilities": abilities,
|
||||
"rewards": rewards}
|
||||
return {"format": "ravenous-roll20-character", "version": 1,
|
||||
"name": core["name"], "bio": text(core["description"]),
|
||||
"name": core["name"], "bio": translate_typst(text(core["description"]), glossary),
|
||||
"gmnotes": json.dumps(source, ensure_ascii=False),
|
||||
"attributes": list(attrs.values())}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue