Files
windroost/tools/compose_pixel_battle_preview.py
T

72 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""Compose a static 390x844 pixel battle review image.
This is a layout check only; the rectangles are placeholders for the Godot HUD
contract and do not represent final UI art.
"""
from __future__ import annotations
import argparse
from pathlib import Path
from PIL import Image, ImageDraw
def fit_cover(image: Image.Image, size: tuple[int, int]) -> Image.Image:
scale = max(size[0] / image.width, size[1] / image.height)
image = image.resize((round(image.width * scale), round(image.height * scale)), Image.Resampling.NEAREST)
x = (image.width - size[0]) // 2
y = (image.height - size[1]) // 2
return image.crop((x, y, x + size[0], y + size[1]))
def paste_display(base: Image.Image, path: Path, size: int, xy: tuple[int, int]) -> None:
sprite = Image.open(path).convert("RGBA")
sprite = sprite.resize((size, size), Image.Resampling.NEAREST)
base.alpha_composite(sprite, xy)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--background", required=True, type=Path)
parser.add_argument("--hero", required=True, type=Path)
parser.add_argument("--enemy", required=True, type=Path)
parser.add_argument("--boss", required=True, type=Path)
parser.add_argument("--output", required=True, type=Path)
args = parser.parse_args()
size = (390, 844)
base = fit_cover(Image.open(args.background).convert("RGB"), size).convert("RGBA")
draw = ImageDraw.Draw(base)
# HUD placeholders follow the agreed vertical contract: progress/header,
# battlefield, then manual controls and bottom navigation.
draw.rectangle((12, 12, 378, 76), fill=(24, 45, 63, 235), outline=(235, 204, 124, 255), width=2)
draw.rectangle((26, 32, 235, 48), fill=(11, 20, 35, 230), outline=(129, 220, 184, 255), width=1)
draw.rectangle((28, 34, 174, 46), fill=(220, 119, 75, 255))
draw.rectangle((242, 26, 364, 60), fill=(72, 55, 85, 235), outline=(235, 204, 124, 255), width=1)
draw.text((253, 34), "BOSS 00:21", fill=(255, 242, 201, 255))
# Battlefield samples; all sprite sizes are nearest-neighbour display sizes.
paste_display(base, args.boss, 220, (85, 250))
paste_display(base, args.enemy, 92, (266, 478))
paste_display(base, args.hero, 112, (30, 556))
draw.rectangle((16, 690, 374, 756), fill=(21, 32, 49, 220), outline=(129, 220, 184, 255), width=2)
draw.rectangle((28, 706, 100, 740), fill=(50, 83, 94, 255), outline=(235, 204, 124, 255), width=1)
draw.rectangle((112, 706, 184, 740), fill=(83, 59, 89, 255), outline=(235, 204, 124, 255), width=1)
draw.rectangle((196, 706, 268, 740), fill=(87, 65, 49, 255), outline=(235, 204, 124, 255), width=1)
draw.rectangle((280, 706, 352, 740), fill=(49, 75, 74, 255), outline=(235, 204, 124, 255), width=1)
draw.rectangle((12, 778, 378, 832), fill=(24, 34, 52, 245), outline=(235, 204, 124, 255), width=2)
for x, label in ((30, "港口"), (112, "英雄"), (194, "远征"), (276, "更多")):
draw.text((x, 797), label, fill=(255, 242, 201, 255))
args.output.parent.mkdir(parents=True, exist_ok=True)
base.convert("RGB").save(args.output, "PNG")
print(args.output)
return 0
if __name__ == "__main__":
raise SystemExit(main())