4 unique cards had incorrect or missing dual-flavor marks: - Countertoxin: missing Recovery+Defense marks (had none) - Thornburst Grenade: missing Offense+Strike marks (had none) - Scroll of Detect Magic (Magic + Utility copies): had wrong colors (#c34cff/#ffcc00) instead of correct Magic (#9966cc) + Utility (#ff9933) - Slinger's Chalk (Strike copy): missing Offense+Strike marks (had none) Adds check-flavor-marks.py (audit tool) and fix-flavor-marks.py (repair tool). Reprint PDF: "Specialist Flavor Mark Reprints.pdf" (4 unique cards, 8 pages). Made-with: Cursor
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Inject correct flavor marks into existing SVGs.
|
|
|
|
Usage:
|
|
python3 scripts/fix-flavor-marks.py "path/to/Card.svg" "Offense,Strike" 0c
|
|
"""
|
|
import sys, os, 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 fix_marks(svg_path, flavors, tier_code):
|
|
tree = ET.parse(svg_path)
|
|
root = tree.getroot()
|
|
|
|
layer = root
|
|
for child in root:
|
|
tag = child.tag.split("}")[-1] if "}" in child.tag else child.tag
|
|
if tag == "g":
|
|
layer = child
|
|
break
|
|
|
|
# Remove ALL existing rect_mark elements from anywhere in the layer tree
|
|
def remove_marks(parent):
|
|
for elem in list(parent):
|
|
eid = elem.get("id", "")
|
|
if eid.startswith("rect_mark"):
|
|
parent.remove(elem)
|
|
else:
|
|
tag = elem.tag.split("}")[-1] if "}" in elem.tag else elem.tag
|
|
if tag == "g":
|
|
remove_marks(elem)
|
|
remove_marks(layer)
|
|
remove_marks(root)
|
|
|
|
elements = gc.find_elements(layer)
|
|
|
|
gc.set_flavor_marks(layer, elements, flavors, tier_code)
|
|
|
|
tree.write(svg_path, xml_declaration=True, encoding="unicode")
|
|
print(f"OK: {svg_path} — {flavors} (tier {tier_code})")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 4:
|
|
print("Usage: fix-flavor-marks.py <svg> <flavors> <tier_code>", file=sys.stderr)
|
|
sys.exit(1)
|
|
fix_marks(sys.argv[1], sys.argv[2], sys.argv[3])
|