Files
windroost/p2_godot_sample/scripts/side_systems_ui_test.gd
T
wushenghua f1f2c31a94 feat: side systems runtime — partners/records/black market (L5 runtime)
Continued FULL_GAME_GOAL. The three side systems had authored content but no
runtime, so none of their numbers were actually used. Added a Python-authoritative
engine and a GDScript mirror (parity gate over 3 profile tiers) plus a real UI.

- 5 partners: tiered low-pressure tasks derived from play counters (distance,
  relics, records, wins, new skies), no combat and no failure penalty, claim
  once per tier for gold/crystal.
- 167 records: progress from play counters, stage rewards every third record,
  one-time claims, no miss penalty or daily streak; list shows claimable
  milestones and X/167 progress.
- 6 black-market offers: crystal-only purchases (relic/emblem/material/cosmetic/
  time/recovery), no pay-to-win; insufficient balance is a clean rejection.
- Skyport 旅团事务 page with three tabs; claims/purchases route through the
  real engines and persist. Added battle_wins/total_gold_earned/partner_claims/
  revive_charges/cosmetics profile fields with normalization, and victory now
  increments the win/earned counters in both slice and world flows.
- side_systems_ui_test drives tabs/claims/purchases/locale through real hooks;
  registered alongside parity in the full gate. Added p3a_side capture and
  ignored regenerated artifact files.

All gates pass incl. 25 UI captures; P2_CHECKS_PASS. prototype/ untracked.
2026-11-18 16:36:17 +08:00

136 lines
5.1 KiB
GDScript

extends SceneTree
## Side-system runtime UI (L5): partner task claims, record milestone claims,
## and crystal-only market purchases, all through the real shell pages.
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _check(cond: bool, msg: String) -> void:
if not cond:
_problems.append(msg)
func _record(name: String, data: Dictionary) -> void:
var e := data.duplicate()
e["step"] = name
_steps.append(e)
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()
var gp := shell.get_profile()
gp["highest_node"] = 120
gp["battle_wins"] = 30
gp["gold"] = 1000
gp["crystal"] = 200
gp["relics"] = {"R01": true}
gp["emblems"] = {"E01": true}
gp["talents"] = {"T01": true, "T02": true}
gp["unlocked_heroes"] = ["H01", "H02", "H03", "H04"]
var nodes_done: Array = []
for i in range(1, 31):
nodes_done.append("R1-C01-N%02d" % i)
gp["completed_nodes"] = nodes_done
gp["total_essence_earned"] = 500
gp["total_gold_earned"] = 5000
gp["new_sky_count"] = 1
gp["final_boss_first_clears"] = 1
ProfileStore.save_profile(gp)
shell.refresh_pages_for_test()
shell.show_page_for_test("side")
await process_frame
var st := shell.get_side_state_for_test()
_check(str(st["tab"]) == "partners", "default side tab should be partners")
_check(int(st["rows"]) == 5, "partner tab should show 5 partners")
_record("partners", st)
# Claim navigator tier 1: no combat, no failure, gold+crystal granted.
var gold_before := int(shell.get_profile().get("gold", 0))
var crystal_before := int(shell.get_profile().get("crystal", 0))
var r := shell.claim_partner_for_test("P01")
_check(bool(r.get("ok")), "partner claim should succeed")
_check(int(r.get("tier", 0)) == 1, "partner tier should start at 1")
_check(int(shell.get_profile().get("gold", 0)) == gold_before + 20, "partner gold reward")
_check(int(shell.get_profile().get("crystal", 0)) == crystal_before + 2, "partner crystal reward")
shell.on_modal_action_for_test("side")
_record("partner_claim", {"result": r, "gold": shell.get_profile().get("gold")})
# Records: milestones derive from play counters; A001 should be claimable.
shell.set_side_tab_for_test("records")
await process_frame
st = shell.get_side_state_for_test()
_check(int(st["rows"]) >= 1, "records tab should list claimable records")
_check(st["summary"].contains("167"), "records summary should show 167 total")
_record("records", st)
var r2 := shell.claim_record_for_test("A001")
_check(bool(r2.get("ok")), "record A001 should be claimable from 30 cleared nodes")
shell.on_modal_action_for_test("side")
_check(not bool(shell.claim_record_for_test("A001").get("ok")), "record claim must be one-time")
_record("record_claim", {"result": r2})
# Market: 6 crystal-only offers; buy relic pack and recovery tool.
shell.set_side_tab_for_test("market")
await process_frame
st = shell.get_side_state_for_test()
_check(int(st["rows"]) == 6, "market tab should show 6 offers")
_record("market", st)
var relics_before := (shell.get_profile().get("relics", {}) as Dictionary).size()
var r3 := shell.buy_market_for_test("M01")
_check(bool(r3.get("ok")), "relic pack purchase should succeed")
_check((shell.get_profile().get("relics", {}) as Dictionary).size() == relics_before + 1,
"relic pack should grant a relic")
var r4 := shell.buy_market_for_test("M06")
_check(bool(r4.get("ok")), "recovery tool purchase should succeed")
_check(int(shell.get_profile().get("revive_charges", 0)) == 1, "recovery tool should grant a charge")
_record("market_buy", {"relic": r3, "recovery": r4})
# Insufficient crystal path is a clean rejection, not a negative balance.
gp = shell.get_profile()
gp["crystal"] = 0
ProfileStore.save_profile(gp)
var r5 := shell.buy_market_for_test("M02")
_check(not bool(r5.get("ok")), "purchase with 0 crystal should be rejected")
_check(int(shell.get_profile().get("crystal", 0)) >= 0, "crystal must not go negative")
_record("insufficient", {"result": r5})
shell.set_locale_for_test("en_US")
await process_frame
st = shell.get_side_state_for_test()
_check(not st["summary"].contains("风晶交易") and not st["summary"].contains("已领"),
"en side summary should not be Chinese")
_check(st["summary"].to_lower().contains("crystal"), "en side summary should be translated")
_record("en", {"summary": st["summary"]})
root.remove_child(shell)
shell.free()
_finish()
func _finish() -> void:
var passed := _problems.is_empty()
var report := {"schema": 1, "kind": "windroost_side_systems_ui_test",
"overall": "PASS" if passed else "FAIL", "problems": _problems, "steps": _steps}
var dir := ProjectSettings.globalize_path("res://artifacts")
DirAccess.make_dir_recursive_absolute(dir)
var f := FileAccess.open(dir.path_join("side_systems_ui_test.json"), FileAccess.WRITE)
if f != null:
f.store_string(JSON.stringify(report, "\t", true)); f.close()
for e in _steps:
print("SIDE_UI_STEP %s" % JSON.stringify(e))
if passed:
print("SIDE_UI_PASS")
else:
print("SIDE_UI_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)