Files
rick 8be320c0b2 lore(0b): restructure openings for Dustcloud Ball, Quarry Tag, Sneaker's Grease
Replace mechanics-first paragraph 1 with origin hooks:
- Dustcloud Ball: flour mill explosion → retired sapper origin
- Quarry Tag: bounty hunter who decided the problem was philosophical
- Sneaker's Grease: cobbler who moonlighted as second-story specialist

Paragraphs 2-3 and closers preserved. Adds rewrite-lore.py helper script.

Made-with: Cursor
2026-04-16 19:08:49 +02:00

75 lines
2.4 KiB
Python

#!/usr/bin/env python3
"""Rewrite lore text in an existing SVG card without regenerating the full card.
Usage:
python3 scripts/rewrite-lore.py "path/to/Card.svg" "New lore text here..."
Uses the same format_lore_text() and set_text_content() pipeline as generate-card.py
to avoid the tspan space-loss bug (SKILL.md lesson #13).
"""
import sys
import os
import re
import xml.etree.ElementTree as ET
sys.path.insert(0, os.path.dirname(__file__))
from importlib.machinery import SourceFileLoader
gc = SourceFileLoader("generate_card", os.path.join(os.path.dirname(__file__), "generate-card.py")).load_module()
SVG_NS = "http://www.w3.org/2000/svg"
ET.register_namespace("", SVG_NS)
for prefix, uri in [
("xlink", "http://www.w3.org/1999/xlink"),
("inkscape", "http://www.inkscape.org/namespaces/inkscape"),
("sodipodi", "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"),
("svg", SVG_NS),
]:
ET.register_namespace(prefix, uri)
def find_lore_element(root):
"""Locate the lore text element using the same heuristic as generate-card.py."""
texts = []
for child in root:
tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
if tag == "text":
texts.append(child)
elif tag == "g":
for sub in child:
sub_tag = sub.tag.split("}")[-1] if "}" in sub.tag else sub.tag
if sub_tag == "text":
texts.append(sub)
for t in texts:
style = t.get("style", "")
transform = t.get("transform", "")
if "shape-inside" in style and "matrix" in transform:
m = re.search(r"matrix\([^,]+,[^,]+,[^,]+,[^,]+,([^,]+)", transform)
if m:
x_offset = float(m.group(1))
if x_offset > 50:
return t
return None
def rewrite(svg_path, new_lore):
tree = ET.parse(svg_path)
root = tree.getroot()
lore_el = find_lore_element(root)
if lore_el is None:
print(f"ERROR: No lore text element found in {svg_path}", file=sys.stderr)
sys.exit(1)
formatted = gc.format_lore_text(new_lore)
gc.set_text_content(lore_el, formatted, wrap_width=42)
tree.write(svg_path, xml_declaration=True, encoding="unicode")
print(f"OK: {svg_path}")
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: rewrite-lore.py <svg-path> <new-lore-text>", file=sys.stderr)
sys.exit(1)
rewrite(sys.argv[1], sys.argv[2])