Files
splatter-tennis/assets/_zsheet.py
T
wuwiandClaude Opus 5 e1ce2486c0 SERVE UP was dropping you into gore whatever you picked
THE MENU BUG, and it explains three reports at once. cStart's handler was
`addEventListener('click', start)` — and addEventListener hands a listener the
MouseEvent as its first argument, so `start(modeId = pickedMode)` never saw its
default: modeId was an EVENT OBJECT. `G.classic = modeId === 'classic'` was
therefore always false and the zombie branch never fired. Picking CLASSIC or
ZOMBIE TENNIS on the setup screen did nothing at all; SERVE UP always started
the gore mode. A default parameter only applies to `undefined`, and a click
handler always passes something. `() => start()`.

That is also why "in normal tennis i dont see the ball circles and the serve
hint bar": there was no normal tennis to be in. Both are drawn unconditionally
in render() and the tennis struggle hints are already mode-gated correctly.
Verified through the real menu after the fix: CLASSIC gives mode=tennis with
no bodies on court, ZOMBIE gives match=true against the SHAMBLER in its own
body. Every other bare handler in the codebase takes no parameters — checked.

THE MOP BOY had the same class of bug one layer down. sendBoy was called and
mopWorthIt() refused: it tests `d.z >= COURT.netZ - 2`, the NEAR half, because
in the gore mode everything dies on the near court. A match's blood is all on
the FAR side, where the body stands and bleeds through four wound stages, so
the boy could never qualify. The near-side bias stays; the match is the
exception.

DANIEL was being dropped, not missing. Two causes, both mine: the asides were
queued at 0.7-1.5 s and matchPoint fires the score call at 0.4 s with a clip
over a second long — voice() drops anything that would start while he is still
talking (one man, one microphone). And asideEvery is 55 s, a whole match game.
Delays moved past the score call; matchAsideEvery is 15 s, which fits a mode
whose events are a limb and your blood rather than a wave of bodies.

