Files
windroost/tools/compose_style_candidate_preview.py
T

101 lines
4.4 KiB
Python

#!/usr/bin/env python3
"""Compose a static 390x844 style-candidate battle preview.
This is a review artifact only. It does not replace Godot runtime rendering.
"""
from pathlib import Path
from PIL import Image, ImageDraw, ImageFont, ImageOps
ROOT = Path(__file__).resolve().parents[1]
OUT = ROOT / "PRODUCTION/references/style_review/candidate-bd-battle-preview.png"
BG = ROOT / "PRODUCTION/source/style_candidate_bd/background_windplain.png"
ASSET = ROOT / "PRODUCTION/cleaned/style_candidate_bd/characters"
def font(size: int, bold: bool = False):
name = "Arial Bold.ttf" if bold else "Arial.ttf"
return ImageFont.truetype(f"/System/Library/Fonts/Supplemental/{name}", size)
def draw_centered(draw: ImageDraw.ImageDraw, box, text, fnt, fill):
x1, y1, x2, y2 = box
bounds = draw.textbbox((0, 0), text, font=fnt)
x = x1 + (x2 - x1 - (bounds[2] - bounds[0])) // 2
y = y1 + (y2 - y1 - (bounds[3] - bounds[1])) // 2 - 1
draw.text((x, y), text, font=fnt, fill=fill)
def paste_scaled(base: Image.Image, path: Path, box):
im = Image.open(path).convert("RGBA")
x1, y1, x2, y2 = box
im.thumbnail((x2 - x1, y2 - y1), Image.Resampling.LANCZOS)
x = x1 + (x2 - x1 - im.width) // 2
y = y2 - im.height
base.alpha_composite(im, (x, y))
def main():
canvas = Image.new("RGBA", (390, 844), (226, 237, 240, 255))
bg = Image.open(BG).convert("RGB")
bg = ImageOps.fit(bg, (390, 844), method=Image.Resampling.LANCZOS, centering=(0.5, 0.55))
canvas.alpha_composite(bg.convert("RGBA"), (0, 0))
draw = ImageDraw.Draw(canvas)
navy = (28, 52, 76, 246)
cream = (247, 226, 177, 255)
pale = (216, 244, 238, 255)
coral = (225, 106, 70, 255)
teal = (75, 184, 178, 255)
gold = (235, 182, 72, 255)
border = (221, 175, 67, 255)
# Top resource block.
draw.rounded_rectangle((8, 8, 382, 88), radius=14, fill=navy, outline=border, width=2)
draw.text((20, 18), "WINDROOST", font=font(17, True), fill=cream)
draw.text((20, 42), "AETHER RUN · NODE 01", font=font(9), fill=pale)
draw.text((280, 20), "GOLD 12.4K", font=font(10, True), fill=cream)
draw.text((280, 44), "WIND 3.2K", font=font(9), fill=pale)
# Boss target bar.
draw.rounded_rectangle((36, 102, 354, 136), radius=11, fill=navy, outline=border, width=2)
draw.text((48, 112), "B01 CLOUDHEART WARDEN", font=font(9, True), fill=cream)
draw.text((278, 112), "00:27", font=font(9, True), fill=cream)
draw.rounded_rectangle((47, 142, 343, 160), radius=7, fill=(33, 30, 45, 235), outline=(112, 75, 57, 255), width=1)
draw.rounded_rectangle((48, 143, 266, 159), radius=6, fill=coral)
# Combat actors.
paste_scaled(canvas, ASSET / "B01_idle.png", (72, 174, 318, 448))
paste_scaled(canvas, ASSET / "EG01_idle.png", (12, 378, 132, 504))
paste_scaled(canvas, ASSET / "H01_idle.png", (245, 388, 378, 520))
draw.text((20, 505), "EG01 SKY GOBLIN", font=font(8, True), fill=(255, 246, 214, 255))
draw.text((271, 523), "H01 · DPS 10", font=font(8, True), fill=(255, 246, 214, 255))
# Tactical slots.
draw.rounded_rectangle((9, 552, 381, 657), radius=14, fill=navy, outline=border, width=2)
draw.text((20, 565), "MANUAL ACTIONS", font=font(12, True), fill=cream)
for i, label in enumerate(("H01", "H02", "H03", "H04", "H05")):
x = 20 + i * 71
draw.rounded_rectangle((x, 584, x + 57, 642), radius=8, fill=(20, 49, 72, 255), outline=border, width=1)
draw.ellipse((x + 22, 593, x + 34, 605), fill=coral)
draw_centered(draw, (x, 612, x + 57, 638), label, font(8, True), cream)
# Actions and navigation.
draw.rounded_rectangle((9, 672, 381, 835), radius=14, fill=navy, outline=border, width=2)
for box, label, fill in [((38, 694, 126, 786), "STORM", teal), ((151, 694, 239, 786), "ULTIMATE", coral), ((264, 694, 352, 786), "AUTO", gold)]:
draw.rounded_rectangle(box, radius=14, fill=(19, 48, 70, 255), outline=fill, width=2)
draw.ellipse((box[0] + 27, box[1] + 14, box[0] + 61, box[1] + 48), fill=fill)
draw_centered(draw, (box[0], box[1] + 53, box[2], box[3]), label, font(9, True), cream)
for x, label in ((28, "EXPEDITION"), (119, "ROSTER"), (214, "SKYPORT"), (310, "ARCHIVE")):
draw.text((x, 806), label, font=font(7), fill=pale)
OUT.parent.mkdir(parents=True, exist_ok=True)
canvas.convert("RGB").save(OUT)
print(OUT)
if __name__ == "__main__":
main()