Files
windroost/p2_godot_sample/scripts/attack_anim_test.gd
T
wushenghua 613f92db1e fix: wire hero attack animation to real battle events (found by frame review)
Owner said "you can see the effect locally" — so I reviewed a 5 s real
auto-battle frame-by-frame. Found a gap static screenshots and tests missed:
heroes stood still the whole time; the 4-frame attacks made for H02/H03/H04
were only ever played by a test hook, never by the real game.

Fix:
- BattleHud.play_team_attack() plays a one-shot attack on every visible hero,
  driven by authoritative manual events click_enemy / offboard_burst (both are
  genuine company-wide player actions, so the animation is honest). Passive
  auto DPS has no per-hit event and deliberately does NOT trigger it.
- Reduced motion skips the attack (it would freeze on frame 0); moreover
  set_reduced_motion(true) now snaps any in-flight one-shot state back to idle
  so toggling the setting mid-attack cannot freeze a hero.

attack_anim_test (4 stages): manual click -> 3 heroes in attack state; frames
advance and all recover to idle; reduced motion never starts the attack.
Registered in the full gate; P2_CHECKS_PASS. prototype/ untracked.
2026-11-18 10:36:27 +08:00

129 lines
4.2 KiB
GDScript

extends SceneTree
## Hero attack animation is driven by authoritative manual actions (automated_verified).
##
## Regression found by reviewing a real 5 s auto-battle frame sequence: heroes
## never played their 4-frame attack because only a test hook ever called
## play_once("attack"). Manual click / storm events must now trigger the visible
## company's attack pose; passive auto DPS must NOT (no fake attack).
const OUTPUT_PATH := "res://artifacts/attack_anim_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var shell := load("res://scenes/game_root.tscn").instantiate() as GameRoot
root.add_child(shell)
await process_frame
await process_frame
shell.reset_profile_for_test()
shell.set_reduced_motion_for_test(false)
shell.start_node("R1-C01-N02")
await process_frame
await process_frame
var battle := shell.get_battle()
battle.set_process(false)
var hud := battle.hud
# Baseline: at rest heroes are in idle state (frame from the idle cycle).
var idle_frames: Dictionary = {}
for hid in ["H01", "H02", "H03"]:
idle_frames[hid] = hud.hero_frame_for_test(hid)
_record("idle_baseline", idle_frames)
# Authoritative manual action: inject a click_enemy event into the sim, let
# the HUD scan it, and verify heroes switch to attack frame 0.
P2BattleSim.inject_input(battle.state, {
"time": float(battle.state["time"]),
"type": "click_enemy",
"target_id": str(battle.state["enemies"][0]["content_id"]),
})
battle.advance_ticks(1)
await process_frame
var attack_started := false
for hid in ["H01", "H02", "H03"]:
if hud.hero_frame_for_test(hid) == 0:
attack_started = true
break
# A just-started attack is on frame 0, same as a just-reset idle — so also
# check the unit's internal state via a dedicated hook below.
var states := hud.hero_states_for_test()
var in_attack := 0
for hid in states.keys():
if str(states[hid]) == "attack":
in_attack += 1
if in_attack < 3:
_problems.append("manual click should put all 3 visible heroes in attack state, got %d" % in_attack)
_record("after_click", {"attack_state_count": in_attack, "frame0_seen": attack_started})
# Attack must recover to idle after its frames play (no permanent freeze).
# Drive the hero animation clock explicitly (headless frames have ~0 delta).
for i in range(30):
hud.advance_hero_anims_for_test(0.05)
await process_frame
var states2 := hud.hero_states_for_test()
var still_attack := 0
for hid in states2.keys():
if str(states2[hid]) == "attack":
still_attack += 1
if still_attack != 0:
_problems.append("heroes should recover to idle after attack, %d stuck" % still_attack)
_record("after_recover", {"still_attack": still_attack})
# Reduced motion must skip the attack anim entirely (would freeze frame 0).
shell.set_reduced_motion_for_test(true)
battle.advance_ticks(1)
P2BattleSim.inject_input(battle.state, {
"time": float(battle.state["time"]),
"type": "click_enemy",
"target_id": str(battle.state["enemies"][0]["content_id"]),
})
battle.advance_ticks(1)
await process_frame
var states3 := hud.hero_states_for_test()
for hid in states3.keys():
if str(states3[hid]) == "attack":
_problems.append("reduced motion must not start attack anim (%s)" % hid)
_record("reduced_motion", {"states": states3})
root.remove_child(shell)
shell.free()
_finish()
func _fb(): return null
func _finish() -> void:
var passed := _problems.is_empty()
var report := {
"schema": 1, "kind": "windroost_attack_anim_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("attack_anim_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("ATK_STEP %s" % JSON.stringify(entry))
if passed:
print("ATK_PASS %d stages verified" % _steps.size())
else:
print("ATK_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)
func _record(name: String, data: Dictionary) -> void:
var entry := data.duplicate()
entry["step"] = name
_steps.append(entry)