fix: compose forge equipment base names
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
7606fa254c
commit
1a73e15627
|
|
@ -27,6 +27,14 @@ class CraftSiteTests(unittest.TestCase):
|
|||
self.assertEqual(by_name[("Méthodes", "Préparation Rapide")]["wine_available"], 2)
|
||||
self.assertEqual(by_name[("Effets principaux", "Fulgurance")]["wine_cost"], 3)
|
||||
self.assertEqual(by_name[("Principaux", "Gorkul (Bison)")]["satiety"], 2)
|
||||
forge_bases = [item["name"] for item in catalog["entries"]
|
||||
if item["discipline"] == "Forge" and item["stage"] == "Bases"]
|
||||
crossbows = {name for name in forge_bases if name.startswith("Arbalète")}
|
||||
self.assertEqual(crossbows, {"Arbalète légère", "Arbalète lourde",
|
||||
"Arbalète moyenne", "Arbalète super-lourde"})
|
||||
self.assertNotIn("Arbalète", forge_bases)
|
||||
self.assertFalse(any(name.endswith(" lourde lourde") for name in forge_bases))
|
||||
self.assertFalse(any(name.startswith("Arme ") for name in forge_bases))
|
||||
html = (one / "index.html").read_text(encoding="utf-8")
|
||||
self.assertNotIn("{{", html)
|
||||
self.assertIn("catalog.js", html)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,50 @@ TABLES = {
|
|||
"traps.tsv": ("Pièges", "Pièges"),
|
||||
}
|
||||
|
||||
FORGE_NUMERIC_FIELDS = (
|
||||
"rarity", "cost", "difficulty", "tier", "damage", "p_damage", "precision",
|
||||
"rmax", "armor_break", "armor_pierce", "antimaterial", "protection",
|
||||
"integrity", "dodge", "parry", "speed", "stealth", "action_cost", "range",
|
||||
"agility_bonus",
|
||||
)
|
||||
|
||||
FORGE_ADJECTIVES = {
|
||||
"Light": ("léger", "légère"), "Medium": ("moyen", "moyenne"),
|
||||
"Heavy": ("lourd", "lourde"), "SuperHeavy": ("super-lourd", "super-lourde"),
|
||||
}
|
||||
|
||||
def json_scalar(value):
|
||||
if value in (None, "", "null"):
|
||||
return None
|
||||
try:
|
||||
return json.loads(value)
|
||||
except (TypeError, json.JSONDecodeError):
|
||||
return value
|
||||
|
||||
def forge_name(shape: dict, nature: dict) -> str:
|
||||
category = json_scalar(nature.get("category"))
|
||||
masculine, feminine = FORGE_ADJECTIVES[category]
|
||||
adjective = feminine if shape["name"] in {"Épée", "Hache", "Arbalète", "Armure"} else masculine
|
||||
if shape["name"] == "Griffes":
|
||||
adjective += "s"
|
||||
return f"{shape['name']} {adjective}"
|
||||
|
||||
def compose_forge_base(shape: dict, nature: dict) -> dict:
|
||||
item = dict(shape)
|
||||
for field in FORGE_NUMERIC_FIELDS:
|
||||
item[field] = (shape.get(field) or 0) + (nature.get(field) or 0)
|
||||
item.update({
|
||||
"shape_id": shape["id"], "nature_id": nature["id"],
|
||||
"shape_name": shape["name"], "nature_name": nature["name"],
|
||||
"shape_category": json_scalar(shape.get("category")),
|
||||
"nature_category": json_scalar(nature.get("category")),
|
||||
"name": forge_name(shape, nature), "meta_category": "Equipment",
|
||||
})
|
||||
reload_cost = json_scalar(shape.get("reload_cost"))
|
||||
reload_modifier = json_scalar(nature.get("reload_cost")) or 0
|
||||
item["reload_cost"] = None if reload_cost is None else reload_cost + reload_modifier
|
||||
return item
|
||||
|
||||
def slug(value: str) -> str:
|
||||
plain = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode().lower()
|
||||
return re.sub(r"[^a-z0-9]+", "-", plain).strip("-")
|
||||
|
|
@ -102,11 +146,15 @@ def catalog() -> list[dict]:
|
|||
if WEAPONS.is_file():
|
||||
with sqlite3.connect(f"file:{WEAPONS}?mode=ro", uri=True) as db:
|
||||
db.row_factory = sqlite3.Row
|
||||
for row in db.execute("SELECT * FROM Equipements ORDER BY id"):
|
||||
item = dict(row)
|
||||
name = " ".join(filter(None, [str(item.get("name") or ""), str(item.get("adjective") or "")])).strip()
|
||||
rows = [dict(row) for row in db.execute("SELECT * FROM Equipements ORDER BY id")]
|
||||
shapes = [row for row in rows if row["meta_category"] == "Shape" and json_scalar(row.get("apply_category"))]
|
||||
natures = [row for row in rows if row["meta_category"] == "Nature"]
|
||||
equipment = [compose_forge_base(shape, nature) for shape in shapes for nature in natures
|
||||
if json_scalar(nature.get("target")) == json_scalar(shape.get("apply_category"))]
|
||||
for item in equipment:
|
||||
name = item["name"]
|
||||
entries.append({
|
||||
"id": f"forge:bases:{item['id']}", "discipline": "Forge", "stage": "Bases",
|
||||
"id": f"forge:bases:{item['shape_id']}:{item['nature_id']}", "discipline": "Forge", "stage": "Bases",
|
||||
"name": name, "tier": item.get("tier"), "cost": item.get("cost"),
|
||||
"difficulty": item.get("difficulty"), "toxicity": None, "finishing": None,
|
||||
"satiety": None, "wine": None, "wine_available": None, "wine_cost": None, "time": None,
|
||||
|
|
|
|||
Loading…
Reference in New Issue