Generated stand-in art and sounds, ten more OFL fonts, PNG tiles in the theme generator; untrack __pycache__. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
79 lines
3.3 KiB
Python
79 lines
3.3 KiB
Python
"""Regenerate the stand-in theme art for every theme, plus tools/theme_art/meta.json.
|
|
|
|
Run from anywhere: python3 -I tools/theme_art/make_theme_art.py
|
|
Writes themes/<id>/{background_tile, background_scene, frame_corner, frame_corner_fixed, frame_edge,
|
|
thread_strip}.svg. Files a theme does not use are removed, so a re-run always matches the plan.
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
sys.dont_write_bytecode = True # keep __pycache__ out of the repo
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
from frame_styles import FRAME_STYLES # noqa: E402
|
|
from frames import corner_fixed_svg, corner_svg, edge_svg, frame_meta # noqa: E402
|
|
from scenes import make_background_scene # noqa: E402
|
|
from svg_common import remove_theme_file, write_theme_file # noqa: E402
|
|
from theme_colours import THEMES # noqa: E402
|
|
from threads import make_thread_strip # noqa: E402
|
|
from threads_more import PIN_SIZE_PX, pushpin_svg # noqa: E402
|
|
|
|
META_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "meta.json")
|
|
|
|
|
|
def write_or_remove(theme_id, file_name, text):
|
|
if text is None:
|
|
remove_theme_file(theme_id, file_name)
|
|
else:
|
|
write_theme_file(theme_id, file_name, text)
|
|
|
|
|
|
def write_background_tile(theme_id, pattern):
|
|
"""Write the tile (SVG, or PNG for marble, which needs noise SVG cannot draw in ThorVG); return its meta."""
|
|
if pattern["kind"] == "marble":
|
|
from marble_tile import make_marble_png # only this tile needs numpy
|
|
|
|
remove_theme_file(theme_id, "background_tile.svg")
|
|
write_theme_file(theme_id, "background_tile.png", make_marble_png(pattern))
|
|
return {"file": "background_tile.png", "opacity": pattern["op"], "scale": 1.0}
|
|
from tiles import make_background_tile
|
|
|
|
remove_theme_file(theme_id, "background_tile.png")
|
|
tile_text, tile_meta = make_background_tile(pattern)
|
|
write_or_remove(theme_id, "background_tile.svg", tile_text)
|
|
return tile_meta
|
|
|
|
|
|
def build_theme(theme_id, theme):
|
|
"""Write one theme's files and return its meta entry."""
|
|
tile_meta = write_background_tile(theme_id, theme["pattern"])
|
|
scene_text, scene_meta = make_background_scene(theme["scene"])
|
|
write_or_remove(theme_id, "background_scene.svg", scene_text)
|
|
|
|
style = FRAME_STYLES[theme["frame"]](theme["colours"])
|
|
write_theme_file(theme_id, "frame_corner.svg", corner_svg(style))
|
|
write_theme_file(theme_id, "frame_edge.svg", edge_svg(style))
|
|
write_or_remove(theme_id, "frame_corner_fixed.svg", corner_fixed_svg(style))
|
|
|
|
strip_text, thread_meta = make_thread_strip(theme["thread"])
|
|
write_theme_file(theme_id, "thread_strip.svg", strip_text)
|
|
has_pins = theme.get("pins", False)
|
|
write_or_remove(theme_id, "thread_pin.svg", pushpin_svg(theme["colours"]) if has_pins else None)
|
|
if has_pins:
|
|
thread_meta["pin_size"] = PIN_SIZE_PX
|
|
return {"frame": frame_meta(style), "thread": thread_meta,
|
|
"background_tile": tile_meta, "background_scene": scene_meta}
|
|
|
|
|
|
def main():
|
|
meta = {theme_id: build_theme(theme_id, theme) for theme_id, theme in THEMES.items()}
|
|
with open(META_PATH, "w", encoding="utf-8") as handle:
|
|
json.dump(meta, handle, indent=2)
|
|
handle.write("\n")
|
|
print(f"Wrote art for {len(meta)} themes; meta in {META_PATH}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|