Files
windroost/tools/create_pixel_vfx.py
T
wushenghua 7a101173ea feat: add pixel VFX, event binding and visible-node caps; close P2 locally
VFX. The three feedback effects existed only as IDs in the contract. They
are now generated as low-resolution transparent sprite sheets (16/32/64px,
hard pixel clusters, nearest filtering) with their own manifest. VfxView
advances frame indices without interpolation, finishes deterministically, and
drops intermediate frames in low-power mode while keeping the final state.
The battle scene maps authoritative sim events to effects: shield_break,
cast_ultimate and hit. Feedback can no longer disagree with the simulation.

Node caps. The stage now clamps visible enemies to five and visible heroes to
five, with a test that supplies seven enemies and six heroes, checks the real
node counts and verifies stale nodes are released when content shrinks.

tools/run_p2_checks.sh now runs 13 gates; all pass. PRODUCTION/38 records
P2-VFX-01 and the node-count portion of P2-BAT-03 as PASS, so P2 local
acceptance is complete. Open gates are the real-device ones (safe-area inset,
frame time, memory, heat) plus human comprehension and willingness to
continue; no local automation can grant those.
2026-11-17 00:03:47 +08:00

171 lines
5.9 KiB
Python

#!/usr/bin/env python3
"""Generate the three runtime VFX sheets for the Windroost battle stage.
The art contract requires feedback to originate from a low-resolution logical
grid with hard pixel clusters and a limited palette. These sheets are drawn
pixel by pixel at small integer canvases; the Godot side plays them with
nearest filtering and integer placement.
Sheets:
* hit_light 16x16, 4 frames - short bright cross on a landed hit
* shield_break 32x32, 6 frames - shards flying out of a broken shield
* ultimate_burst 64x64, 8 frames - expanding ring plus four rays
Each output is transparent RGBA PNG plus a manifest with frame count, fps and
the anchor a runtime node should use. No frame is interpolated: every frame
is a deliberate pixel cluster.
"""
from __future__ import annotations
import hashlib
import json
import math
from pathlib import Path
from typing import Callable, Dict, List, Tuple
from PIL import Image
from PIL import ImageDraw
OUT_DIR = Path("PRODUCTION/source/pixel_pilot/vfx")
BG = (0, 0, 0, 0)
WHITE = (255, 244, 205, 255)
GOLD = (232, 201, 120, 255)
ORANGE = (225, 116, 72, 255)
MINT = (111, 218, 178, 255)
PURPLE = (126, 93, 154, 255)
def blank(size: int) -> Image.Image:
return Image.new("RGBA", (size, size), BG)
def cross(draw: ImageDraw.ImageDraw, cx: int, cy: int, arm: int, color, thickness: int = 1) -> None:
draw.rectangle((cx - arm, cy, cx + arm, cy), fill=color)
draw.rectangle((cx, cy - arm, cx, cy + arm), fill=color)
if thickness > 1:
draw.rectangle((cx - arm, cy - 1, cx + arm, cy + 1), fill=color)
draw.rectangle((cx - 1, cy - arm, cx + 1, cy + arm), fill=color)
def diagonals(draw: ImageDraw.ImageDraw, cx: int, cy: int, radius: int, color) -> None:
for sx, sy in ((-1, -1), (1, -1), (-1, 1), (1, 1)):
for step in range(radius - 1, radius + 1):
draw.point((cx + sx * step, cy + sy * step), fill=color)
def pixel_ring(draw: ImageDraw.ImageDraw, cx: int, cy: int, radius: int, color, thickness: int = 1) -> None:
# Integer Bresenham-style ring; no antialiasing, no fractional pixels.
x, y = radius, 0
err = 1 - radius
while x >= y:
for dx, dy in ((x, y), (y, x), (-y, x), (-x, y), (-x, -y), (-y, -x), (y, -x), (x, -y)):
px, py = cx + dx, cy + dy
if 0 <= px < 2 * cx + 1 and 0 <= py < 2 * cy + 1:
draw.point((px, py), fill=color)
if thickness > 1:
draw.point((px + 1 if dx > 0 else px - 1, py), fill=color)
y += 1
if err < 0:
err += 2 * y + 1
else:
x -= 1
err += 2 * (y - x) + 1
def hit_light(frame: int) -> Image.Image:
image = blank(16)
draw = ImageDraw.Draw(image)
arms = [2, 4, 6, 7]
colors = [WHITE, WHITE, GOLD, ORANGE]
cross(draw, 8, 8, arms[frame], colors[frame], thickness=1)
if frame >= 1:
diagonals(draw, 8, 8, arms[frame] - 1, colors[frame])
if frame == 3:
pixel_ring(draw, 8, 8, 6, ORANGE)
return image
def shield_break(frame: int) -> Image.Image:
image = blank(32)
draw = ImageDraw.Draw(image)
cx = cy = 16
directions: List[Tuple[int, int]] = [
(1, 0), (-1, 0), (0, 1), (0, -1),
(1, 1), (-1, 1), (1, -1), (-1, -1),
]
radius = 2 + frame * 3
color = MINT if frame < 4 else GOLD
for index, (sx, sy) in enumerate(directions):
# Low-power mode can skip odd shards without losing the read.
distance = radius + (index % 3)
px = cx + sx * distance
py = cy + sy * distance
if not (0 <= px < 32 and 0 <= py < 32):
continue
size = max(1, 3 - frame // 2)
draw.rectangle((px, py, px + size - 1, py + size - 1), fill=color)
if frame == 0:
cross(draw, cx, cy, 6, WHITE, thickness=2)
else:
pixel_ring(draw, cx, cy, max(1, radius - 2), WHITE)
return image
def ultimate_burst(frame: int) -> Image.Image:
image = blank(64)
draw = ImageDraw.Draw(image)
cx = cy = 32
radius = 3 + frame * 4
if frame < 6:
pixel_ring(draw, cx, cy, radius, GOLD if frame % 2 == 0 else WHITE, thickness=2 if frame > 2 else 1)
else:
pixel_ring(draw, cx, cy, radius, ORANGE)
# Four rays stay readable at every frame, including low power.
for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
for step in range(max(1, radius - 3), radius + 1):
draw.point((cx + dx * step, cy + dy * step), fill=PURPLE if frame % 2 else ORANGE)
if frame == 0:
cross(draw, cx, cy, 5, WHITE, thickness=2)
return image
SPECS: Dict[str, Tuple[int, int, int, Callable[[int], Image.Image]]] = {
"hit_light": (16, 4, 20, hit_light),
"shield_break": (32, 6, 16, shield_break),
"ultimate_burst": (64, 8, 14, ultimate_burst),
}
def main() -> int:
OUT_DIR.mkdir(parents=True, exist_ok=True)
manifest = {"schema": 1, "style": "pixel", "filter": "nearest", "effects": {}}
for name, (size, frames, fps, draw_fn) in SPECS.items():
sheet = Image.new("RGBA", (size * frames, size), BG)
for index in range(frames):
sheet.alpha_composite(draw_fn(index), (index * size, 0))
path = OUT_DIR / f"{name}.png"
sheet.save(path)
manifest["effects"][name] = {
"file": path.name,
"cell_size": [size, size],
"frame_count": frames,
"fps": fps,
"loop": False,
"anchor": [size // 2, size - 1],
"low_power_frame_step": 2 if frames > 4 else 1,
"sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
}
print(f"vfx {name}: {frames} frames of {size}x{size} -> {path}")
manifest_path = OUT_DIR / "vfx_manifest.json"
manifest_path.write_text(
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n", encoding="utf-8"
)
print(f"wrote {manifest_path}")
return 0
if __name__ == "__main__":
raise SystemExit(main())