155 lines
5.6 KiB
GDScript
155 lines
5.6 KiB
GDScript
extends SceneTree
|
|
|
|
## Focused before/after evidence runner for the UI visual-language candidate.
|
|
## It reuses the exact real-render path of capture_runner.gd (game_root shell and
|
|
## battle scene) and writes into the directory named by
|
|
## WINDROOST_UI_LANGUAGE_CAPTURE_DIR. It changes no game behaviour and claims
|
|
## only runtime render + input evidence, never human/device/release acceptance.
|
|
|
|
const BATTLE_SCENE := "res://scripts/battle_scene.gd"
|
|
|
|
var _dir: String = ""
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
var env_dir := OS.get_environment("WINDROOST_UI_LANGUAGE_CAPTURE_DIR")
|
|
_dir = env_dir if not env_dir.is_empty() else "res://artifacts/ui_language_captures/"
|
|
DirAccess.make_dir_recursive_absolute(ProjectSettings.globalize_path(_dir))
|
|
|
|
var shots := [
|
|
{"name": "skyport_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "page": "skyport"},
|
|
{"name": "world_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "page": "world"},
|
|
{"name": "side_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "page": "side"},
|
|
{"name": "loadout_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "page": "loadout"},
|
|
{"name": "victory_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "victory": "R1-C01-N02"},
|
|
{"name": "battle_390_zh_CN", "size": Vector2i(390, 844), "locale": "zh_CN", "battle": true},
|
|
# Locale / viewport preservation checks.
|
|
{"name": "skyport_360_zh_CN", "size": Vector2i(360, 800), "locale": "zh_CN", "page": "skyport"},
|
|
{"name": "skyport_430_zh_CN", "size": Vector2i(430, 932), "locale": "zh_CN", "page": "skyport"},
|
|
{"name": "skyport_390_en_US", "size": Vector2i(390, 844), "locale": "en_US", "page": "skyport"},
|
|
{"name": "world_390_en_US", "size": Vector2i(390, 844), "locale": "en_US", "page": "world"},
|
|
]
|
|
|
|
var manifest: Array = []
|
|
var problems: Array = []
|
|
for shot in shots:
|
|
var entry := await _capture(shot)
|
|
manifest.append(entry)
|
|
if str(entry["status"]) != "ok":
|
|
problems.append("%s: %s" % [shot["name"], entry["status"]])
|
|
|
|
var file := FileAccess.open(_dir.path_join("manifest.json"), FileAccess.WRITE)
|
|
if file != null:
|
|
file.store_string(JSON.stringify({
|
|
"schema": 1,
|
|
"kind": "windroost_ui_visual_language_evidence",
|
|
"generator": "scripts/ui_language_capture_runner.gd",
|
|
"evidence_level": "runtime_verified(render) + agent_visual_reviewed(composition)",
|
|
"captures": manifest,
|
|
}, "\t", true))
|
|
file.close()
|
|
|
|
for entry in manifest:
|
|
print("UI_LANGUAGE_SHOT %s sha256=%s" % [entry["name"], entry["sha256"]])
|
|
if problems.is_empty():
|
|
print("UI_LANGUAGE_CAPTURE_PASS %d shots" % manifest.size())
|
|
quit(0)
|
|
else:
|
|
print("UI_LANGUAGE_CAPTURE_FAIL %s" % "; ".join(problems))
|
|
quit(1)
|
|
|
|
|
|
func _capture(shot: Dictionary) -> Dictionary:
|
|
var size: Vector2i = shot["size"]
|
|
var root := get_root()
|
|
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
|
|
|
|
if bool(shot.get("battle", false)):
|
|
var scene: Node = load(BATTLE_SCENE).new()
|
|
root.add_child(scene)
|
|
scene.set_process(false)
|
|
var battle = scene as BattleScene
|
|
battle.setup(str(shot["locale"]), "P3A-N03-SEMI", 10001)
|
|
battle.advance_ticks(50)
|
|
await _wait_frames(4)
|
|
var image := root.get_texture().get_image()
|
|
var path := _dir.path_join("%s.png" % shot["name"])
|
|
var saved := image.save_png(ProjectSettings.globalize_path(path))
|
|
root.remove_child(scene)
|
|
scene.queue_free()
|
|
return _entry(shot, real_size, path, saved)
|
|
|
|
# Shell pages use the same authoritative profile setup as capture_runner.gd.
|
|
var shell := load("res://scenes/game_root.tscn").instantiate() as GameRoot
|
|
root.add_child(shell)
|
|
shell.set_locale(str(shot["locale"]))
|
|
if str(shot.get("page", "")) == "world":
|
|
shell.select_world_region_for_test("R3")
|
|
shell.select_world_chapter_for_test("R3-C05")
|
|
if str(shot.get("page", "")) == "side":
|
|
var sp := shell.get_profile()
|
|
sp["highest_node"] = 120
|
|
sp["battle_wins"] = 30
|
|
sp["crystal"] = 200
|
|
ProfileStore.save_profile(sp)
|
|
shell.show_page("side")
|
|
await _wait_frames(3)
|
|
ProfileStore.save_profile(ProfileStore.fresh_profile())
|
|
if shot.has("victory"):
|
|
shell.reset_profile_for_test()
|
|
shell.force_victory_for_test(str(shot["victory"]))
|
|
await _wait_frames(50)
|
|
else:
|
|
shell.show_page(str(shot.get("page", "skyport")))
|
|
await _wait_frames(6)
|
|
var image := root.get_texture().get_image()
|
|
var path := _dir.path_join("%s.png" % shot["name"])
|
|
var saved := image.save_png(ProjectSettings.globalize_path(path))
|
|
root.remove_child(shell)
|
|
shell.queue_free()
|
|
return _entry(shot, real_size, path, saved)
|
|
|
|
|
|
func _entry(shot: Dictionary, real_size: Vector2, path: String, saved: int) -> Dictionary:
|
|
return {
|
|
"name": str(shot["name"]),
|
|
"size": [int(shot["size"].x), int(shot["size"].y)],
|
|
"viewport_size": [real_size.x, real_size.y],
|
|
"locale": str(shot["locale"]),
|
|
"state": str(shot.get("page", "battle" if shot.get("battle", false) else "victory")),
|
|
"file": path,
|
|
"status": "ok" if saved == OK else "save_failed:%d" % saved,
|
|
"sha256": _sha256(path),
|
|
}
|
|
|
|
|
|
func _wait_frames(count: int) -> void:
|
|
for _index in range(count):
|
|
await process_frame
|
|
await RenderingServer.frame_post_draw
|
|
|
|
|
|
func _sha256(path: String) -> String:
|
|
var file := FileAccess.open(ProjectSettings.globalize_path(path), FileAccess.READ)
|
|
if file == null:
|
|
return ""
|
|
var data := file.get_buffer(file.get_length())
|
|
file.close()
|
|
var context := HashingContext.new()
|
|
context.start(HashingContext.HASH_SHA256)
|
|
context.update(data)
|
|
var digest := context.finish()
|
|
var hex := ""
|
|
for byte in digest:
|
|
hex += "%02x" % byte
|
|
return hex
|