Files
windroost/p2_godot_sample/scripts/first_run_test.gd
T
wushenghua 5fe1ff57b7 fix: correct first-run onboarding and printf placeholders in UI strings
Running the game window on a clean profile exposed two player-visible defects
that headless assertions never caught.

A brand-new player was told "offline report settled · progress saved" before
they had ever left the game. ProfileStore now tracks seen_intro (schema 4,
migrated from older saves as already-seen), first runs show a welcome banner,
and starting the first node marks the intro seen and persists it.

Upgrade buttons at 0 gold were disabled but looked identical to enabled ones,
and their text showed the literal "需 %d ◆": the string used printf % while
UiText.tf only substitutes {name}. Fixed all such strings (offline reward,
victory, rebuild, archive, growth) to use named placeholders, and added a
validator guard that fails any key passed to UiText.tf whose text still has a
printf % placeholder. Disabled upgrades now read "需 120 ◆" and render dimmed.

Added a first-run evidence test over a real rendered GameRoot. It verifies the
welcome banner, unaffordable button state, and that intro-seen persists.
tools/run_p2_checks.sh now runs 17 gates; all pass. Verified again in a live
Godot window with a clean profile and terminated the process after inspection.
2026-11-17 10:55:27 +08:00

86 lines
3.0 KiB
GDScript

extends SceneTree
## First-run onboarding evidence from a real rendered GameRoot.
##
## A brand-new player must not be told "offline report settled" before they
## have ever left, and unaffordable upgrades must read as unaffordable. Once
## the player starts a node, the intro is marked seen and later visits show the
## returning-player copy.
const OUTPUT_PATH := "res://artifacts/first_run_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
var profile := shell.get_profile()
_check(ProfileStore.is_first_run(profile), "a fresh profile should be a first run")
var intro_text := shell.skyport_report_text.text
_check(intro_text.contains("欢迎") or intro_text.contains("Welcome"), "first-run banner should welcome, got: %s" % intro_text)
_record("first_run_banner", {"text": intro_text})
# Upgrades are unaffordable at 0 gold and must say so.
var rows := shell.get_upgrade_rows_for_test()
var unaffordable := 0
for hero_id in rows.keys():
var button: Button = rows[hero_id]["button"]
if button.disabled:
unaffordable += 1
_check(button.text.contains("需") or button.text.contains("Need"), "disabled upgrade should show need-gold, got: %s" % button.text)
_check(unaffordable >= 3, "fresh profile should have all upgrades unaffordable")
_record("upgrade_affordability", {"disabled_count": unaffordable})
# Starting a node marks the intro seen and persists it.
shell.start_node("R1-C01-N01")
await process_frame
var after := shell.get_profile()
_check(not ProfileStore.is_first_run(after), "starting a node should mark intro seen")
var reloaded := ProfileStore.load_profile()
_check(not ProfileStore.is_first_run(reloaded), "seen_intro should persist across reload")
_profile_reload = reloaded
_record("intro_seen", {"in_memory": not ProfileStore.is_first_run(after), "persisted": not ProfileStore.is_first_run(reloaded)})
var passed := _problems.is_empty()
var report := {
"schema": 1, "kind": "windroost_first_run_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("first_run_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("FIRST_RUN_STEP %s" % JSON.stringify(entry))
if passed:
print("FIRST_RUN_PASS %d stages verified" % _steps.size())
else:
print("FIRST_RUN_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)
var _profile_reload: Dictionary = {}
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)