THE FALL: quicker down, longer on the floor (0.09/0.11/2.0/0.30). And it was
genuinely SHRUNKEN — the generator draws fall rows smaller than standing rows
(the brute's buckle came back 190 px against a 224 px stance) and _zsheet's one
global scale preserved that faithfully, so the body shrank the moment it
started to fall. A fall row is anchored on its own buckle now, which must draw
at standing height. All seven generated families re-cut: 224/153/98/181 against
the hand-made racket family's 224/154/85/179 — the convergence is the check.

THE FLICK: 0.42 made going out impossible, which fixed the 8-in-10 bug and
overshot it ("too easy. i must be able to play out"). 0.62 puts risk back where
it belongs — ~15% out at quality 0, 5% at 0.75, and never on a perfect flick.
The test now asserts that shape: bounded, monotonically falling, zero at 1.

59 tests green.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 20:07:02 +02:00

138 lines
6.9 KiB
Python

# _zsheet.py — ONE generated multi-row sheet -> a whole zombie family of sprites.
#
# python3 assets/_zsheet.py assets/_refcheck/brute_all3.png br --out assets/_refcheck/sprites
# python3 assets/_zsheet.py assets/_refcheck/brute_all3.png br --install
#
# WHY THIS EXISTS. _regen.py generates a family as nine separate sheets, and nine separate rolls is
# nine chances for the character to drift — which is exactly what it did, all day. Asking for the
# WHOLE family in one image fixes that by construction: one roll, one character, one light, one
# palette. What was missing was the way back down — a generated sheet is 9 rows of figures and
# _fine.py cuts a single row. This is that step, and nothing else.
#
# TWO THINGS ARE GLOBAL, and both were bugs when they were not:
# SCALE _fine.py anchors one scale per sheet, so nine bands would each be scaled to their own
# tallest figure — the serve strike would come out the same height as the idle stance and
# every pose would pop, because the game sizes a sprite off its own PNG height. The scale
# is taken ONCE, from the standing frame of the play row, and every band uses it.
# PALETTE taken once from the largest figure in the whole sheet, so a wound row cannot quantise
# itself onto a slightly different set of colours than the healthy row it follows.
import os, sys
import numpy as np
from PIL import Image
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from _fine import key, block_size, frames, split_piece # the proven keyer and column cutter
HERE = os.path.dirname(os.path.abspath(__file__))
TARGET_H = 224
MIN_BAND = 40
# The family layout, exactly config.famFrames' order. The wound rows carry no separate stance —
# the shuffle doubles as one — which is why they are 3 and not 4.
def layout(k):
P = ['bounce', 'toss', 'serve']
F = ['fall1', 'fall2', 'fall3', 'rise']
rows = [[f'z_{k}1', f'z_{k}2', f'z_{k}3', f'z_{k}4'],
[f'z_{k}{s}' for s in P],
[f'z_{k}{s}' for s in F]]
for st in (1, 2):
rows += [[f'z_{k}w{st}', f'z_{k}w{st}b', f'z_{k}w{st}s'],
[f'z_{k}w{st}{s}' for s in P],
[f'z_{k}w{st}{s}' for s in F]]
return rows
def bands(a):
"""Row bands = runs of rows that contain ink. Rows are what a grid has and _fine.py refuses;
here they are the point, so they are found first and each band is handed over as its own row."""
rows = (a[..., 3] > 0).any(1)
out, s = [], None
for y, v in enumerate(rows):
if v and s is None: s = y
elif not v and s is not None:
if y - s >= MIN_BAND: out.append((s, y))
s = None
if s is not None and len(rows) - s >= MIN_BAND: out.append((s, len(rows)))
return out
def cut(sheet, fam, outdir):
want = layout(fam)
src = Image.open(sheet).convert('RGB')
a = key(src)
# THE ENCLOSED MAGENTA IS THE RACKET, AND HERE IT IS MEANT TO GO. _fine.py repaints magenta that
# is trapped inside a figure as pale grey, because the generator used to fill string beds with
# the backdrop colour BY ACCIDENT and keying them left men holding an empty hoop. This sheet is
# the opposite case: the prompt asks for the string bed to be exactly the background magenta so
# it cuts to transparency, and it obeyed. So every magenta pixel goes, connected to the border
# or not. That is safe only because nothing else on the figure is magenta — check a new sheet.
n = np.array(src).astype(int)
lo = np.minimum(n[..., 0], n[..., 2])
a[(lo > 140) & (n[..., 1] < lo - 55), 3] = 0
b = block_size(a)
bs = bands(a)
if len(bs) != len(want):
sys.exit(f'ERROR: found {len(bs)} row bands, expected {len(want)}')
crops = []
for (y0, y1), row in zip(bs, want):
band = a[y0:y1]
spans = frames(band, [], len(row))
if len(spans) != len(row):
sys.exit(f'ERROR: row {row[0]}: found {len(spans)} figures, expected {len(row)}')
for x0, x1 in spans:
sub = band[:, x0:x1]
ys = np.where((sub[..., 3] > 0).any(1))[0]
xs = np.where((sub[..., 3] > 0).any(0))[0]
c = sub[ys.min():ys.max() + 1, xs.min():xs.max() + 1]
if split_piece(c):
sys.exit(f'ERROR: a frame in row {row[0]} holds two stacked bodies')
crops.append(c)
flat = [n for row in want for n in row]
# ONE scale, off the play row's standing frame; ONE palette, off the biggest figure anywhere.
k = TARGET_H / (crops[0].shape[0] / b)
big = max(crops, key=lambda c: (c[..., 3] > 0).sum())
px = big[big[..., 3] > 200][:, :3]
pal = np.unique((px // 8) * 8, axis=0)
# A FALL ROW IS ANCHORED ON ITS OWN BUCKLE, not on the sheet. The generator draws the fall rows
# noticeably smaller than the standing rows — the brute's buckle came back at 190 px against a
# 224 px stance — and one global scale preserves that faithfully, so the body SHRANK the moment
# it started to fall ("the fall animation seems shrunken"). The first frame of a fall is a body
# still on its feet, so it must draw at standing height; the other three are scaled by the same
# factor, which keeps the collapse's own proportions intact. A row that was already right (the
# racket family's, at 224/224) gets a factor of 1.0 and is untouched — which is the check that
# this rule is the right one rather than a fudge for one bad sheet.
mult = [1.0] * len(crops)
i = 0
for row in want:
if row[0].endswith('fall1') and crops[i].shape[0]:
k_row = crops[0].shape[0] / crops[i].shape[0]
for j in range(i, i + len(row)):
mult[j] = k_row
i += len(row)
os.makedirs(outdir, exist_ok=True)
for c, name, m in zip(crops, flat, mult):
h, w = c.shape[:2]
snap = Image.fromarray(c, 'RGBA').resize((max(1, round(w / b)), max(1, round(h / b))), Image.BOX)
im = snap.resize((max(1, round(snap.width * k * m)), max(1, round(snap.height * k * m))), Image.BOX)
arr = np.array(im).astype(int)
solid = arr[..., 3] > 110
f = arr[..., :3].reshape(-1, 3)
arr[..., :3] = pal[((f[:, None, :] - pal[None, :, :]) ** 2).sum(2).argmin(1)].reshape(arr.shape[0], arr.shape[1], 3)
arr[..., 3] = np.where(solid, 255, 0)
Image.fromarray(arr.astype('uint8'), 'RGBA').save(os.path.join(outdir, name + '.png'))
print(f'{len(flat)} frames, art block {b}, scale {k:.3f}, palette {len(pal)} colours -> {outdir}')
for (y0, y1), row in zip(bs, want):
hs = [Image.open(os.path.join(outdir, n + '.png')).height for n in row]
print(f' {row[0]:14s} {len(row)} frames heights {hs}')
if __name__ == '__main__':
args = [a for a in sys.argv[1:] if not a.startswith('--')]
out = HERE if '--install' in sys.argv else None
if '--out' in sys.argv: out = sys.argv[sys.argv.index('--out') + 1]
cut(args[0], args[1], out or os.path.join(HERE, '_refcheck', 'sprites'))