Numbers. The paper runner (tools/mvp_validation_sim.py) and the Godot runtime adapter were two independent rewrites of the same rules and had drifted: seed derivation, damage order, the weakness rule and the shield rebuild semantics all differed, so the runtime never actually reproduced the paper numbers and P2-BAT-01 could never pass. - add data/mvp_battle_rules.json as the single source of balance data and of the per-run seed derivation, read by both engines - derive the efficiency factor from SHA-256 (48-bit prefix) so Python and GDScript land on the same float64 - port the paper semantics into battle_sim.gd and expose the simulation as a stepwise state machine so a live scene can drive it at 1x/2x/3x - add tools/mvp_parity_gate.py: diffs 300 results field by field, event log by event log, and exits non-zero on any difference - freeze data/mvp_validation_seed_reference.json so unapproved numeric drift fails the gate - note that GDScript's roundf() is half-away-from-zero while Python's round() is banker's rounding; the runtime uses String.num instead UI. The sample had no real UI carrier, no localization and no touch path, so the NinePatch, dynamic text, safe area and input cases had nothing to be proven against. - add the battle HUD, laid out from the contract table rather than container stretch ratios, reproducing the 390x844 rectangles exactly and adapting 360x800 / 430x932 with the stage kept as priority space - add runtime text tables for zh_CN and en_US and a key validator that proves both locales carry the same keys and every content id has a string - add NinePatch frames with a 6px border band and 6px cut corners - add the live battle scene, the capture runner and the 1x/2x/3x equivalence test tools/run_p2_checks.sh runs the nine gates in one command; all pass.
156 lines
5.5 KiB
GDScript
156 lines
5.5 KiB
GDScript
extends SceneTree
|
|
|
|
## Capture runner for the battle HUD.
|
|
##
|
|
## Produces normal-render frames at every required viewport size and locale,
|
|
## and records the live HUD region rectangles so the layout can be checked
|
|
## against `BATTLE_HUD_HIGH_FIDELITY_SPEC.md` without eyeballing.
|
|
##
|
|
## This runner needs a real display: headless Godot has no renderer.
|
|
|
|
const SCENES_DIR := "res://scenes/"
|
|
const OUTPUT_DIR := "res://artifacts/ui_captures/"
|
|
const BATTLE_SCENE := "res://scripts/battle_scene.gd"
|
|
|
|
const SHOTS := [
|
|
{"name": "battle_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "scenario": "P3A-N03-SEMI", "ticks": 50, "state": "battle"},
|
|
{"name": "battle_390_en_US", "size": Vector2i(390, 844), "locale": "en_US", "scenario": "P3A-N03-SEMI", "ticks": 50, "state": "battle"},
|
|
{"name": "battle_360_zh_CN", "size": Vector2i(360, 800), "locale": "zh_CN", "scenario": "P3A-N03-SEMI", "ticks": 50, "state": "battle"},
|
|
{"name": "battle_430_zh_CN", "size": Vector2i(430, 932), "locale": "zh_CN", "scenario": "P3A-N03-SEMI", "ticks": 50, "state": "battle"},
|
|
{"name": "battle_360_en_US", "size": Vector2i(360, 800), "locale": "en_US", "scenario": "P3A-N03-SEMI", "ticks": 50, "state": "battle"},
|
|
{"name": "pause_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "scenario": "P3A-N03-SEMI", "ticks": 50, "state": "pause"},
|
|
{"name": "victory_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "scenario": "P3A-N01-AUTO", "ticks": 160, "state": "battle"},
|
|
{"name": "victory_390_en_US", "size": Vector2i(390, 844), "locale": "en_US", "scenario": "P3A-N01-AUTO", "ticks": 160, "state": "battle"},
|
|
]
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(OUTPUT_DIR))
|
|
var manifest: Array = []
|
|
var failures: Array = []
|
|
for shot in SHOTS:
|
|
var entry := await _capture_shot(shot)
|
|
manifest.append(entry)
|
|
if not bool(entry["layout_ok"]):
|
|
failures.append("%s: %s" % [shot["name"], "; ".join(entry["layout_problems"])])
|
|
if str(entry["status"]) != "ok":
|
|
failures.append("%s: %s" % [shot["name"], entry["status"]])
|
|
|
|
var manifest_path := OUTPUT_DIR.path_join("ui_captures_manifest.json")
|
|
var file := FileAccess.open(manifest_path, FileAccess.WRITE)
|
|
if file != null:
|
|
file.store_string(JSON.stringify({"schema": 1, "captures": manifest}, "\t", true))
|
|
file.close()
|
|
|
|
for entry in manifest:
|
|
print(
|
|
"UI_CAPTURE %s size=%s viewport=%s locale=%s layout_ok=%s file=%s"
|
|
% [
|
|
entry["name"],
|
|
str(entry["size"]),
|
|
str(entry["viewport_size"]),
|
|
entry["locale"],
|
|
str(entry["layout_ok"]),
|
|
entry["file"],
|
|
]
|
|
)
|
|
for problem in entry["layout_problems"]:
|
|
print(" UI_LAYOUT_PROBLEM %s" % problem)
|
|
|
|
if failures.is_empty():
|
|
print("UI_CAPTURE_PASS %d captures" % manifest.size())
|
|
quit(0)
|
|
else:
|
|
print("UI_CAPTURE_FAIL %s" % "; ".join(failures))
|
|
quit(1)
|
|
|
|
|
|
func _capture_shot(shot: Dictionary) -> Dictionary:
|
|
var size: Vector2i = shot["size"]
|
|
var root := get_root()
|
|
# The window must exist before its size can be changed, otherwise the OS
|
|
# keeps the default size and the capture silently records the wrong size.
|
|
await _wait_frames(2)
|
|
root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
|
|
root.content_scale_size = size
|
|
root.size = size
|
|
await _wait_frames(3)
|
|
var real_size := root.get_visible_rect().size
|
|
|
|
var scene_script := load(BATTLE_SCENE)
|
|
var scene: Node = scene_script.new()
|
|
root.add_child(scene)
|
|
scene.set_process(false)
|
|
|
|
var battle = scene as BattleScene
|
|
battle.setup(str(shot["locale"]), str(shot["scenario"]), 10001)
|
|
battle.advance_ticks(int(shot["ticks"]))
|
|
if str(shot["state"]) == "pause":
|
|
battle.paused = true
|
|
battle.hud.show_modal(
|
|
"modal.pause.title",
|
|
"modal.pause.resume",
|
|
[
|
|
{"id": "resume", "label_key": "modal.pause.resume"},
|
|
{"id": "settings", "label_key": "modal.pause.settings"},
|
|
{"id": "exit", "label_key": "modal.pause.exit"},
|
|
]
|
|
)
|
|
|
|
await _wait_frames(4)
|
|
|
|
var rects: Dictionary = battle.hud.region_rects()
|
|
# The contract is stated at 390x844, so only that size can be diffed
|
|
# against the reference rectangles. Other sizes are recorded and their
|
|
# own consistency is checked separately.
|
|
var reference := Vector2i(390, 844)
|
|
var problems: Array[String] = []
|
|
if real_size == Vector2(reference):
|
|
problems = BattleHudLayout.verify_layout(rects)
|
|
elif real_size.x < 340.0 or real_size.y < 700.0:
|
|
problems.append("viewport %s is smaller than the smallest required size" % str(real_size))
|
|
var image := root.get_texture().get_image()
|
|
var output_path := OUTPUT_DIR.path_join("%s.png" % shot["name"])
|
|
var saved := image.save_png(ProjectSettings.globalize_path(output_path))
|
|
|
|
root.remove_child(scene)
|
|
scene.queue_free()
|
|
|
|
return {
|
|
"name": str(shot["name"]),
|
|
"size": [size.x, size.y],
|
|
"viewport_size": [real_size.x, real_size.y],
|
|
"locale": str(shot["locale"]),
|
|
"scenario": str(shot["scenario"]),
|
|
"ticks": int(shot["ticks"]),
|
|
"state": str(shot["state"]),
|
|
"file": output_path,
|
|
"status": "ok" if saved == OK else "save_failed:%d" % saved,
|
|
"layout_ok": problems.is_empty(),
|
|
"layout_problems": problems,
|
|
"region_rects": _rects_to_json(rects),
|
|
}
|
|
|
|
|
|
func _rects_to_json(rects: Dictionary) -> Dictionary:
|
|
var out: Dictionary = {}
|
|
for key in rects.keys():
|
|
var rect: Rect2 = rects[key]
|
|
out[str(key)] = {
|
|
"x": rect.position.x,
|
|
"y": rect.position.y,
|
|
"w": rect.size.x,
|
|
"h": rect.size.y,
|
|
}
|
|
return out
|
|
|
|
|
|
func _wait_frames(count: int) -> void:
|
|
for _index in range(count):
|
|
await process_frame
|
|
await RenderingServer.frame_post_draw
|