Skip to content

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

fix(prompt): a caller's walk names --character in every view

Soohong Kimd9e5287958f1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d3903ed..e5602ef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,7 +9,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
- **Fix: a facing correction's regeneration carried the facing sentence twice** (`--facing-fix regen`): the correction now replaces the sentence it corrects.
- **Fix: a key background is read however it is worded, and not when ruled out** (`chroma.named_key_background`). "A background of pure magenta" and "magenta-colored background" were not read, so the key line went on a second time. "No green screen" and "holding a green key" were read as asking for green, so a reference run got no key line and came back on a light ground. The name before or after "background" / "backdrop", "keyed on magenta" and "on a green key" are read now; a negation right before the key's name rules it out (`chroma.ruled_out_key_backgrounds`). A prompt that rules out the key `--chroma-key` chose is refused before the model runs.
- **Fix: `video --direction side` added its side-view hold after a clip prompt that already had it.** A `video-prompt` or `video-set` prompt is sent as it is, and one that faces the other way than `--facing` is refused before the facing inspection.
-- **A walk or run says "in place" and its view once.** The side and diagonal gait sentences ended "without moving across the screen" and the frame sentence said "does not move across the screen"; the gait sentences and holds no longer add it. A walk or run seen from the front, from behind or at a diagonal said its view in the gait sentence ("facing the viewer", "keeps the exact three-quarter back angle of the image") and again in the view sentence ("The character is seen from the front, facing the viewer directly."); its prompt now leaves the view sentence out (`batch.GAIT_SAYS_VIEW`). A side gait keeps the view sentence, and a caller's own side gait is held with "It stays in place as if on a treadmill." (its facing is the view sentence's). Other states are unchanged. A cached `video-set` clip made with the old wording is refused as before ("cached clip prompt differs"); pass `--force` to film it again.
+- **A walk or run says "in place" and its view once.** The side and diagonal gait sentences ended "without moving across the screen" and the frame sentence said "does not move across the screen"; the gait sentences and holds no longer add it. A walk or run seen from the front, from behind or at a diagonal said its view in the gait sentence ("facing the viewer", "keeps the exact three-quarter back angle of the image") and again in the view sentence ("The character is seen from the front, facing the viewer directly."); its prompt now leaves the view sentence out (`batch.GAIT_SAYS_VIEW`). With a caller's own motion paragraph (`--motion`), `--character` was named only on that view sentence; it is now named on the gait hold that says the view ("A small fox adventurer in a green cloak stays in place as if on a treadmill, without coming any closer, and keeps facing the viewer the whole time."), and a clip prompt that would leave the character out is an error. A side gait keeps the view sentence, and a caller's own side gait is held with "It stays in place as if on a treadmill." (its facing is the view sentence's). Other states are unchanged. A cached `video-set` clip made with the old wording is refused as before ("cached clip prompt differs"); pass `--force` to film it again.
- **The caller's own words are reported, not edited.** Text that turns the subject another way than `--facing` (or to a side in a front or back view), or puts a `--handed` item on its other side, is sent as written with a warning; text that repeats an option gets a note. `gen` prints them and records `extra.prompt_notes`; `video-prompt --json` lists conflicts in `warnings` and all of them in `notes`; `video-set` records `prompt_notes` per item.
- **Fix: a watch on the far wrist was in no frame of a side walk.** 2.22.0 said every item on the far side of a side view hidden, and never named it in the clip ("the wrist in front of the body stays bare"). A walking character's far arm comes forward of the body with every step, and what it wears shows then. An item on a far arm or leg (`handedness.limb` reads the body part) is now said to show wherever that limb is out in front of the body: in the still ("wherever the far arm reaches out in front of the body, clear of its outline, the black smartwatch shows whole on it; where the body covers that arm, it is hidden") and in a walk or run ("stays on the wrist that wears it in the image, on the arm on the far side of the body, and shows each time that arm swings forward; the arm nearer the viewer stays bare, exactly as in the image"). On the near arm the walk says the other arm stays bare "both where it shows behind the body and where it swings out in front of it". Both start "Both arms swing back and forth with each step, opposite to the legs.", and no sentence holds an arm still. A far part that does not swing (a pin on the far side of the head) and a state that does not step (idle, attack) keep the 2.22.0 sentences. [docs/video-pipeline.md](docs/video-pipeline.md#handedness--an-item-on-one-side).
- **A side view names the near part "nearer the viewer", not "in front of the body"** (still and clip sentences): in a mid-stride still the far arm is the one in front of the body, so "the wrist in front of the body stays bare" named the wrist with the watch.
diff --git a/docs/prompt-assembly.md b/docs/prompt-assembly.md
index ff5defb..7571bd8 100644
--- a/docs/prompt-assembly.md
+++ b/docs/prompt-assembly.md
@@ -43,7 +43,11 @@ sentence's ("does not move across the screen"); the side and diagonal gait sente
longer add "without moving across the screen". A walk or run seen from the front, from behind or at
a diagonal says its view in the gait sentence or hold ("facing the viewer", "keeps the exact
three-quarter back angle of the image"), so the view sentence is left out of its prompt
-(`batch.GAIT_SAYS_VIEW`); a side gait keeps the view sentence, which carries the facing.
+(`batch.GAIT_SAYS_VIEW`); a side gait keeps the view sentence, which carries the facing. With a
+caller's own motion paragraph, `--character` is named on the sentence that says the view: the view
+sentence, or where that is left out, the gait hold ("A small fox adventurer in a green cloak stays in
+place as if on a treadmill, without coming any closer, and keeps facing the viewer the whole time.").
+A clip prompt that would go out without the character is an error, not a prompt.
`video --direction side` holds the side view ("The subject stays in exact side view, facing left. No
turning around.") only for a prompt that does not say it already: a `video-prompt` or `video-set`
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 9cb5fce..f9987ac 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -153,8 +153,9 @@ the viewer and to the right … three-quarter front angle" for the front one). I
its first frame (`PINNED_GAIT_VIEWS`, `pins_last_frame`) with the return sentence, and cut as any
walk (`--anchor motion-auto`). The view is said once: a walk or run seen from the front, from behind
or at a diagonal says it in the gait sentence ("facing the viewer", "keeps the exact three-quarter
-back angle of the image"), so its prompt leaves the view sentence out (`GAIT_SAYS_VIEW`); a side gait
-keeps it ("The character is seen from the exact side, facing right."), and so does every other state,
+back angle of the image"), so its prompt leaves the view sentence out (`GAIT_SAYS_VIEW`) and, with
+`--motion`, names `--character` on the gait hold instead ("The knight stays in place as if on a
+treadmill …"); a side gait keeps it ("The character is seen from the exact side, facing right."), and so does every other state,
whose view sentence points at the image ("seen from a
three-quarter back angle, turned exactly as in the image"); a still drawn at a diagonal from another
picture takes `STILL_VIEW_TEXT` instead (`still_view_text`), which says the whole body and head turn
diff --git a/sprite_gen/video/batch.py b/sprite_gen/video/batch.py
index eab8502..9de2564 100644
--- a/sprite_gen/video/batch.py
+++ b/sprite_gen/video/batch.py
@@ -146,6 +146,11 @@ GAIT_HOLD_TEXT = {
# view's gait says only that it stays in place, so its view sentence stays and carries the facing.
GAIT_SAYS_VIEW = frozenset({"front", "back", "front_diagonal", "back_diagonal"})
VIEW_SENTENCE = " The character is {view}."
+# With a caller's own motion paragraph, `--character` is named on the engine sentence that says the view: the
+# view sentence, or where that is left out, the gait hold ("A small fox ... stays in place ..." for "It stays").
+# Every view that leaves its view sentence out has a gait hold to name it on.
+GAIT_HOLD_SUBJECT = "It "
+assert GAIT_SAYS_VIEW <= GAIT_HOLD_TEXT.keys() and all(text.startswith(GAIT_HOLD_SUBJECT) for text in GAIT_HOLD_TEXT.values())
MOTION_TEXT = {
# A side-view full body asked for "a subtle weight sway" and an evenly paced loop steps in place
# more often than not, so the feet are held and walking is named as what not to do.
@@ -333,15 +338,18 @@ def clip_prompt_parts(direction: str, state: str, character: str | None, facing:
if not motion:
raise SystemExit("video: motion description is empty")
head = "2D game sprite animation. The character {motion}"
- subject = character.strip().rstrip(".") if character else "The character"
+ subject = character.strip().rstrip(".") if character else None
parts = prompt_parts.Prompt(f"2D game sprite animation. {motion}", caller=f"{motion} {character or ''}", sep=" ")
if state in HOLD_TEXT:
parts.add("hold", HOLD_TEXT[state])
if state in GAIT_STATES and direction in GAIT_HOLD_TEXT:
- parts.add("gait-hold", GAIT_HOLD_TEXT[direction].format(facing=facing))
+ hold = GAIT_HOLD_TEXT[direction].format(facing=facing)
+ if says_view and subject: # the hold says the view: it names the character (`GAIT_HOLD_SUBJECT`)
+ hold = f"{subject} {hold[len(GAIT_HOLD_SUBJECT):]}"
+ parts.add("gait-hold", hold)
if state in REPEAT_TEXT:
parts.add("repeat", REPEAT_TEXT[state])
- frame = template[len(head):].replace(VIEW_SENTENCE, f" {subject} is {view}.", 1)
+ frame = template[len(head):].replace(VIEW_SENTENCE, f" {subject or 'The character'} is {view}.", 1)
parts.add("frame", frame.strip(), facing=turned or prompt_parts.NO_TURN)
else:
built_in = (VIEW_MOTION_TEXT[(state, direction)].format(facing=facing) if (state, direction) in VIEW_MOTION_TEXT
@@ -350,6 +358,8 @@ def clip_prompt_parts(direction: str, state: str, character: str | None, facing:
parts = prompt_parts.Prompt(text.replace("The character", character, 1) if character else text,
caller=character or "", sep=" ")
parts.note(facing=turned or prompt_parts.NO_TURN)
+ if character and character.strip().rstrip(".") not in parts.text:
+ raise AssertionError(f"video: the {state} {direction} clip prompt lost the character ({character!r})")
for topic, text in _lite_pieces(state, direction, model, built_in=motion is None):
parts.add(topic, text)
if handed:
diff --git a/tests/gen/test_prompt_assembly.py b/tests/gen/test_prompt_assembly.py
index 937a3ab..82ae614 100644
--- a/tests/gen/test_prompt_assembly.py
+++ b/tests/gen/test_prompt_assembly.py
@@ -3,7 +3,8 @@
A prompt is the caller's text plus the engine's pieces (`sprite_gen.gen.prompt_parts`). The table below
is every still, clip, start-still and correction prompt the options can make; each one is checked for a
-sentence said twice, for words that turn the subject both ways, and for more than one key background.
+sentence said twice, for words that turn the subject both ways, for more than one key background, and
+for anything asked for (the caller's text, `--character`, a handed item, the key line) that never reached it.
A new option is a new row in a table here, not a new test.
The checks are written here, apart from the engine's own (`prompt_parts`), so they do not agree with it
@@ -43,6 +44,8 @@ USER_TEXT = {
"says-item-side": {"text": f"{SUBJECT}, wearing a black smartwatch on its left wrist.", "item": "left"},
"says-other-item-side": {"text": f"{SUBJECT}, wearing a black smartwatch on its right wrist.", "item": "right"},
}
+# --character: words the motion paragraphs below never use, so a clip that names the character got them from here
+CHARACTER = "A small fox adventurer in a green cloak"
STATES = ("idle", "walk", "run", "jump", "attack", "cheer")
MODELS = {"pro": "grok-imagine-video-1.5", "lite": "grok-imagine-video-1.5-lite"}
# --motion: the built-in sentence, the caller's own, one that quotes an engine rule, one that walks the other way
@@ -84,9 +87,9 @@ def _clip_rows():
for (view, facing), handed, state, model, motion in itertools.product(_views(), HANDED, STATES, MODELS, MOTION):
if MOTION[motion]["text"] and state != "walk":
continue
- parts = batch.clip_prompt_parts(view, state, "The fox", facing=facing or "right",
+ parts = batch.clip_prompt_parts(view, state, CHARACTER, facing=facing or "right",
motion=MOTION[motion]["text"], model=MODELS[model], handed=_items(handed))
- row = {"user": None, "motion": motion, "facing": facing, "handed": handed, "state": state}
+ row = {"user": None, "motion": motion, "facing": facing, "handed": handed, "state": state, "character": CHARACTER}
yield f"clip/{view}@{facing}/{state}/{model}/{motion}/{handed}", parts, row
if view == "side": # handed on to `sprite-gen video --direction side`
yield (f"clip+video/{view}@{facing}/{state}/{model}/{motion}/{handed}",
@@ -96,11 +99,11 @@ def _clip_rows():
def _start_still_rows():
for view, key, handed in itertools.product(batch.WALK_START_TEXT, chroma.KEY_BACKGROUND_TEXT, HANDED):
text = batch.walk_start_prompt(view, key, _items(handed))
- row = {"user": None, "facing": None, "handed": handed}
+ row = {"user": None, "facing": None, "handed": handed, "key": key}
yield f"start-still/{view}/{key}/{handed}", prompt_parts.Prompt(text, caller=""), row
# handed back to `gen --ref --transparent --direction --handed`, as an agent reading `video-prompt` may
again = gen.still_prompt(text, view=view, handed=_items(handed), refs=True, key=key)
- yield f"start-still+gen/{view}/{key}/{handed}", again, row
+ yield f"start-still+gen/{view}/{key}/{handed}", again, {**row, "own": text}
ROWS = [*_still_rows(), *_clip_rows(), *_start_still_rows()]
@@ -197,6 +200,37 @@ def test_no_clip_calls_a_limb_bare_and_dressed_or_swings_an_arm_that_stands_stil
assert text.count("Both arms swing back and forth with each step") == 1
[email protected]("name,parts,row", ROWS, ids=[name for name, _, _ in ROWS])
+def test_every_part_asked_for_reaches_the_prompt(name, parts, row) -> None:
+ """What the caller wrote and what the options ask for is in the prompt, whatever the engine left out as said
+ twice. Since f899101 a front, back or diagonal walk with a caller's motion paragraph dropped its view sentence,
+ and with it the only place `--character` was said."""
+ text = " ".join(parts.text.split())
+ asked = [USER_TEXT[row["user"]]["text"]] if row["user"] else []
+ asked += [MOTION[row["motion"]]["text"]] if row.get("motion") and MOTION[row["motion"]]["text"] else []
+ asked += [row["character"]] if row.get("character") else []
+ asked += [row["own"]] if row.get("own") else []
+ for item in _items(row["handed"]) or []:
+ # the one item left unnamed on purpose: on the far side of a side view where nothing steps it into sight,
+ # since a clip prompt that names a hidden item draws it on the near arm (docs/video-pipeline.md)
+ hidden = (name.startswith("clip") and "/side@" in name and row["state"] not in batch.GAIT_STATES
+ and h.placement(item.side, "side", row["facing"])["depth"] == "far")
+ if hidden:
+ assert _ARTICLE.sub("", item.item) not in text, text
+ else:
+ asked.append(_ARTICLE.sub("", item.item))
+ for words in asked:
+ assert " ".join(words.split()) in text, (words, text)
+ if row.get("key"):
+ assert chroma.KEY_BACKGROUND_TEXT[row["key"]] in text, text
+ if name.startswith("still") and parts.piece("key-background") is not None:
+ named = USER_TEXT[row["user"]].get("key")
+ assert (chroma.KEY_BACKGROUND_TEXT["magenta"] in text) or named, text
+
+
+_ARTICLE = re.compile(r"^(?:the|a|an)\s+", re.IGNORECASE)
+
+
@pytest.mark.parametrize("name,parts,row", [r for r in ROWS if r[0].startswith("still")], ids=[r[0] for r in ROWS if r[0].startswith("still")])
def test_a_still_carries_the_key_line_unless_its_text_names_a_key(name, parts, row) -> None:
piece = parts.piece("key-background")
@@ -313,3 +347,12 @@ def test_gen_reports_what_the_callers_text_says_against_the_options(tmp_path, mo
assert '[gen] warning: the text says "facing left" and the engine\'s sentence says right' in err
quiet = gen.generate_image("fake", "a fox", tmp_path / "quiet.png", view="side", facing="right")
assert "prompt_notes" not in quiet.extra
+
+
+def test_video_prompt_names_the_character_in_every_view_of_a_callers_walk() -> None:
+ """f899101: a front, back or diagonal walk or run with --motion left its view sentence out, and with it
+ --character; the prompt went out without the character and no warning said so."""
+ for view, state in itertools.product(h.VIEWS, batch.GAIT_STATES):
+ record = clip_prompt.plan_prompt(direction=view, state=state, character=CHARACTER, facing="right",
+ motion=MOTION["own"]["text"])
+ assert record["prompt"].count(CHARACTER) == 1, record["prompt"]
diff --git a/tests/video/test_video_pipeline.py b/tests/video/test_video_pipeline.py
index 131e09c..58e0d1c 100644
--- a/tests/video/test_video_pipeline.py
+++ b/tests/video/test_video_pipeline.py
@@ -523,8 +523,11 @@ def test_a_callers_gait_is_held_in_place_and_facing_the_images_way() -> None:
for state in ("walk", "run"):
p = batch_mod.build_prompt(direction, state, "The knight", "left", motion=sneak)
hold = batch_mod.GAIT_HOLD_TEXT[direction].format(facing="left")
- # the side view's facing is its view sentence's; a front or back hold says the view itself
+ # the side view's facing is its view sentence's; a front or back hold says the view itself, and so
+ # names the character in place of "It"
view = f" The knight is {batch_mod.VIEW_TEXT[direction].format(facing='left')}." if direction == "side" else ""
+ if direction != "side":
+ hold = hold.replace("It ", "The knight ", 1)
assert p.startswith(f"2D game sprite animation. {sneak} {hold}{view} Stays centered in the frame")
assert batch_mod.MOTION_TEXT[state] not in p
assert p.count("move across the screen") + p.count("moving across the screen") == 1