Files
windroost/p2_godot_sample/scripts/breathing_test.gd
T
wushenghua c4b5b98577 art: batch heroes H14-H24 via real AI GIF + respect AI frame timing
Continued full-art batch. Added heroes H14, H15(idle), H16-H21, H24 via
gpt-image-2.6-gif: 4-frame idle + 6-frame attack (real AI pose changes),
chroma-keyed and packed into runtime atlases, symlinked and Godot-imported.

Key improvement: gif_to_runtime.py now reads the AI GIF's own per-frame
duration (idle 300ms -> 3fps, attack 180ms -> 6fps) and writes that fps into
the runtime manifest with provenance — playback now follows the AI's rhythm
instead of an arbitrary fixed fps. breathing_test wait window widened to 70
renders to cover the slower AI-GIF timing. All gates pass; P2_CHECKS_PASS.

Batch robustness added earlier: 10s submit throttle (avoids upstream rate
limit), POST direct / GET proxy / CDN direct, cost controls (paid re-gen at
most once, download retries free, one hero failure doesn't abort batch).

Remaining: H22/H23 (submit failed, retryable), H09-H12/H01-H06 upgrade from
procedural micro-motion to real GIF, 9 single-frame R1 enemies, B02-B20.
prototype/ untracked.
2026-11-19 03:37:59 +08:00

123 lines
5.1 KiB
GDScript

extends SceneTree
## Idle-breathing evidence.
##
## Characters with a single atlas frame look static. A looping squash tween on
## the idle sprite makes them feel alive without any AI-generated frames.
## This test proves the tween runs, tracks state, and respects reduced motion.
const OUTPUT_PATH := "res://artifacts/breathing_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
# The real path configures BEFORE the node enters the tree (battle_hud.gd).
# Breathing must still start and animate once the node is live.
var unit := UnitView.new()
var ok: bool = unit.configure("H01", ["idle", "attack"], false)
_check(ok, "H01 idle should configure")
root.add_child(unit)
await process_frame
await process_frame
var art: Sprite2D = unit.get_node_or_null("Art") as Sprite2D
_check(art != null, "unit should have an Art sprite")
_check(unit.is_breathing(), "idle unit should start breathing")
var scale_start: float = art.scale.y if art != null else -1.0
for i in range(40):
await process_frame
var scale_end: float = art.scale.y if art != null else -1.0
_check(absf(scale_end - scale_start) > 0.001,
"idle sprite scale should change over time (%.4f -> %.4f)" % [scale_start, scale_end])
_record("idle", {"start": scale_start, "end": scale_end, "breathing": unit.is_breathing()})
# A non-idle state must stop breathing.
unit.set_state("attack")
_check(not unit.is_breathing(), "attack state should stop breathing")
_record("attack", {"breathing": unit.is_breathing()})
# Returning to idle resumes it.
unit.set_state("idle")
_check(unit.is_breathing(), "returning to idle should resume breathing")
_record("resume", {"breathing": unit.is_breathing()})
# Multi-frame animation path: the approved H01 idle AND the new H02 attack
# atlas each have 4 frames; the runtime must actually advance them (not just
# squash a single frame). This proves generated atlases are really played.
# Enemies all map to art EG01 (4-frame idle, runtime) and boss to B01.
# Prove the enemy idle atlas really advances too.
for spec in [{"id": "H01", "state": "idle"}, {"id": "H02", "state": "idle"}, {"id": "H02", "state": "attack"}, {"id": "H03", "state": "attack"}, {"id": "H04", "state": "attack"}, {"id": "H05", "state": "attack"}, {"id": "H06", "state": "attack"}, {"id": "H07", "state": "idle"}, {"id": "H07", "state": "attack"}, {"id": "EG01", "state": "idle"}, {"id": "B01", "state": "idle"}]:
var f4 := UnitView.new()
root.add_child(f4)
var ok4: bool = f4.configure(str(spec["id"]), [str(spec["state"])], false)
_check(ok4, "%s %s atlas should configure" % [spec["id"], spec["state"]])
# play_once keeps a non-looping attack on its last frame; use set_state
# so the 4-frame strip advances, and re-arm when it reaches the end.
# configure() already set the state; observe the strip advance. Both
# idle (loop) and attack (non-loop) pass through frames 0,1,2,3.
var seen: Dictionary = {}
# AI-GIF fps now comes from the GIF's own duration: idle can be as low
# as 3fps (~20 render frames per anim frame), attack ~6fps. Wait long
# enough (70 renders ≈ 1.1s) to observe >1 frame even at 3fps.
for i in range(70):
seen[f4.current_frame()] = true
await process_frame
_check(seen.size() > 1, "%s %s should advance atlas frames, saw %s" % [spec["id"], spec["state"], str(seen.keys())])
_record("multiframe_" + str(spec["id"]) + "_" + str(spec["state"]), {"distinct_frames": seen.size(), "indices": seen.keys()})
root.remove_child(f4)
f4.free()
# Reduced motion stops breathing and resets scale.
unit.set_reduced_motion(true)
_check(not unit.is_breathing(), "reduced motion should stop breathing")
_check(art != null and is_equal_approx(art.scale.y, 1.0), "reduced motion should reset sprite scale")
_record("reduced", {"breathing": unit.is_breathing(), "scale": art.scale.y if art != null else -1.0})
# Turning reduced motion back off resumes idle breathing.
unit.set_reduced_motion(false)
_check(unit.is_breathing(), "disabling reduced motion should resume idle breathing")
_record("restored", {"breathing": unit.is_breathing()})
root.remove_child(unit)
unit.free()
_finish()
func _finish() -> void:
var passed := _problems.is_empty()
var report := {
"schema": 1, "kind": "windroost_breathing_test",
"overall": "PASS" if passed else "FAIL",
"problems": _problems, "steps": _steps,
}
var artifact_dir := ProjectSettings.globalize_path("res://artifacts")
DirAccess.make_dir_recursive_absolute(artifact_dir)
var file := FileAccess.open(artifact_dir.path_join("breathing_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("BREATH_STEP %s" % JSON.stringify(entry))
if passed:
print("BREATH_PASS %d stages verified" % _steps.size())
else:
print("BREATH_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)
func _check(condition: bool, message: String) -> void:
if not condition:
_problems.append(message)
func _record(name: String, data: Dictionary) -> void:
var entry := data.duplicate()
entry["step"] = name
_steps.append(entry)