Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

refactor(video): the body plans are named once, BIPED, QUADRUPED and LEGLESS unpacked from body_plan.PLANS, and video-set's Lite walk sentence and the single-play anatomy sentences look them up by those names

Soohong Kim20369cd17242
diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.py
index 5ab9dca..969a4cb 100644
--- a/sprite_gen/video/batch.py
+++ b/sprite_gen/video/batch.py
@@ -552,7 +552,7 @@ def _lite_text(state: str, direction: str, model: str | None, *, built_in: bool,
if body_mod.biped(body_plan):
calm, head = LITE_WALK_TEXT, LITE_HEAD_TEXT
else:
- calm = LITE_WALK_TEXT_LEGLESS if any(b.plan == "legless" for b in body_plan or []) else LITE_WALK_TEXT_LEGGED
+ calm = LITE_WALK_TEXT_LEGLESS if any(b.plan == body_mod.LEGLESS for b in body_plan or []) else LITE_WALK_TEXT_LEGGED
head = LITE_HEAD_TEXT_ANY_BODY
text = f" {calm}" if built_in else ""
if direction in head:
diff --git a/sprite_gen/video/body_plan.py b/sprite_gen/video/body_plan.py
index 87fd8e9..5898434 100644
--- a/sprite_gen/video/body_plan.py
+++ b/sprite_gen/video/body_plan.py
@@ -32,24 +32,24 @@ from __future__ import annotations
from dataclasses import dataclass
-PLANS = ("biped", "quadruped", "legless")
+BIPED, QUADRUPED, LEGLESS = PLANS = ("biped", "quadruped", "legless")
SPEC_FORM = "'<biped|quadruped|legless>' for the character, or '<figure>=<plan>' per figure in a scene, e.g. 'the horse=quadruped'"
# What each figure of a scene stands on, after its name (`text`).
SCENE_TEXT = {
- "biped": "on two legs",
- "quadruped": "on all four legs, never rising onto its hind legs",
- "legless": "without legs, never growing any",
+ BIPED: "on two legs",
+ QUADRUPED: "on all four legs, never rising onto its hind legs",
+ LEGLESS: "without legs, never growing any",
}
# One figure, after the motion sentence (`text`). A biped says nothing: the measured sentences are its own.
ONE_TEXT = {
- "quadruped": "It stays on all four legs, as in the image, and never rises onto its hind legs.",
- "legless": "It has no legs, as in the image, and never grows legs or feet.",
+ QUADRUPED: "It stays on all four legs, as in the image, and never rises onto its hind legs.",
+ LEGLESS: "It has no legs, as in the image, and never grows legs or feet.",
}
# One figure, at the end of the view sentence a still is drawn with (`still_text`): the still may be drawn
# from words alone, so it says what the body stands on rather than "as in the image".
STILL_ONE_TEXT = {
- "quadruped": "standing on all four legs, not rearing onto its hind legs",
- "legless": "resting on its base without legs, never growing any",
+ QUADRUPED: "standing on all four legs, not rearing onto its hind legs",
+ LEGLESS: "resting on its base without legs, never growing any",
}
@@ -82,12 +82,12 @@ def parse_all(specs: list[str] | None) -> list[Body]:
def biped(bodies: list[Body] | None) -> bool:
"""Whether every figure stands on two legs (no body named is a biped): the measured sentences apply."""
- return all(b.plan == "biped" for b in bodies or [])
+ return all(b.plan == BIPED for b in bodies or [])
def legless(bodies: list[Body] | None) -> bool:
"""Whether a body is named and none of its figures has legs."""
- return bool(bodies) and all(b.plan == "legless" for b in bodies or [])
+ return bool(bodies) and all(b.plan == LEGLESS for b in bodies or [])
def scene(bodies: list[Body] | None) -> bool:
@@ -96,7 +96,7 @@ def scene(bodies: list[Body] | None) -> bool:
def text(bodies: list[Body] | None) -> str:
"""What the subject stands on, said after the motion sentence; "" for no body or one biped."""
- if not bodies or (not scene(bodies) and bodies[0].plan == "biped"):
+ if not bodies or (not scene(bodies) and bodies[0].plan == BIPED):
return ""
if not scene(bodies):
return ONE_TEXT[bodies[0].plan]
@@ -107,7 +107,7 @@ def text(bodies: list[Body] | None) -> str:
def still_text(bodies: list[Body] | None) -> str:
"""What the subject stands on, at the end of a still's view sentence (lower case, no full stop); "" for
no body or one biped."""
- if not bodies or (not scene(bodies) and bodies[0].plan == "biped"):
+ if not bodies or (not scene(bodies) and bodies[0].plan == BIPED):
return ""
if not scene(bodies):
return STILL_ONE_TEXT[bodies[0].plan]
diff --git a/sprite_gen/video/nonloop.py b/sprite_gen/video/nonloop.py
index 8d089f1..c2e824d 100644
--- a/sprite_gen/video/nonloop.py
+++ b/sprite_gen/video/nonloop.py
@@ -8,6 +8,7 @@ from typing import Any, Callable
from PIL import Image
from sprite_gen._deps import np
+from sprite_gen.video.body_plan import LEGLESS, QUADRUPED
# Cuts played once: `once` ends held on its terminal pose, `lifetime` on an empty frame, `once-return` back on its
# first pose (a clip pinned to end on its first frame, kept whole, `loop.once_return_cycle`).
@@ -32,10 +33,10 @@ MOTION_TEXT = {'death': 'collapses directly onto the ground, settles into a comp
'returning to the starting form.'}
STATES = frozenset(MOTION_TEXT)
COMMON_TEXT = 'Each action is executed exactly once without looping or returning to the initial state, holding the final pose completely motionless for the final 0.4 seconds, keeping the full body and any props entirely inside the frame under a fixed camera against a flat pure chroma background with no shadows, particles, visual effects, or smears, while preserving the original art style and permitting changes to character design and proportions solely for the transform action.'
-ANATOMY_TEXT = {'quadruped': 'Preserve quadruped anatomical structure without requiring an upright or standing stance, '
+ANATOMY_TEXT = {QUADRUPED: 'Preserve quadruped anatomical structure without requiring an upright or standing stance, '
'allowing natural weight transfer, crouching, and full ground collapse during death or '
'falls without requiring all four limbs to touch the ground on every frame.',
- 'legless': 'Preserve continuous limbless anatomy without forcing an upright orientation, allowing '
+ LEGLESS: 'Preserve continuous limbless anatomy without forcing an upright orientation, allowing '
'undulating, coiled, or fully flattened ground configurations during death or falls without '
'introducing limbs.'}
CYCLIC_STATES = frozenset({"idle", "walk", "run", "talk", "blink", "breathe"})