104 lines
4.4 KiB
Python
104 lines
4.4 KiB
Python
"""Generator for drink-v5.bin and drink-hand-v5.png: 6 animated drinks (42 frames) for Assembler Casino."""
|
|
import json
|
|
import struct
|
|
from pathlib import Path
|
|
from PIL import Image
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SOURCE_DIR = ROOT / "assets/sprites/hall"
|
|
ANIM_DIR = ROOT / "assets/animations/hall"
|
|
BUILD_DIR = ROOT / "build/hall"
|
|
SOURCE_BIN = ANIM_DIR / "drink-v4.bin"
|
|
SPRITE_PNG = SOURCE_DIR / "drink-hand-v5.png"
|
|
OUTPUT_BIN = ANIM_DIR / "drink-v5.bin"
|
|
PREVIEW_PNG = BUILD_DIR / "drink-v5.bin.png"
|
|
|
|
def main():
|
|
ANIM_DIR.mkdir(parents=True, exist_ok=True)
|
|
BUILD_DIR.mkdir(parents=True, exist_ok=True)
|
|
SOURCE_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
data = SOURCE_BIN.read_bytes()
|
|
magic, w, h, nframes, plen = struct.unpack("<4sIIII", data[:20])
|
|
assert magic == b"ANM1"
|
|
frames = []
|
|
for i in range(nframes):
|
|
raw = data[20 + i*w*h*4 : 20 + (i+1)*w*h*4]
|
|
frames.append(Image.frombytes("RGBA", (w, h), raw, "raw", "BGRA"))
|
|
|
|
whisky = frames[0:7]
|
|
cocktail = frames[7:14]
|
|
water = frames[14:21]
|
|
|
|
def tint_liquid(frame_list, color_mode):
|
|
out = []
|
|
for f in frame_list:
|
|
img = f.copy()
|
|
px = img.load()
|
|
for y in range(h):
|
|
for x in range(w):
|
|
r, g, b, a = px[x, y]
|
|
if a < 25:
|
|
continue
|
|
if 55 <= x <= 225 and 45 <= y <= 215:
|
|
is_skin = (r > 130 and g > 75 and b > 45 and r > g and g > b and (r - g) > 22 and (g - b) < 75)
|
|
if not is_skin and (r > 35 or g > 35 or b > 35):
|
|
lum = (r * 299 + g * 587 + b * 114) // 1000
|
|
if color_mode == "cyan":
|
|
nr = min(255, int(lum * 0.12))
|
|
ng = min(255, int(lum * 0.85 + 50))
|
|
nb = min(255, int(lum * 1.15 + 75))
|
|
px[x, y] = (nr, ng, nb, a)
|
|
elif color_mode == "lime":
|
|
nr = min(255, int(lum * 0.3 + 20))
|
|
ng = min(255, int(lum * 1.2 + 55))
|
|
nb = min(255, int(lum * 0.2))
|
|
px[x, y] = (nr, ng, nb, a)
|
|
elif color_mode == "gold_emerald":
|
|
nr = min(255, int(lum * 0.88 + 45))
|
|
ng = min(255, int(lum * 1.08 + 50))
|
|
nb = min(255, int(lum * 0.22 + 10))
|
|
px[x, y] = (nr, ng, nb, a)
|
|
out.append(img)
|
|
return out
|
|
|
|
d0 = whisky # Double Bluff (Whisky)
|
|
d1 = cocktail # Cold Calc (Crimson Cocktail)
|
|
d2 = tint_liquid(whisky, "cyan") # Cyber Punch (Neon Cyan Energy)
|
|
d3 = tint_liquid(whisky, "lime") # Chameleon (Emerald Lime Shot)
|
|
d4 = tint_liquid(cocktail, "gold_emerald") # Lucky Clover (Gold-Emerald Sparkle)
|
|
d5 = water # Pure Ice Water
|
|
|
|
all_frames = d0 + d1 + d2 + d3 + d4 + d5
|
|
assert len(all_frames) == 42
|
|
|
|
# 1. Save master sprite sheet: assets/sprites/hall/drink-hand-v5.png (7 columns x 6 rows)
|
|
sheet_w = 7 * w
|
|
sheet_h = 6 * h
|
|
sheet = Image.new("RGBA", (sheet_w, sheet_h), (0, 0, 0, 0))
|
|
for idx, f in enumerate(all_frames):
|
|
row = idx // 7
|
|
col = idx % 7
|
|
sheet.paste(f, (col * w, row * h))
|
|
sheet.save(SPRITE_PNG)
|
|
print(f"Saved master sprite sheet: {SPRITE_PNG} ({sheet_w}x{sheet_h})")
|
|
|
|
# 2. Save binary pack: assets/animations/hall/drink-v5.bin (ANM1 BGRA)
|
|
payload = b"".join(f.tobytes("raw", "BGRA") for f in all_frames)
|
|
hdr = struct.pack("<4sIIII", b"ANM1", w, h, len(all_frames), len(payload))
|
|
OUTPUT_BIN.write_bytes(hdr + payload)
|
|
print(f"Wrote binary pack: {OUTPUT_BIN} ({len(all_frames)} frames)")
|
|
|
|
# 3. Save developer preview: build/hall/drink-v5.bin.png (4 columns on dark background)
|
|
cols = 4
|
|
rows = (len(all_frames) + cols - 1) // cols
|
|
preview = Image.new("RGBA", (cols * w, rows * h), (25, 29, 31, 255))
|
|
for idx, f in enumerate(all_frames):
|
|
cx = (idx % cols) * w
|
|
cy = (idx // cols) * h
|
|
preview.alpha_composite(f, (cx, cy))
|
|
preview.save(PREVIEW_PNG)
|
|
print(f"Saved developer preview: {PREVIEW_PNG} ({preview.width}x{preview.height})")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|