77 lines
3.2 KiB
Python
77 lines
3.2 KiB
Python
"""Static quality checks for fixed-cell 16-frame runtime atlases."""
|
|
from pathlib import Path
|
|
|
|
import numpy as np
|
|
from PIL import Image, ImageChops
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ASSETS = ROOT / "assets"
|
|
SPECS = {
|
|
"mafuyu-attack-16.png": (4, 4, 320, 320),
|
|
"mafuyu-ice-bow.png": (4, 4, 320, 320),
|
|
"mafuyu-ice-charge.png": (4, 4, 320, 320),
|
|
"mafuyu-ice-release.png": (4, 4, 320, 320),
|
|
"sekai-enemies-16.png": (16, 4, 192, 144),
|
|
"sekai-interactables-16.png": (16, 4, 192, 192),
|
|
"sekai-expansion-enemies-16.png": (16, 4, 192, 160),
|
|
"sekai-expansion-interactables-16.png": (16, 4, 224, 224),
|
|
"mafuyu-final-boss-16.png": (16, 4, 256, 256),
|
|
}
|
|
LOOP_ATLASES = {"sekai-enemies-16.png", "sekai-interactables-16.png", "sekai-expansion-enemies-16.png", "sekai-expansion-interactables-16.png"}
|
|
|
|
|
|
def frames(image: Image.Image, columns: int, rows: int, width: int, height: int):
|
|
for row in range(rows):
|
|
for column in range(columns):
|
|
yield image.crop((column * width, row * height, (column + 1) * width, (row + 1) * height))
|
|
|
|
|
|
def distance(first: Image.Image, second: Image.Image) -> float:
|
|
a = np.asarray(first, dtype=np.int16)
|
|
b = np.asarray(second, dtype=np.int16)
|
|
return float(np.abs(a - b).mean())
|
|
|
|
|
|
problems = []
|
|
for name, (columns, rows, width, height) in SPECS.items():
|
|
path = ASSETS / name
|
|
if not path.exists():
|
|
problems.append(f"missing {name}")
|
|
continue
|
|
image = Image.open(path).convert("RGBA")
|
|
if image.size != (columns * width, rows * height):
|
|
problems.append(f"{name}: expected {columns * width}x{rows * height}, got {image.size}")
|
|
continue
|
|
atlas_frames = list(frames(image, columns, rows, width, height))
|
|
for index, frame in enumerate(atlas_frames):
|
|
alpha = np.asarray(frame.getchannel("A"))
|
|
if not np.any(alpha > 8):
|
|
problems.append(f"{name}: empty frame {index + 1}")
|
|
if np.any(alpha[:2] > 12) or np.any(alpha[-2:] > 12) or np.any(alpha[:, :2] > 12) or np.any(alpha[:, -2:] > 12):
|
|
problems.append(f"{name}: frame {index + 1} touches its cell border")
|
|
|
|
if name in LOOP_ATLASES:
|
|
for row in range(rows):
|
|
loop = atlas_frames[row * 16:(row + 1) * 16]
|
|
steps = [distance(loop[index], loop[index + 1]) for index in range(15)]
|
|
seam = distance(loop[-1], loop[0])
|
|
if seam > max(steps) * 1.5 + 0.25:
|
|
problems.append(f"{name}: row {row + 1} loop seam {seam:.2f} exceeds motion steps")
|
|
|
|
charge = Image.open(ASSETS / "mafuyu-ice-charge.png").convert("RGBA")
|
|
charge_frames = list(frames(charge, 4, 4, 320, 320))
|
|
if ImageChops.difference(charge_frames[0], charge_frames[-1]).getbbox() is not None:
|
|
problems.append("mafuyu-ice-charge.png: frame 16 must exactly match frame 1")
|
|
|
|
if problems:
|
|
print("Animation asset validation failed:")
|
|
for problem in problems:
|
|
print(f"FAIL {problem}")
|
|
raise SystemExit(1)
|
|
|
|
print("PASS nine fixed-cell atlases have complete, non-overlapping frame gutters")
|
|
print("PASS base and expansion enemy/interactable 16-frame loop seams are bounded")
|
|
print("PASS final boss has four isolated sixteen-frame action rows")
|
|
print("PASS charged ice-sword frame 16 exactly matches frame 1")
|