Files
windroost/p2_godot_sample/scripts/p3a_loop_test.gd
T
wushenghua b4125fdaa4 feat: make event nodes real choices and verify the full chapter
Event nodes N04 and N07 now present two bounded options (immediate gold versus
permanent crystal) instead of silently granting gold. The data lives with the
rest of the launch content, the strings are keyed in both ship locales, and an
event-choice flow test verifies two options, the reward, and completion.

The modal stacks its actions vertically: two 220px buttons overflowed the
390px viewport and clipped the second choice.

Chapter balance is now measured rather than assumed. tools/simulate_chapter.py
plays all ten nodes with two profiles: the minimum-effort profile clears 9/10
(N08 needs taps), and the active profile clears 10/10 including the boss. That
is the evidence that manual input changes the outcome and that the chapter is
completable. The boss HP scale bug found by this simulation was fixed earlier.

tools/run_p2_checks.sh still runs 15 gates; all pass.
2026-11-17 01:55:25 +08:00

180 lines
6.3 KiB
GDScript

extends SceneTree
## P3a end-to-end loop test.
##
## Drives the real game shell through: fresh profile -> node 1 battle -> reward
## -> unlock node 2 -> upgrade -> save -> reload. No page callbacks are faked;
## the battle scene is stepped with the same tick driver the capture uses.
const OUTPUT_PATH := "res://artifacts/p3a_loop_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
# A fresh profile in an isolated user directory is not trivial in one
# process, so start from a known state and clear the progression fields.
var shell := load("res://scenes/game_root.tscn").instantiate() as GameRoot
root.add_child(shell)
await process_frame
await process_frame
var profile := shell.get_profile()
profile["gold"] = 0
profile["crystal"] = 0
profile["hero_levels"] = {}
profile["unlocked_heroes"] = ["H01", "H02", "H03"]
profile["completed_nodes"] = []
profile["claimed_rewards"] = []
profile["current_node"] = "R1-C01-N01"
_record("fresh", {
"gold": profile["gold"], "unlocked": profile["unlocked_heroes"].size(),
"completed": profile["completed_nodes"].size(),
})
shell.start_node("R1-C01-N01")
await process_frame
await process_frame
var battle := shell.get_battle()
_check(battle != null, "node 1 should have created a battle scene")
if battle == null:
_finish()
return
battle.set_process(false)
var dbg: Array = []
for e in battle.state.get("enemies", []):
dbg.append({"id": str(e.get("id", "")), "hp": float(e.get("hp", 0.0)), "dead": bool(e.get("dead", false))})
_record("battle_started", {
"scenario": str(battle.scenario.get("id", "")),
"enemies": str(battle.scenario.get("enemy_ids", [])),
"roster_dps": float(battle.state.get("roster_dps", 0.0)),
})
# Drive until the battle resolves or the tick budget runs out.
var guard := 0
while not battle.finished and guard < 900:
battle.advance_ticks(1)
guard += 1
await process_frame
await process_frame
_check(str(battle.state.get("result", "")) == "win", "node 1 should be winnable")
_record("battle_result", {
"result": str(battle.state.get("result", "")),
"duration": float(battle.state.get("time", 0.0)),
})
profile = shell.get_profile()
_check(int(profile.get("gold", 0)) == 30, "node 1 should pay 30 gold, got %s" % str(profile.get("gold")))
_check((profile.get("completed_nodes", []) as Array).has("R1-C01-N01"), "node 1 should be marked complete")
_record("reward", {
"gold": profile.get("gold"),
"completed": profile.get("completed_nodes"),
"unlocked": profile.get("unlocked_heroes"),
})
# Start node 2: it should be unlocked and use a higher HP scale.
shell.start_node("R1-C01-N02")
await process_frame
await process_frame
var second := shell.get_battle()
_check(second != null, "node 2 should start")
if second != null:
second.set_process(false)
_record("node_2", {
"scenario": str(second.scenario.get("id", "")),
"hp_scale": float(second.scenario.get("hp_scale", 0.0)),
"enemies": str(second.scenario.get("enemy_ids", [])),
"roster_dps": float(second.state.get("roster_dps", 0.0)),
})
var n2guard := 0
while not second.finished and n2guard < 900:
second.advance_ticks(1)
n2guard += 1
await process_frame
await process_frame
_check(str(second.state.get("result", "")) == "win", "node 2 should be winnable with the starting roster")
var p2 := shell.get_profile()
_check((p2.get("unlocked_heroes", []) as Array).has("H04"), "clearing node 2 should unlock H04")
_record("node_2_result", {
"result": str(second.state.get("result", "")),
"duration": float(second.state.get("time", 0.0)),
"unlocked": p2.get("unlocked_heroes"),
"gold": p2.get("gold"),
})
# Event nodes must present a real choice, not a free grant.
profile = shell.get_profile()
var completed_events: Array = profile.get("completed_nodes", [])
if not completed_events.has("R1-C01-N03"):
completed_events.append("R1-C01-N03")
profile["completed_nodes"] = completed_events
shell.start_node("R1-C01-N04")
await process_frame
_check(shell.is_modal_visible(), "event node should open a choice modal")
_check(shell.modal_action_count() == 2, "event node should offer two choices")
var gold_before_event := int(shell.get_profile().get("gold", 0))
shell.choose_event("rescue")
await process_frame
var after_event := shell.get_profile()
_check(not shell.is_modal_visible(), "choosing should close the event modal")
_check(int(after_event.get("gold", 0)) == gold_before_event + 35, "rescue should pay 35 gold")
_check(int(after_event.get("crystal", 0)) == 1, "rescue should pay 1 crystal")
_check((after_event.get("completed_nodes", []) as Array).has("R1-C01-N04"), "event node should complete")
_record("event_choice", {
"choices": 2, "gold_gain": int(after_event.get("gold", 0)) - gold_before_event,
"crystal": after_event.get("crystal"), "completed": after_event.get("completed_nodes"),
})
# Persistence round-trip.
var ok := ProfileStore.save_profile(profile)
_check(ok, "profile should save")
var reloaded := ProfileStore.load_profile()
_check(int(reloaded.get("gold", 0)) == int(profile.get("gold", 0)), "gold should survive reload")
_check(
(reloaded.get("completed_nodes", []) as Array).has("R1-C01-N01"),
"cleared nodes should survive reload"
)
_record("save_reload", {
"gold": reloaded.get("gold"), "completed": reloaded.get("completed_nodes"),
})
_finish()
func _finish() -> void:
var passed := _problems.is_empty()
var report := {
"schema": 1, "kind": "windroost_p3a_loop_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("p3a_loop_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("P3A_STEP %s" % JSON.stringify(entry))
if passed:
print("P3A_LOOP_PASS %d stages verified" % _steps.size())
else:
print("P3A_LOOP_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)