"""Offline packing of generated kiosk/lantern art for the assembly renderer.""" from pathlib import Path import re import struct from PIL import Image ROOT = Path(__file__).resolve().parents[2] SOURCE = ROOT / "assets/sprites/terminals" OUT = ROOT / "assets/animations/hall" def pack(path, frames): w, h = frames[0].size raw = b"".join(image.tobytes("raw", "BGRA") for image in frames) path.write_bytes(struct.pack("<4s4I", b"ANM1", w, h, len(frames), len(raw)) + raw) def title(image, text, y): font = bytes(int(x, 16) for x in re.findall(r"\b([0-9A-Fa-f]{3})h\b", (ROOT / "font8x8.inc").read_text(encoding="cp1251"))) x = (image.width - len(text) * 8) // 2 for n, char in enumerate(text): for row in range(8): for col in range(8): if font[char * 8 + row] & (128 >> col): image.putpixel((x + n * 8 + col, y + row), (48, 30, 16, 255)) def main(): frames = [Image.open(SOURCE / name).convert("RGBA").resize((256, 512), Image.Resampling.LANCZOS) for name in ("cash-front-v1.png", "trophy-front-v1.png", "lantern-glass-v1.png", "body-side-rear-v2.png")] title(frames[0], b"\xca\xc0\xd1\xd1\xc0", 27) title(frames[1], b"\xc4\xce\xd1\xd2\xc8\xc6\xc5\xcd\xc8\xdf", 25) pack(OUT / "terminals-v2.bin", frames) screen = Image.open(SOURCE / "display-v1.png").convert("RGBA").resize((640, 480), Image.Resampling.LANCZOS) pack(OUT / "terminal-screen-v1.bin", [screen]) print("Packed four 256x512 world materials, including a dedicated equipment enclosure, and one 640x480 screen") if __name__ == "__main__": main()