"""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//{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.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 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 build_theme(theme_id, theme): """Write one theme's files and return its meta entry.""" from tiles import make_background_tile # local import keeps the module list above short tile_text, tile_meta = make_background_tile(theme["pattern"]) write_or_remove(theme_id, "background_tile.svg", tile_text) 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) 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()