Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
feat(ui-kit): the 2:3 guide draws the dots and the joystick parts as circles and asks for bare fills; a round part cut with filled corners makes the report needs-review
Soohong Kimb34c5ea4ffb4
diff --git a/sprite_gen/frames/ui_kit.py b/sprite_gen/frames/ui_kit.pyindex 530d10f..f2ad22f 100644--- a/sprite_gen/frames/ui_kit.py+++ b/sprite_gen/frames/ui_kit.py@@ -35,6 +35,9 @@ MARGIN = 2# the centre, so a smooth gradient face is interior and a border's sharp edge ends it.PADDING_STEP = 16PADDING_SPAN = 96+# A round part whose cut is more than this opaque outside the ellipse its bounding box holds was drawn on a+# square plate, not as a circle (docs/ui-kit.md "Layout").+ROUND_CORNER_FILL = 0.25GUIDE_BACKGROUND = (0xF6, 0xF6, 0xF6)GUIDE_BOX = (0x2F, 0x80, 0xED)STRETCHES = ("xy", "x", "none")@@ -54,6 +57,8 @@ class Slot:content: bool = True# A fill: the bar frame whose content area it fills (docs/ui-kit.md "Fills").inside: str | None = None+ # A round part: the guide draws a circle in its box, and a cut with filled corners is flagged.+ round: bool = FalseLAYOUT = (@@ -73,22 +78,23 @@ LAYOUT = ("a small round badge with an empty centre"),# The band below the square, on the 2:3 sheet only.Slot("hp_bar_fill", (48, 1024, 608, 64), "x", "the long thin box at the top left of the band",- "the health bar's fill, a solid horizontal strip", content=False, inside="hp_bar_frame"),+ "the health bar's fill alone, a bare strip of colour with no frame, rim or end pieces around it",+ content=False, inside="hp_bar_frame"),Slot("xp_bar_fill", (48, 1136, 608, 64), "x", "the long thin box below it",- "the experience bar's fill, the same kind of strip in its own colour", content=False,+ "the experience bar's fill alone, the same kind of bare strip in its own colour", content=False,inside="xp_bar_frame"),Slot("slot", (48, 1248, 192, 192), "xy", "the square box below them at the left","a square item slot frame with an empty centre"),Slot("badge", (288, 1248, 176, 112), "xy", "the small wide box to its right","a small counter plate with an empty centre"),- Slot("pip_on", (512, 1248, 96, 96), "none", "the small square box to the right of that",- "a small round indicator dot, lit", content=False),- Slot("pip_off", (512, 1392, 96, 96), "none", "the small square box below it",- "the same dot unlit", content=False),- Slot("joystick_base", (704, 1024, 272, 272), "none", "the large square box at the right of the band",- "a round touch joystick base", content=False),- Slot("joystick_knob", (768, 1344, 144, 144), "none", "the smaller square box below it",- "the joystick's round knob", content=False),+ Slot("pip_on", (512, 1248, 96, 96), "none", "the small circle to the right of that",+ "a small round indicator dot, lit", content=False, round=True),+ Slot("pip_off", (512, 1392, 96, 96), "none", "the small circle below it",+ "the same dot unlit", content=False, round=True),+ Slot("joystick_base", (704, 1024, 272, 272), "none", "the large circle at the right of the band",+ "a round touch joystick base", content=False, round=True),+ Slot("joystick_knob", (768, 1344, 144, 144), "none", "the smaller circle below it",+ "the joystick's round knob", content=False, round=True),)FRAME_COUNT = 7# Sheet shape -> (the size the layout's boxes are given at, the slots it holds). The 2:3 sheet keeps the@@ -143,18 +149,21 @@ def guide_text(size: tuple[int, int] = (REFERENCE, REFERENCE)) -> str:frames, band = slots[:FRAME_COUNT], slots[FRAME_COUNT:]return ("Layout: the last attached image is a layout guide, not part of the artwork. It shows "- f"{len(slots)} blue boxes on a grey sheet: {len(frames)} in the square at the top and {len(band)} in the "- "band below it. Draw exactly one user interface element inside each box, filling most of its box without "- "touching the box's edges, and leave everything outside the boxes empty and transparent. In the square "+ f"{len(slots)} blue boxes and circles on a grey sheet: {len(frames)} in the square at the top and "+ f"{len(band)} in the band below it. Draw exactly one user interface element inside each box and circle, "+ "filling most of it without touching its edges, and leave everything outside them empty and transparent. "+ "In the square "f"at the top: {_places(frames)}. In the band below it: {_places(band)}. Every frame, button, bar, fill, ""slot and plate has straight, even edges between its corners, so it can be stretched along them: put ""ornaments only in the corners, and on the bars and the fills only at their two ends. Each fill is one ""solid strip with no frame of its own, the same colour all along its length (it may shade from its top ""edge to its bottom edge), with no marks, segments or highlights along it. Leave the centre of every ""frame, button, bar frame, slot and plate empty: no text, no letters, no numbers, no icons and no fill "- "inside the bar frames. The two dots, the joystick base and the knob are round and seen straight from "- "the front; the two dots are the same size. Do not reproduce the layout guide itself: no boxes, guide "- "lines, guide colors or the guide's grey background may appear in the output."+ "inside the bar frames. The two dots, the joystick base and the knob are circles drawn on the guide's "+ "circles and seen straight from the front, with nothing square around them: no plate, tile or backing, "+ "so the corners around each circle stay empty and transparent; the two dots are the same size. Do not "+ "reproduce the layout guide itself: no boxes, circles, guide lines, guide colors or the guide's grey "+ "background may appear in the output.")@@ -165,8 +174,9 @@ def draw_guide(path: Path, size: tuple[int, int] = (REFERENCE, REFERENCE)) -> didraw = ImageDraw.Draw(image)line = max(2, round(3 * width / REFERENCE))scaled = boxes(size)- for x, y, w, h in scaled.values():- draw.rectangle((x, y, x + w - 1, y + h - 1), outline=GUIDE_BOX, width=line)+ shapes = {slot.name: draw.ellipse if slot.round else draw.rectangle for slot in LAYOUT}+ for name, (x, y, w, h) in scaled.items():+ shapes[name]((x, y, x + w - 1, y + h - 1), outline=GUIDE_BOX, width=line)Path(path).parent.mkdir(parents=True, exist_ok=True)image.save(path)return {"kind": "ui-kit", "width": width, "height": height,@@ -268,6 +278,17 @@ def measure_padding(image: Image.Image) -> tuple[dict[str, int], list[str]]:return padding, notes+def measure_round(image: Image.Image) -> list[str]:+ """Review notes for a round part: its cut's corners, outside the ellipse its bounding box holds, are empty."""+ alpha = np.asarray(image.convert("RGBA"))[..., 3]+ height, width = alpha.shape+ yy, xx = np.indices((height, width))+ outside = ((xx + 0.5 - width / 2) / (width / 2)) ** 2 + ((yy + 0.5 - height / 2) / (height / 2)) ** 2 > 1+ if outside.any() and (alpha[outside] >= 128).mean() > ROUND_CORNER_FILL:+ return ["its corners are filled: it was drawn on a square plate or backing, not as a circle; regenerate it"]+ return []++def _runs(mask: Any) -> list[tuple[int, int, int]]:runs = []for y in np.flatnonzero(mask.any(axis=1)):@@ -362,7 +383,8 @@ def split_ui_kit(image: Image.Image, *, alpha_floor: int = 64,element = Image.fromarray(cut)insets, inset_notes = measure_insets(element, slot.stretch)padding, padding_notes = measure_padding(element) if slot.content else (dict.fromkeys(SIDES, 0), [])- reasons += [f"{slot.name}: {note}" for note in inset_notes + padding_notes]+ round_notes = measure_round(element) if slot.round else []+ reasons += [f"{slot.name}: {note}" for note in inset_notes + padding_notes + round_notes]elements[slot.name] = elementrecords[slot.name] = {"file": f"{slot.name}.png",