Files
windroost/p2_godot_sample/scripts/enemy_name_test.gd
T
wushenghua 08feec50db fix: enemy name plates show raw keys and wrong language
Found while inspecting the victory capture at reduced size: focal enemy name
plates displayed raw keys like [content.enemy.E-R1-F2-V1]. Two real bugs:

1. Only 3 of the 9 battle enemies had UI text keys; UiText.t returns "[key]"
   on a miss. Added the 5 missing names (zh_CN + en_US) sourced from the
   authoritative mvp_launch_content.json (Bandit Scout, Stone Golem, Goblin
   Bomber, Storm Sprite, Void Cultist). Added a HUD guard so any future miss
   falls back to the bare content id instead of a bracketed raw key.

2. GameRoot._start_active_wave hardcoded _battle.setup("zh_CN", ...); setup()
   uses that to reset the HUD locale, so English players saw Chinese enemy
   names in battle. Pass the shell locale instead.

enemy_name_test.gd (12 plates across 3 nodes x 2 locales) asserts no raw keys,
no empty names, and ASCII names under en_US. Registered as full-gate step
"enemy name plates". Added 360/430 victory captures for viewport coverage of
the new ribbon (visual check clean). Full gate P2_CHECKS_PASS, bundle sync PASS.
prototype/ stays untracked and untouched.
2026-11-18 01:19:12 +08:00

101 lines
3.2 KiB
GDScript

extends SceneTree
## Enemy name-plate localization (automated_verified).
##
## The battle HUD must never show a raw "[content.enemy.X]" key on the focal
## enemy plate. Regression: 5 of the 9 battle enemies had no text key, so the
## plates showed raw keys in normal play. Keys are now present plus a HUD
## fallback; this test proves every plate in a real battle is resolved.
const OUTPUT_PATH := "res://artifacts/enemy_name_test.json"
var _problems: Array = []
var _steps: Array = []
var _checked := 0
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()
# Battle nodes covering all previously-missing enemy IDs, both locales.
var nodes := ["R1-C01-N02", "R1-C01-N06", "R1-C01-N09"]
for locale in ["zh_CN", "en_US"]:
shell.set_locale(locale)
for node_id in nodes:
shell.start_node(node_id)
await process_frame
await process_frame
var battle := shell.get_battle()
if battle == null or battle.hud == null:
continue
var names: Array = []
_find_plate_names(battle.hud, names)
for n in names:
_checked += 1
if n.begins_with("[") and n.ends_with("]"):
_problems.append("raw key on enemy plate (%s): %s" % [locale, n])
if n.is_empty():
_problems.append("empty enemy plate name (%s)" % locale)
# Regression: battle setup() used to hardcode zh_CN, so en_US
# plates showed Chinese. English names must be ASCII.
if locale == "en_US" and n.to_utf8_buffer().size() != n.length():
_problems.append("en_US plate shows non-ASCII name: %s" % n)
_record(locale + ":" + node_id, {"plates": names})
root.remove_child(shell)
shell.free()
_check(_checked > 0, "no enemy name plates were inspected")
_record("summary", {"inspected": _checked})
_finish()
func _find_plate_names(node: Node, out: Array) -> void:
# Name plates are tagged with the "name_label" meta in _build_unit_plate.
if node.has_meta("name_label"):
var lbl: Label = node.get_meta("name_label")
if lbl != null and is_instance_valid(lbl):
out.append(lbl.text)
for child in node.get_children():
_find_plate_names(child, out)
func _finish() -> void:
var passed := _problems.is_empty()
var report := {
"schema": 1, "kind": "windroost_enemy_name_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("enemy_name_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("ENAME_STEP %s" % JSON.stringify(entry))
if passed:
print("ENAME_PASS %d plates verified" % _checked)
else:
print("ENAME_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)