Files
windroost/p2_godot_sample/scripts/visible_node_test.gd
T
wushenghua 7a101173ea feat: add pixel VFX, event binding and visible-node caps; close P2 locally
VFX. The three feedback effects existed only as IDs in the contract. They
are now generated as low-resolution transparent sprite sheets (16/32/64px,
hard pixel clusters, nearest filtering) with their own manifest. VfxView
advances frame indices without interpolation, finishes deterministically, and
drops intermediate frames in low-power mode while keeping the final state.
The battle scene maps authoritative sim events to effects: shield_break,
cast_ultimate and hit. Feedback can no longer disagree with the simulation.

Node caps. The stage now clamps visible enemies to five and visible heroes to
five, with a test that supplies seven enemies and six heroes, checks the real
node counts and verifies stale nodes are released when content shrinks.

tools/run_p2_checks.sh now runs 13 gates; all pass. PRODUCTION/38 records
P2-VFX-01 and the node-count portion of P2-BAT-03 as PASS, so P2 local
acceptance is complete. Open gates are the real-device ones (safe-area inset,
frame time, memory, heat) plus human comprehension and willingness to
continue; no local automation can grant those.
2026-11-17 00:03:47 +08:00

99 lines
3.4 KiB
GDScript

extends SceneTree
## Visible-node cap evidence for P2-BAT-03.
##
## The contract allows at most five full enemy nodes and five visible hero
## nodes in the battle stage. Background heroes must not get a Sprite or a
## collision body. This test supplies more content than the cap and checks
## the actual node counts, including after the content shrinks again.
const OUTPUT_PATH := "res://artifacts/visible_node_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
var scene = load("res://scripts/battle_scene.gd").new()
root.add_child(scene)
var battle := scene as BattleScene
battle.set_process(false)
battle.setup("zh_CN", "P3A-N03-SEMI", 10001)
var heroes: Array = []
for hero_id in ["H01", "H02", "H04", "H05", "H06", "H03"]:
heroes.append({"id": hero_id, "signature": "auto", "energy": 0.0, "energy_max": 100.0})
battle.hud.set_roster(heroes)
var enemies: Array = []
for index in range(7):
enemies.append({
"id": "E-R1-F1-V1#%d" % (index + 1),
"content_id": "E-R1-F1-V1",
"kind": "normal", "hp": 100.0, "max_hp": 100.0,
"armor": 1.0, "shield": 0.0, "weak_tag": "aoe",
"shield_broken": false, "dead": false,
})
battle.hud.set_enemies(enemies, "")
await process_frame
await process_frame
var counts := battle.hud.visible_node_counts()
_check(int(counts["enemy_units"]) <= 5, "enemy unit count %s exceeds 5" % str(counts["enemy_units"]))
_check(int(counts["enemy_plates"]) <= 5, "enemy plate count %s exceeds 5" % str(counts["enemy_plates"]))
_check(int(counts["enemy_hit_areas"]) <= 5, "enemy hit area count %s exceeds 5" % str(counts["enemy_hit_areas"]))
_check(int(counts["hero_units"]) <= 5, "visible hero unit count %s exceeds 5" % str(counts["hero_units"]))
_record("over_cap_content", counts)
# Non-visible heroes must not have spawned any art: only H01 has an atlas,
# so a leaked unit for H02/H04 would fail to configure and stay absent.
_check(int(counts["hero_units"]) == 1, "only H01 has art; expected 1 hero unit, got %s" % str(counts["hero_units"]))
# Shrinking the content must release the stale nodes.
battle.hud.set_enemies(enemies.slice(0, 1), "")
battle.hud.set_roster(heroes.slice(0, 1))
await process_frame
await process_frame
var shrunk := battle.hud.visible_node_counts()
_check(int(shrunk["enemy_units"]) == 1, "stale enemy units were not released")
_check(int(shrunk["hero_units"]) == 1, "stale hero units were not released")
_record("after_shrink", shrunk)
var passed := _problems.is_empty()
var report := {
"schema": 1,
"kind": "windroost_visible_node_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("visible_node_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("VISIBLE_NODE_STEP %s" % JSON.stringify(entry))
if passed:
print("VISIBLE_NODE_PASS caps and stale-node cleanup verified")
else:
print("VISIBLE_NODE_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)