#!/usr/bin/env python3 """Generate the runtime NinePatch frames for the Windroost UI. The pixel UI component board (`pixel_ui_component_board.png`) is a style reference only. The game needs individual frames with known border margins so Godot's NinePatchRect can keep the pixel corners and the 6px border band crisp while the interior stretches. Frame geometry (shared with the component board): * 6px accent border band * 6px transparent pixel-cut corners * flat interior * patch margin = 6 on every side Outputs land in PRODUCTION/source/pixel_pilot/ui/frames/ and are linked into the Godot sample as symlinks; the board is never modified. """ from __future__ import annotations import json from pathlib import Path from typing import Dict from PIL import Image, ImageDraw BG = (15, 25, 42) PANEL = (28, 45, 68) PANEL_INNER = (36, 58, 82) BORDER = (232, 201, 120) BORDER_DARK = (127, 91, 58) TEXT = (255, 244, 205) MINT = (111, 218, 178) ORANGE = (225, 116, 72) PURPLE = (126, 93, 154) PURPLE_DARK = (86, 62, 110) FRAME_SIZE = 48 BORDER_INSET = 6 OUT_DIR = Path("PRODUCTION/source/pixel_pilot/ui/frames") # name -> (interior fill, accent colour, transparent background) FRAMES: Dict[str, tuple] = { "ui_frame_panel": (PANEL, BORDER, False), "ui_frame_button": (PANEL, BORDER, False), "ui_frame_button_pressed": (PURPLE, BORDER, False), "ui_frame_tab": (PANEL, BORDER, False), "ui_frame_tab_selected": (PURPLE_DARK, BORDER, False), "ui_frame_tile": (PANEL, BORDER, False), "ui_frame_stage": (PANEL_INNER, BORDER, False), } def draw_frame(size: int, fill, accent, transparent_bg: bool) -> Image.Image: """Draw one NinePatch frame using the component board's geometry.""" if transparent_bg: image = Image.new("RGBA", (size, size), (0, 0, 0, 0)) else: image = Image.new("RGBA", (size, size), BG + (255,)) draw = ImageDraw.Draw(image) inset = BORDER_INSET # Pixel-cut corners keep NinePatch corners stable when the center stretches. draw.rectangle((inset, 0, size - inset, size), fill=accent + (255,)) draw.rectangle((0, inset, size, size - inset), fill=accent + (255,)) draw.rectangle((inset, inset, size - inset, size - inset), fill=fill + (255,)) # Punch the four corner notches back out so the panel reads as pixel cut. for cx, cy in ((0, 0), (size - inset, 0), (0, size - inset), (size - inset, size - inset)): draw.rectangle((cx, cy, cx + inset - 1, cy + inset - 1), fill=(0, 0, 0, 0)) return image def draw_icon(size: int, kind: str, color) -> Image.Image: image = Image.new("RGBA", (size, size), (0, 0, 0, 0)) draw = ImageDraw.Draw(image) if kind == "sword": draw.polygon([(20, 4), (30, 14), (14, 30), (4, 20)], fill=color + (255,)) draw.rectangle((2, 29, 31, 35), fill=BORDER + (255,)) draw.rectangle((13, 34, 20, 43), fill=BORDER_DARK + (255,)) elif kind == "bolt": draw.polygon( [(22, 2), (8, 24), (19, 24), (13, 44), (35, 17), (24, 17)], fill=color + (255,) ) else: draw.polygon( [ (22, 2), (28, 16), (43, 18), (31, 28), (35, 43), (22, 34), (9, 43), (13, 28), (1, 18), (16, 16), ], fill=color + (255,), ) return image def main() -> int: OUT_DIR.mkdir(parents=True, exist_ok=True) manifest = {} for name, (fill, accent, transparent) in FRAMES.items(): image = draw_frame(FRAME_SIZE, fill, accent, transparent) path = OUT_DIR / f"{name}.png" image.save(path) manifest[name] = { "file": path.name, "width": FRAME_SIZE, "height": FRAME_SIZE, "patch_margin": BORDER_INSET, "transparent_background": transparent, } for name, kind, color in ( ("ui_icon_sword", "sword", ORANGE), ("ui_icon_bolt", "bolt", MINT), ("ui_icon_star", "star", BORDER), ): image = draw_icon(48, kind, color) path = OUT_DIR / f"{name}.png" image.save(path) manifest[name] = { "file": path.name, "width": 48, "height": 48, "patch_margin": 0, "transparent_background": True, } manifest_path = OUT_DIR / "ui_frames_manifest.json" manifest_path.write_text( json.dumps({"schema": 1, "frames": manifest}, ensure_ascii=False, indent=2) + "\n", encoding="utf-8", ) print(f"wrote {len(manifest)} frames + manifest to {OUT_DIR}") return 0 if __name__ == "__main__": raise SystemExit(main())