Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
docs: ui-kit 2:3 sheet with fills, slot, badge, dots and joystick; fills fit their frame's content area; game-pack fill entries; CHANGELOG
Soohong Kim13fd0a35703a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ee4c14a..4546e64 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,7 +10,8 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the- **New: `game-pack` request and manifest version 2 with `images`, `tiles` and `ui`.** Single images (props) are atlas frames with an anchor and an optional footprint (`"base"` measures where the image meets the ground); tiles are their own PNG and WebP files with their stored and on-screen sizes; `ui.kit` reads a `ui-kit` report into nine-slice entries (frame, size, stretch, insets, padding) and `ui.icons` adds fixed icons. Every number is in pixels of the stored image. A version 1 request is packed byte for byte as before, and a version 1 request naming the new sections is refused ([game-pack](docs/game-pack.md#version-2-images-tiles-and-ui)).- **New: `slice-sheet --scale sheet` keeps the sizes a sheet was drawn at, and `--fit contain` keeps every cut whole.** The default gives each cell's main subject the target height on its own, so the props of one sheet came out the same height, and lets the canvas cut whatever that scale puts past its edge, so a subject wider than the canvas lost its sides. `--scale sheet` takes one factor for the whole sheet (the tallest main subject reaches `--target-height`), so a prop drawn twice as tall stays twice as tall. `--fit contain` lowers the factor until the whole cut fits the canvas, with the main subject still centred on its base; with `--scale sheet` the sheet takes the smallest factor any cell fits at. Every cell of a sheet keeps one canvas size, so a game pack that gives the cells one `display` height keeps their sizes too ([sheet-slicing](docs/sheet-slicing.md#props-and-icons-sheet-scale-and-contain-fit)).- **New: `slice-sheet` writes `<prefix>slice-sheet.json`.** It names the scale and fit, the sheet's factor and where it came from, and per cell the factor, the main subject's size on the sheet and on the canvas, the cut's box on the canvas, the `anchor` (the centre of the main subject's base, ready for a game pack's `images[].anchor`) and `clipped_px`, the pixels the canvas cut ([report](docs/sheet-slicing.md#report)). A run also prints a line for each cell the canvas cut. The PNGs of a default run are unchanged byte for byte; a sheet with an empty cell now fails before any cell is written, where it used to write the cells before it.-- **Tests** — `tests/background/test_tile_xy.py` (an exact doubly periodic crop, a join that stays visible on one axis names that axis, the cyclic seam), `tests/frames/test_alpha_floor.py` (a haze ring cleared, thin strokes and their anti-aliased edges kept), `tests/frames/test_ui_kit.py` (a synthetic sheet on the layout: insets to the pixel over corner ornaments, a long flourish, a bar's end gem and cap; badge padding inside its ring; a packed kit at four scales keeps ornament fringes out of the stretched middle; a report in, beside, below or above `--out-dir` names the PNGs from its own directory and packs the same bytes), `tests/frames/test_slice_sheet_transparent.py`, `tests/compose/test_game_pack_v2.py` (the manifest field by field, refusals, and a version 1 manifest and page pixels frozen from 2.44.0), `tests/compose/test_game_pack_audio.py` (a version 1 pack with sound keeps its file list, manifest bytes and page pixels from 2.44.0; a version 2 pack with sound adds only its tile files) the `--layout-guide ui-kit` cases in `tests/gen/test_layout_guide.py`, and `tests/frames/test_slice_sheet_scale.py` (synthetic sheets: drawn heights kept within a pixel with `--scale sheet`, after the alpha cleanup too; a 2:1 subject whole on a square canvas with `--fit contain` while the default still cuts it and says so; one factor every cut fits; sliced cells packed as game-pack `images` keep one size and stand on the reported anchor; refusals).+- **New: a 2:3 UI kit sheet holds the whole kit: bar fills, an item slot, a counter plate, on and off dots and a joystick.** `gen --layout-guide ui-kit --aspect-ratio 2:3` draws the square layout's seven frames at the same places and, in a band below them, `hp_bar_fill` and `xp_bar_fill` (`x`), `slot` and `badge` (`xy`), `pip_on`, `pip_off`, `joystick_base` and `joystick_knob` (`none`, so round parts keep their proportions; the guide draws them as circles, and a cut with filled corners, a round part drawn on a square plate, makes the report `needs-review`). `ui-kit` picks the layout from the sheet's shape, so a square sheet is cut, measured and packed exactly as before. Padding is measured only for elements that hold content; fills, dots and joystick parts get `0`. Each fill's report entry has `inside`: its bar frame, that frame's content rectangle and the factor that makes the fill as tall as it, and the report is `needs-review` when the fill's ends would overflow it. `game-pack` (still version 2) stores each fill at exactly its frame's content rectangle, ends kept and middle columns repeated or dropped, with `inside` in its entry, and refuses a fill whose frame is missing or whose ends do not fit ([ui-kit](docs/ui-kit.md#fills), [game-pack](docs/game-pack.md#version-2-manifest)).+- **Tests** — `tests/background/test_tile_xy.py` (an exact doubly periodic crop, a join that stays visible on one axis names that axis, the cyclic seam), `tests/frames/test_alpha_floor.py` (a haze ring cleared, thin strokes and their anti-aliased edges kept), `tests/frames/test_ui_kit.py` (a synthetic sheet on the layout: insets to the pixel over corner ornaments, a long flourish, a bar's end gem and cap; badge padding inside its ring; a packed kit at four scales keeps ornament fringes out of the stretched middle; a report in, beside, below or above `--out-dir` names the PNGs from its own directory and packs the same bytes), `tests/frames/test_slice_sheet_transparent.py`, `tests/compose/test_game_pack_v2.py` (the manifest field by field, refusals, and a version 1 manifest and page pixels frozen from 2.44.0), `tests/compose/test_game_pack_audio.py` (a version 1 pack with sound keeps its file list, manifest bytes and page pixels from 2.44.0; a version 2 pack with sound adds only its tile files) the `--layout-guide ui-kit` cases in `tests/gen/test_layout_guide.py` (square and 2:3, any other ratio refused), the 2:3 sheet in `tests/frames/test_ui_kit.py` (every element cut from a synthetic sheet; fills fit their frame's content area in the report and, packed at three scales, to the pixel with their ends unchanged; dots and joystick parts never stretch and one drawn on a square plate is flagged; slot and plate insets to the pixel; a square sheet's report, element pixels and packs frozen from before the 2:3 sheet) and the fill cases in `tests/compose/test_game_pack_v2.py`, and `tests/frames/test_slice_sheet_scale.py` (synthetic sheets: drawn heights kept within a pixel with `--scale sheet`, after the alpha cleanup too; a 2:1 subject whole on a square canvas with `--fit contain` while the default still cuts it and says so; one factor every cut fits; sliced cells packed as game-pack `images` keep one size and stand on the reported anchor; refusals).- Bump audio processing recipe to version 4, measure BS.1770-4 loudness over normalized PCM frames and gated blocks, support a peak-limited loudness goal, normalize loudnorm-unanalysable short clips via limiter passes instead of refusing them, encode AAC using `-aac_coder fast`, record `normalization.pcm_lufs` and `pcm_true_peak_dbtp` required to load version 4 bundles, keep recipe version 3 bundles loadable in game packs by their own rule (target loudness, decoded files re-measured with loudnorm), reject recipe version 1-2 bundles, and reject recipe version 1-3 output directories in `sprite-gen sound` while reusing cached provider audio.- Bump audio processing recipe to version 3, require `ffprobe` on `PATH`, export M4A with `-movie_timescale 48000`, and validate AAC stream duration with `ffprobe`.diff --git a/SKILL.md b/SKILL.mdindex 5f1e992..d76c577 100644--- a/SKILL.md+++ b/SKILL.md@@ -120,7 +120,7 @@ hold the arms still, and check the loop with `handed-check --state walk`.| Engine exports | `export-aseprite`, `export-pngs` | [engine-export](docs/engine-export.md) || Background recipe or repeating tile | existing `gen` / `cutout`, then optional `background-tile` | [asset-tools](docs/asset-tools.md#background-recipe) || Ground tile that repeats both ways | `gen` (opaque), then `background-tile --axis xy` | [asset-tools](docs/asset-tools.md#both-axes-a-ground-tile) |-| Game UI kit: panel, buttons, card, HP/XP bar frames, timer badge as nine-slice elements | `gen --transparent --aspect-ratio 1:1 --layout-guide ui-kit`, then `ui-kit` | [ui-kit](docs/ui-kit.md) |+| Game UI kit: panel, buttons, card, HP/XP bar frames and fills, timer badge, item slot, counter plate, on/off dots, joystick base and knob as sliced elements | `gen --transparent --aspect-ratio 2:3 --layout-guide ui-kit` (`1:1`: the seven frames alone), then `ui-kit` | [ui-kit](docs/ui-kit.md) || Props or icons on a transparent sheet | `slice-sheet --chroma-key none --alpha-floor 64`, props with `--scale sheet --fit contain`, icons with `--fit contain` | [sheet-slicing](docs/sheet-slicing.md#props-and-icons-sheet-scale-and-contain-fit) || Painted props, a ground tile and a UI kit in a game pack | `game-pack` request version 2 (`images`, `tiles`, `ui`) | [game-pack](docs/game-pack.md#version-2-images-tiles-and-ui) || Standalone projected shadow | `shadow` | [asset-tools](docs/asset-tools.md#projected-shadows) |diff --git a/docs/README.md b/docs/README.mdindex 75cf12e..14ebe49 100644--- a/docs/README.md+++ b/docs/README.md@@ -119,7 +119,7 @@ grouping is derived from `sprite_gen/_modules.py`, the one taxonomy table.|---|---|| [directional-anchor-workflow.md](directional-anchor-workflow.md) | Directional / 45° rows: base → direction anchors → rows, the left-right gate || [sheet-slicing.md](sheet-slicing.md) | Multi-figure grid sheets to per-cell standing cuts; the `cutout` routes |-| [ui-kit.md](ui-kit.md) | The UI kit layout guide, splitting a transparent UI kit sheet into nine-slice elements with measured insets and padding, and the shared alpha haze cleanup |+| [ui-kit.md](ui-kit.md) | The UI kit layout guide (square for the frames, 2:3 for the whole kit), splitting a transparent UI kit sheet into nine-slice elements with measured insets and padding, fills fitted to their bar frames, and the shared alpha haze cleanup |## QAdiff --git a/docs/game-pack.md b/docs/game-pack.mdindex d40c453..ebdfdd5 100644--- a/docs/game-pack.md+++ b/docs/game-pack.md@@ -197,7 +197,7 @@ Version 2 adds three sections for painted scene art: single images such as props* `images[]`: one PNG each (a static image or a one-frame descriptor; more frames are refused). `display` takes exactly one of `width` or `height` (no `body_height`), and `resample` works as for assets. `anchor` is `[x, y]` in source pixels and defaults to the bottom centre of the image. `footprint` is optional: an explicit `{x, y, w, h}` rectangle in source pixels, or `"base"` for the measured base described below.* Props cut from one sheet by [`slice-sheet`](sheet-slicing.md#props-and-icons-sheet-scale-and-contain-fit) share one canvas size, so giving every cell of the sheet the same `display` height keeps the sizes the sheet gave them (`--scale sheet`). The [slice-sheet report](sheet-slicing.md#report) states each cell's `anchor`, the centre of its main subject's base, in the PNG's own pixels: pass it as the entry's `anchor` as it is.* `tiles[]`: one PNG each, ideally a seamless tile from [`background-tile --axis xy`](asset-tools.md#repeating-tiles). `display` takes exactly one of `width` or `height`: the size of one tile on screen. The tile's pixels are never resampled: the pack stores the source pixels and states both sizes.-* `ui.kit`: the JSON report a [`ui-kit`](ui-kit.md) run wrote. Every element it lists becomes a nine-slice entry, with the element PNGs it names (paths relative to the report). `ui.scale` (default `1`, positive) resizes every kit element by the same factor, so the kit stays one consistent set.+* `ui.kit`: the JSON report a [`ui-kit`](ui-kit.md) run wrote. Every element it lists becomes a nine-slice entry, with the element PNGs it names (paths relative to the report). `ui.scale` (default `1`, positive) resizes every kit element by the same factor, so the kit stays one consistent set; a [fill](ui-kit.md#fills) instead takes its size from its frame's content area, below.* `ui.icons[]`: fixed images such as upgrade or weapon icons, with `id`, `source` and `display` as for `images` (no anchor or footprint).* The `"base"` footprint is measured on the source image: take the bounding box of pixels with alpha at least 128, keep its lowest fifth (rounded up, at least one row), and the footprint is the bounding box of the pixels with alpha at least 128 inside that band. It is where a prop meets the ground in a top-down or three-quarter view. It is a measurement, not a collision shape the art guarantees.@@ -240,6 +240,14 @@ Version 2 adds three sections for painted scene art: single images such as props"stretch": "x","insets": { "left": 66, "right": 30, "top": 0, "bottom": 0 },"padding": { "left": 70, "right": 34, "top": 18, "bottom": 18 }+ },+ "hp_bar_fill": {+ "frame": "ui/hp_bar_fill",+ "size": { "w": 200, "h": 20 },+ "stretch": "x",+ "insets": { "left": 6, "right": 6, "top": 0, "bottom": 0 },+ "padding": { "left": 0, "right": 0, "top": 0, "bottom": 0 },+ "inside": { "element": "hp_bar_frame", "rect": { "x": 70, "y": 18, "w": 200, "h": 20 } }}},"icons": {@@ -258,11 +266,12 @@ What each field means, with no reading left to the consumer:* `images[*].size` is the stored frame size. `anchor` is `[x, y]` from the frame's top-left corner (a fraction where the scaled point falls between pixels, as for animation anchors), and the atlas frame's `pivot` is the same point normalised. `footprint` is `{x, y, w, h}` from the frame's top-left corner, or `null` when the request declared none. A source footprint is scaled outward to whole pixels (left and top rounded down, right and bottom rounded up) and kept inside the frame.* `tiles[*].size` is the stored PNG size. `display_size` is the on-screen size of one tile: draw the repeating texture with a tile scale of `display_size.w / size.w` horizontally and `display_size.h / size.h` vertically.* `ui.nine_slice[*].size` is the stored frame size. `stretch` says how the element may be resized: `"xy"` both ways (a nine-slice), `"x"` in width only (a three-slice whose height stays `size.h`; `top` and `bottom` are `0`), `"none"` not at all (draw it at `size`; every inset is `0`). `insets` are the widths of the fixed border slices: in Phaser, `scene.add.nineslice(x, y, texture, frame, width, height, insets.left, insets.right, insets.top, insets.bottom)`. The stretched middle lies between the insets, and every corner ornament the [`ui-kit`](ui-kit.md) run found lies inside them. When the pack resizes the kit by `ui.scale`, each inset is the report's inset scaled and rounded up, or, where it is larger, the inset the same [measurement](ui-kit.md#insets) finds on the resized pixels: resampling spreads an ornament's edge a little, and that fringe stays in the fixed slice too. A scale so small that the insets leave no stretchable middle, or the padding no content area, is refused.-* `padding` places the element's content: the inner area where a panel's text, a card's contents, a badge's digits or a bar's fill goes. For an element drawn at width `W` and height `H` (its stored size or any size its `stretch` allows), the content rectangle is `x = padding.left`, `y = padding.top`, `w = W - padding.left - padding.right`, `h = H - padding.top - padding.bottom`, from the element's top-left corner. For `hp_bar_frame` and `xp_bar_frame` this is the track: fill it from its left edge to show a fraction. Paddings are scaled with `ui.scale` and rounded up, so the content area only shrinks.+* `padding` places the element's content: the inner area where a panel's text, a card's contents, a badge's digits or a bar's fill goes. For an element drawn at width `W` and height `H` (its stored size or any size its `stretch` allows), the content rectangle is `x = padding.left`, `y = padding.top`, `w = W - padding.left - padding.right`, `h = H - padding.top - padding.bottom`, from the element's top-left corner. For `hp_bar_frame` and `xp_bar_frame` this is the track: fill it from its left edge to show a fraction, with the kit's `hp_bar_fill` and `xp_bar_fill` when it has them (`inside`, below). Paddings are scaled with `ui.scale` and rounded up, so the content area only shrinks.+* `inside` is on a fill alone (`hp_bar_fill`, `xp_bar_fill`): `element` is the frame it goes in, and `rect` that frame's content rectangle, from the frame's top-left corner in the frame's stored pixels (its `padding` applied to its `size`). The fill is stored at exactly that rectangle's size: resized by the one factor that makes it as tall as the rectangle (its ends keep their shape; each inset is the report's inset times that factor, rounded up, or the [measured](ui-kit.md#insets) inset of the resized pixels where that is larger), then drawn as wide as the rectangle with its end slices kept and its middle columns repeated or dropped. So a full bar is the fill drawn at its `size` at `rect.x`, `rect.y` in the frame, and it covers the content rectangle to the pixel; a fraction `f` is the fill drawn as a three-slice `f × size.w` wide from there (narrower than its two ends, `insets.left + insets.right`, a three-slice cannot shrink: show the fill's left part instead). When the frame is drawn wider than its stored size, the content rectangle grows with it: draw the fill as wide as the new rectangle allows. `ui.scale` reaches a fill only through its frame. A fill whose frame is not in the report (or is itself a fill), a fill that does not stretch `"x"`, and a fill whose two ends, so resized, are as wide as the rectangle are refused. The pack reads only `inside.element` from the report and works the rectangle out again from the frame it packed.* `ui.icons[*].size` is the stored frame size; icons are drawn as they are.* The atlas frames of images, UI elements and icons have `trimmed: false`, `rotated: false` and the same one-pixel extrusion as animation frames. UI element and icon frames have the pivot `{x: 0.5, y: 0.5}`.-The UI kit element names are fixed by the [`ui-kit` layout](ui-kit.md#layout): `panel`, `button`, `button_pressed`, `card`, `hp_bar_frame`, `xp_bar_frame` and `timer_badge`. Their `stretch` is part of the layout: the four frames and buttons are `"xy"`, the two bar frames `"x"`, the timer badge `"none"`.+The UI kit element names are fixed by the [`ui-kit` layout](ui-kit.md#layout): `panel`, `button`, `button_pressed`, `card`, `hp_bar_frame`, `xp_bar_frame` and `timer_badge` from a square sheet, and from a 2:3 sheet those seven and `hp_bar_fill`, `xp_bar_fill`, `slot`, `badge`, `pip_on`, `pip_off`, `joystick_base` and `joystick_knob`. Their `stretch` is part of the layout: the frames, buttons, slot and badge are `"xy"`; the two bar frames and the two fills `"x"`; the timer badge, the pips and the joystick base and knob `"none"`. The fills, the pips and the joystick parts hold no content, so their padding is `0`. These names are additive: the manifest stays version 2, and a kit from a square sheet packs to the same manifest and the same atlas pixels as before.## Audio Assets and Playbackdiff --git a/docs/gen.md b/docs/gen.mdindex f54bb3a..75b3557 100644--- a/docs/gen.md+++ b/docs/gen.md@@ -486,11 +486,14 @@ for `--aspect-ratio` (square without one) and the report records the cell it usestill the caller's own.`--layout-guide ui-kit` attaches the UI kit layout instead: one box per element of a game-UI kit (panel, button, pressed button, card frame, two bar frames, timer badge), and a-paragraph naming what to draw in each box, with straight edges between corner ornaments-and empty centres. [`ui-kit`](ui-kit.md) cuts the sheet along the same boxes. It is square-only (`--aspect-ratio 1:1`, or none); `extra.layout_guide` is then `{"kind": "ui-kit",-"width", "height", "boxes"}`.+UI kit, and a paragraph naming what to draw in each box, with straight edges between+corner ornaments and empty centres. [`ui-kit`](ui-kit.md) cuts the sheet along the same+boxes. The ratio chooses the layout: `--aspect-ratio 1:1` (or none) draws the square+layout's seven frames (panel, button, pressed button, card frame, two bar frames, timer+badge); `--aspect-ratio 2:3` draws the whole kit, those seven at the same places and, below+them, the two bar fills, an item slot, a counter plate, a lit and an unlit dot and a+joystick base and knob. Any other ratio is refused. `extra.layout_guide` is then+`{"kind": "ui-kit", "width", "height", "boxes"}`.The guide is an attached image, so it changes the call: openai sends it to`/images/edits` and bills it as image input, grok sends it as a reference, anddiff --git a/docs/ui-kit.md b/docs/ui-kit.mdindex 57d6fcd..81d88ff 100644--- a/docs/ui-kit.md+++ b/docs/ui-kit.md@@ -1,33 +1,45 @@# `ui-kit` — one painted sheet to nine-slice UI elements-> Owns: The UI kit layout guide, splitting a transparent UI kit sheet into elements, nine-slice insets and content padding · Index: [docs/README.md](README.md)+> Owns: The UI kit layout guide, splitting a transparent UI kit sheet into elements, nine-slice insets, content padding and fills · Index: [docs/README.md](README.md)-A game UI kit is one transparent image with every frame on it: a panel, a button and its pressed state, a card frame, two bar frames and a timer badge. `gen --layout-guide ui-kit` asks the image model to draw each element in a fixed box. `ui-kit` cuts the sheet along those boxes, measures where each element may stretch, and writes one PNG per element with a JSON report. [`game-pack`](game-pack.md#version-2-images-tiles-and-ui) reads that report.+A game UI kit is one transparent image with every part of a game's menus and HUD on it: a panel, a button and its pressed state, a card frame, two bar frames and a timer badge, and on the taller sheet the two bars' fills, an item slot, a counter plate, a lit and an unlit dot, and a touch joystick's base and knob. `gen --layout-guide ui-kit` asks the image model to draw each element in a fixed box. `ui-kit` cuts the sheet along those boxes, measures where each element may stretch, and writes one PNG per element with a JSON report. [`game-pack`](game-pack.md#version-2-images-tiles-and-ui) reads that report.## Generate the sheet```bash-sprite-gen gen --provider openai --quality high --transparent --aspect-ratio 1:1 \+sprite-gen gen --provider openai --quality high --transparent --aspect-ratio 2:3 \--layout-guide ui-kit --prompt-file uikit-prompt.txt --out uikit.png```-`--layout-guide ui-kit` draws the [layout](#layout) as a guide image, attaches it after any `--ref`, and adds a sentence to the prompt that names every box and what to draw in it. The caller's prompt describes the style: material, palette, trim, mood. It does not need to list the elements or their positions. The guide asks for straight, even edges between corner ornaments, empty element centres, no text and empty space between elements, because only those can be nine-sliced. The sheet must be square; `--aspect-ratio 1:1` gives that on every provider that takes a ratio.+`--layout-guide ui-kit` draws the [layout](#layout) as a guide image, attaches it after any `--ref`, and adds a paragraph to the prompt that names every box and what to draw in it. The caller's prompt describes the style: material, palette, trim, mood. It does not need to list the elements or their positions. The guide asks for straight, even edges between corner ornaments, empty element centres, bare fills of one colour along their length, dots and joystick parts as circles with nothing square around them, no text and empty space between elements, because only those can be sliced.-## Layout--The guide and the splitter read one table (`sprite_gen.frames.ui_kit.LAYOUT`). Boxes are in pixels of a 1024 × 1024 sheet and scale with the sheet's size; neighbouring boxes are 48 px apart.+The sheet's shape chooses the layout. `--aspect-ratio 2:3` draws the whole kit; `--aspect-ratio 1:1` (or no ratio) draws the seven frames alone, the layout every square sheet has had. Every provider that takes a ratio takes both.-| Element | Box (x, y, w, h) | Stretch | Content |-|---|---|---|---|-| `panel` | 48, 48, 576, 400 | `xy` | a large frame with an empty centre |-| `button` | 672, 48, 304, 128 | `xy` | a wide button, normal state |-| `button_pressed` | 672, 224, 304, 128 | `xy` | the same button, pressed |-| `card` | 704, 400, 272, 576 | `xy` | a tall card frame with an empty centre |-| `hp_bar_frame` | 48, 496, 608, 112 | `x` | an empty horizontal health bar frame |-| `xp_bar_frame` | 48, 656, 608, 112 | `x` | an empty horizontal experience bar frame |-| `timer_badge` | 48, 816, 160, 160 | `none` | a small round badge with an empty centre |+## Layout-`stretch` is how a game may resize the element: `xy` as a nine-slice, `x` in width only (a three-slice), `none` not at all. It belongs to the layout, not to the measurement.+The guide and the splitter read one table (`sprite_gen.frames.ui_kit.LAYOUT`). Boxes are in pixels of a sheet 1024 px wide: 1024 × 1024 for the square sheet, 1024 × 1536 for the 2:3 sheet. They scale with the sheet's size, and neighbouring boxes are 48 px apart. The square sheet holds the first seven elements. The 2:3 sheet holds the same seven at the same places and the other eight in a band below them. `ui-kit` reads a sheet's shape to know which: square or 2:3, each within 1 %; any other shape is refused. So a square sheet drawn before the 2:3 sheet existed is cut, measured and packed exactly as before.++| Element | Sheet | Box (x, y, w, h) | Stretch | Padding | What to draw |+|---|---|---|---|---|---|+| `panel` | both | 48, 48, 576, 400 | `xy` | measured | a large frame with an empty centre |+| `button` | both | 672, 48, 304, 128 | `xy` | measured | a wide button, normal state |+| `button_pressed` | both | 672, 224, 304, 128 | `xy` | measured | the same button, pressed |+| `card` | both | 704, 400, 272, 576 | `xy` | measured | a tall card frame with an empty centre |+| `hp_bar_frame` | both | 48, 496, 608, 112 | `x` | measured | an empty horizontal health bar frame |+| `xp_bar_frame` | both | 48, 656, 608, 112 | `x` | measured | an empty horizontal experience bar frame |+| `timer_badge` | both | 48, 816, 160, 160 | `none` | measured | a small round badge with an empty centre |+| `hp_bar_fill` | 2:3 | 48, 1024, 608, 64 | `x` | `0` | the health bar's fill alone, a bare strip of colour ([fills](#fills)) |+| `xp_bar_fill` | 2:3 | 48, 1136, 608, 64 | `x` | `0` | the experience bar's fill alone, the same kind of strip |+| `slot` | 2:3 | 48, 1248, 192, 192 | `xy` | measured | a square item slot frame with an empty centre |+| `badge` | 2:3 | 288, 1248, 176, 112 | `xy` | measured | a small counter plate with an empty centre |+| `pip_on` | 2:3 | 512, 1248, 96, 96 (circle) | `none` | `0` | a small round indicator dot, lit |+| `pip_off` | 2:3 | 512, 1392, 96, 96 (circle) | `none` | `0` | the same dot unlit |+| `joystick_base` | 2:3 | 704, 1024, 272, 272 (circle) | `none` | `0` | a round touch joystick base |+| `joystick_knob` | 2:3 | 768, 1344, 144, 144 (circle) | `none` | `0` | the joystick's round knob |++`stretch` is how a game may resize the element: `xy` as a nine-slice, `x` in width only (a three-slice), `none` not at all. Round parts (`timer_badge`, the pips, the joystick base and knob) are `none`, so they are only ever drawn at their own proportions. `stretch` belongs to the layout, not to the measurement; so does whether padding is measured: an element that holds no content (a fill, a pip, a joystick part) gets a padding of `0` on every side. The two pips have boxes of one size, so a row of dots can swap one for the other in place.++The guide draws the pips and the joystick base and knob as the circles their boxes hold, and asks for them as circles with nothing square around them. A model may still draw a round part on a square plate that fills its box, so the splitter checks: when more than a quarter of the area outside the ellipse a round part's cut holds (the ellipse touching the cut's four sides) is opaque, at alpha 128 or more, the report is `needs-review` with `<element>: its corners are filled`. Regenerate the sheet; a plate behind a dot or a joystick shows as a square in the game. The timer badge keeps the square sheet's box and is not checked, so square sheets cut as they always have.## Split the sheet@@ -35,7 +47,7 @@ The guide and the splitter read one table (`sprite_gen.frames.ui_kit.LAYOUT`). Bsprite-gen ui-kit --sheet uikit.png --out-dir ui/```-The command writes `ui/<element>.png` for every element of the layout and `ui/ui-kit.json`. It never changes the sheet and refuses an output directory that holds the sheet. Options:+The command writes `ui/<element>.png` for every element the sheet's layout holds and `ui/ui-kit.json`. It never changes the sheet and refuses an output directory that holds the sheet. Options:* `--alpha-floor N` (default `64`, `0` turns it off) and `--alpha-edge N` (default `2`): the [alpha cleanup](#alpha-cleanup) that runs before anything is cut.* `--report PATH`: write the JSON report elsewhere (default `<out-dir>/ui-kit.json`); it must end in `.json`. Each element's `file` in it then leads from the report's directory to the PNG in `--out-dir`.@@ -60,7 +72,28 @@ So every column with an ornament, a cap, a border line or their anti-aliased edg## Padding-Padding places the content (text, a card's contents, a bar's fill, a badge's digits). On the element's middle five rows, take the per-column median. The interior is the run of columns around the centre that continues while each step to the next column changes no channel by more than 16 and every column stays within 96 of the centre (the median of the central 5 × 5 pixels): a smooth gradient on a button face stays interior, a border's sharp edge ends it. The same on the middle five columns gives the interior rows. A pixel counts as interior when every channel lies within 16 of the range those two runs cover; when a corner of the rectangle is not interior (a round badge, an ornament reaching inward), the rectangle shrinks evenly toward the centre until all four corners are. Each padding is the distance from an element edge to that rectangle, plus 2 px. A content area narrower or shorter than a quarter of its element makes the report `needs-review`: the centre was probably not empty.+Padding places the content (text, a card's contents, a bar's fill, a badge's digits, a slot's icon). It is measured for the elements the [layout](#layout) marks `measured`; the others get `0` on every side. On the element's middle five rows, take the per-column median. The interior is the run of columns around the centre that continues while each step to the next column changes no channel by more than 16 and every column stays within 96 of the centre (the median of the central 5 × 5 pixels): a smooth gradient on a button face stays interior, a border's sharp edge ends it. The same on the middle five columns gives the interior rows. A pixel counts as interior when every channel lies within 16 of the range those two runs cover; when a corner of the rectangle is not interior (a round badge, an ornament reaching inward), the rectangle shrinks evenly toward the centre until all four corners are. Each padding is the distance from an element edge to that rectangle, plus 2 px. A content area narrower or shorter than a quarter of its element makes the report `needs-review`: the centre was probably not empty.++## Fills++`hp_bar_fill` and `xp_bar_fill` go inside `hp_bar_frame` and `xp_bar_frame`: in the frame's content rectangle, the rectangle its [padding](#padding) leaves (`x = padding.left`, `y = padding.top`, `w = size.w - padding.left - padding.right`, `h = size.h - padding.top - padding.bottom`, in the frame's pixels). The image model draws a fill at its own size, so its report entry says how it fits:++```json+"hp_bar_fill": {+ "...": "...",+ "stretch": "x",+ "insets": { "left": 14, "right": 14, "top": 0, "bottom": 0 },+ "padding": { "left": 0, "right": 0, "top": 0, "bottom": 0 },+ "inside": { "element": "hp_bar_frame", "rect": { "x": 46, "y": 30, "w": 520, "h": 52 }, "scale": 0.928571 }+}+```++* `inside.element` is the frame and `inside.rect` its content rectangle.+* `inside.scale` (`rect.h / size.h`, rounded to six decimals) resizes the fill, ends and insets with it, to exactly the rectangle's height. Never resize a fill by a second factor for its width: it is a three-slice, so its ends keep their shape and its middle stretches.+* Drawn `rect.w` wide at `rect.x`, `rect.y` from the frame's top-left corner, a full fill covers the content rectangle to the pixel and never reaches past it. A fraction `f` of a bar is the fill drawn `f × rect.w` wide from the rectangle's left edge. Below its two ends' width (`insets.left + insets.right`, times `scale`), a three-slice cannot shrink: show its left part instead.+* When the two ends, scaled, are at least as wide as the content rectangle, a full bar would overflow it, and the report is `needs-review` naming the fill and its frame.++[`game-pack`](game-pack.md#version-2-manifest) does this sizing for you: it stores each fill at its frame's content rectangle.## Alpha cleanup@@ -111,7 +144,7 @@ Solid pixels and edge pixels are never changed, so a stroke stays whole as long}```-`box` is the layout box scaled to this sheet and `rect` the element's bounding box, both in sheet pixels. `file` is the element PNG's path from the report's own directory, with `/` separators: `panel.png` when the report is in `--out-dir` (the default), `../elements/panel.png` for `--out-dir elements --report reports/kit.json`. A reader joins it to the report's directory, as [`game-pack`](game-pack.md#version-2-request) does, so a report and its elements move together. `size`, `insets` and `padding` are in pixels of the element PNG. Elements appear in layout order. `status` is `needs-review` when any `review_reasons` apply; the PNGs are written either way, so the elements can be inspected.+`box` is the layout box scaled to this sheet and `rect` the element's bounding box, both in sheet pixels. A fill also has [`inside`](#fills); no other element has it. `file` is the element PNG's path from the report's own directory, with `/` separators: `panel.png` when the report is in `--out-dir` (the default), `../elements/panel.png` for `--out-dir elements --report reports/kit.json`. A reader joins it to the report's directory, as [`game-pack`](game-pack.md#version-2-request) does, so a report and its elements move together. `size`, `insets` and `padding` are in pixels of the element PNG. Elements appear in layout order. `status` is `needs-review` when any `review_reasons` apply; the PNGs are written either way, so the elements can be inspected.Like every measurement here, `pass` means the numbers found nothing to flag. Look at the elements stretched to a few sizes before shipping them.@@ -120,5 +153,7 @@ Like every measurement here, `pass` means the numbers found nothing to flag. Loo* `sprite_gen.frames.ui_kit.split_ui_kit(image, *, alpha_floor=64, alpha_edge=2) -> (elements, report)`: the elements as images by name, and the report as written to its default place, `<out-dir>/ui-kit.json` (each `file` is `<element>.png`), without `sheet`.* `sprite_gen.frames.ui_kit.report_file(report, png) -> str` and `element_path(report, file) -> Path`: the `file` a report at `report` gives an element PNG, and the PNG a report's `file` names.* `sprite_gen.frames.ui_kit.measure_insets(image, stretch) -> (insets, notes)` and `measure_padding(image) -> (padding, notes)`: the measures above on one element image, with the review notes they raise.-* `sprite_gen.frames.ui_kit.boxes(size)`, `draw_guide(path, size)` and `guide_text()`: the layout, the guide image and its prompt paragraph.+* `sprite_gen.frames.ui_kit.content_rect(record)` and `fit_inside(fill, frame, name) -> (inside, note)`: an element record's content rectangle, and a fill's `inside` with its review note.+* `sprite_gen.frames.ui_kit.sheet_layout(size) -> (reference_size, slots)`: the layout a sheet of that size holds; a `ValueError` for a shape that is neither square nor 2:3.+* `sprite_gen.frames.ui_kit.boxes(size)`, `draw_guide(path, size)` and `guide_text(size)`: the boxes a sheet of that size holds, the guide image and its prompt paragraph (`size` defaults to the square sheet).* `sprite_gen.frames.alpha_floor.clear_haze(image, *, floor=64, edge=2) -> (image, report)`.