"""Writes tg_surfaces.py: tg_surfaces_head.py (the Tiger's sets, atlases, screen UVs, seam and glass) + the Spearfish's surfaces body (its helper functions and the run: UV layers, the drawn screens, bakes, node dressing; models/tender-spearfish/build/ surfaces_spearfish.py from '# --- UV layers' to the end, without its own screen_uvs, seam_value and dress_glass) with the names changed, as the Mako's make_surfaces.py does. Plain python: python build/tg_make_surfaces.py""" import os HERE = os.path.dirname(os.path.abspath(__file__)) src = open(os.path.join(HERE, "..", "..", "tender-spearfish", "build", "surfaces_spearfish.py"), encoding="utf-8").read() body = src[src.index("# ------------------------------------------------------------------ UV layers"):] for start, end in (("def screen_uvs(o):", "# ------------------------------------------------------------------ the two baked maps"), ("def seam_value(nt, loc_x=0):", "def bake_atlas("), ("def dress_glass(mat, tint):", "# ------------------------------------------------------------------ run")): a, b = body.index(start), body.index(end) body = body[:a] + body[b:] for old, new in [("SM_Spearfish", "SM_Tiger"), ('"SPEARFISH | ', '"TIGER | '), ('startswith("SPEARFISH")', 'startswith("TIGER")'), ("T_Spearfish_", "T_Tiger_")]: assert old in body, old body = body.replace(old, new) assert "SPEARFISH" not in body and "Spearfish" not in body, [l for l in body.splitlines() if "SPEARFISH" in l or "Spearfish" in l] out = open(os.path.join(HERE, "tg_surfaces_head.py"), encoding="utf-8").read() + "\n\n" + body open(os.path.join(HERE, "tg_surfaces.py"), "w", encoding="utf-8").write(out) print("written", len(out.splitlines()), "lines")