Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.
refactor(chroma): the tables kept by key colour, gen.chroma.KEY_BACKGROUND_TEXT, gen.logo.KEY_COLOUR_WORDS and a scene report's key_like_pixels, take cutout.GREEN and MAGENTA for their keys, so the names cannot move without them
Soohong Kim049e1deab4e1
diff --git a/sprite_gen/gen/chroma.py b/sprite_gen/gen/chroma.pyindex 3425fa2..fdb18cf 100644--- a/sprite_gen/gen/chroma.py+++ b/sprite_gen/gen/chroma.py@@ -24,7 +24,7 @@ from PIL import Imagefrom sprite_gen._deps import npfrom sprite_gen.frames import extract as extract_mod-from sprite_gen.frames.cutout import KEY_TARGETS, MAGENTA+from sprite_gen.frames.cutout import GREEN, KEY_TARGETS, MAGENTAfrom sprite_gen.frames.extract import remove_chroma_background_ycbcrfrom sprite_gen.spec.runio import atomic_save_image@@ -35,9 +35,9 @@ KEYS: dict[str, dict[str, tuple[int, int, int]]] = {name: {"target": rgb} for na# reference for a clip (`video.batch.walk_start_prompt`) and a ref run whose transparency# `auto` planned as a chroma key (`gen.generate_image`) both end their prompt with it.KEY_BACKGROUND_TEXT = {- "green": ("The entire background is one perfectly flat, uniform pure green chroma-key fill (#00FF00) with no gradient, "+ GREEN: ("The entire background is one perfectly flat, uniform pure green chroma-key fill (#00FF00) with no gradient, ""no texture, no shadow and no ground line."),- "magenta": ("The entire background is one perfectly flat, uniform pure magenta chroma-key fill (#FF00FF) with no "+ MAGENTA: ("The entire background is one perfectly flat, uniform pure magenta chroma-key fill (#FF00FF) with no ""gradient, no texture, no shadow and no ground line."),}diff --git a/sprite_gen/gen/logo.py b/sprite_gen/gen/logo.pyindex e923eac..81c3fb8 100644--- a/sprite_gen/gen/logo.py+++ b/sprite_gen/gen/logo.py@@ -74,8 +74,8 @@ REFUSED = ("mismatch", "no-text") # the verdicts a text check refuses on# and lavender are not): a colour the style or scene names is looked for in the title's box at a smaller share# (`logo_matte.choose_key`).KEY_COLOUR_WORDS = {- "green": ("green", "mint", "lime", "emerald", "jade", "chartreuse"),- "magenta": ("magenta", "fuchsia", "pink", "purple", "violet", "plum", "orchid"),+ GREEN: ("green", "mint", "lime", "emerald", "jade", "chartreuse"),+ MAGENTA: ("magenta", "fuchsia", "pink", "purple", "violet", "plum", "orchid"),}# How many readings one text check may take: a reading that would refuse is read again, up to this many, and one# that spells the text passes (docs/logo.md, the text check).diff --git a/sprite_gen/scene/inspect_scene.py b/sprite_gen/scene/inspect_scene.pyindex e5d68c7..04c69c8 100644--- a/sprite_gen/scene/inspect_scene.py+++ b/sprite_gen/scene/inspect_scene.py@@ -26,6 +26,7 @@ def _mae(a, b) -> float:def inspect_scene(scene: Scene, *, renderer=None, frame_dir=None):+ from sprite_gen.frames.cutout import GREEN, MAGENTAfrom sprite_gen.scene.render import Rendererrenderer = renderer or Renderer(scene)first = previous = None@@ -101,7 +102,7 @@ def inspect_scene(scene: Scene, *, renderer=None, frame_dir=None):warnings.append(f"layers entirely outside the viewport in some frames: {', '.join(offscreen)}")return {"kind": "sprite-gen-scene-inspection", "version": 1, "frames": scene.frame_count,"source_fingerprints": scene.source_fingerprints, "status": "needs-review" if warnings else "measured",- "loop": loop, "key_like_pixels": {"green": green, "magenta": magenta}, "clipping": clipped,+ "loop": loop, "key_like_pixels": {GREEN: green, MAGENTA: magenta}, "clipping": clipped,"sources": sources, "tile_joins": tiles, "warnings": warnings, "visual_review_required": True}diff --git a/tests/frames/test_cutout.py b/tests/frames/test_cutout.pyindex 0dbad8c..0330f25 100644--- a/tests/frames/test_cutout.py+++ b/tests/frames/test_cutout.py@@ -9,6 +9,7 @@ in it, but the corner flood-fill keys by position so it must survive.from __future__ import annotations+import astimport jsonfrom pathlib import Path@@ -149,6 +150,18 @@ def test_the_tables_kept_by_key_name_name_the_keys() -> None:assert set(chroma.KEY_BACKGROUND_TEXT) == set(logo.KEY_COLOUR_WORDS) == set(cutout_mod.KEY_TARGETS)+def test_no_table_keys_a_key_colour_by_its_spelling() -> None:+ """A table of the two key colours keyed on their text stays behind when `cutout.MAGENTA` or `GREEN` moves, and a+ reader that looks a key up in it by the name fails. (`WHITE_CHECK_COLORS` is the three primaries, not the keys.)"""+ from sprite_gen.frames import cutout as cutout_mod++ root = Path(cli.__file__).parent+ spelt = [f"{path.relative_to(root).as_posix()}:{node.lineno}" for path in sorted(root.rglob("*.py"))+ for node in ast.walk(ast.parse(path.read_text(encoding="utf-8"))) if isinstance(node, ast.Dict)+ if set(cutout_mod.KEY_TARGETS) <= {key.value for key in node.keys if isinstance(key, ast.Constant)}]+ assert spelt == []++def test_every_video_key_flag_reads_its_declaration() -> None:"""video-canvas and video-set take `canvas.KEYS`, video-prompt the keys its redraw sentence is written for."""from sprite_gen.video import canvas, clip_prompt