Files
aetherbound-guild/runtime/tests/dev1/first_launch_capture_test.gd
T

93 lines
3.5 KiB
GDScript

extends SceneTree
const EntryShell = preload("res://entry/entry_shell.gd")
const SettingsStore = preload("res://entry/settings_store.gd")
const FIXTURES := [
{"width": 760, "height": 360, "locale": "zh_CN", "scale": 1.0},
{"width": 844, "height": 390, "locale": "zh_CN", "scale": 1.3},
{"width": 844, "height": 390, "locale": "en", "scale": 1.0},
{"width": 1280, "height": 720, "locale": "en", "scale": 1.3},
]
const STATES := ["default", "accessible"]
var failures: Array[String] = []
var output_root := ""
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
output_root = OS.get_environment("ABG_EVIDENCE_DIR")
if output_root.is_empty():
output_root = "/tmp/abg-sys002-first-launch-captures"
DirAccess.make_dir_recursive_absolute(output_root)
var count := 0
for fixture in FIXTURES:
for state in STATES:
await _capture(fixture, state)
count += 1
if failures.is_empty():
print("ABG_SYS002_FIRST_LAUNCH_CAPTURE_OK frames=%d states=default,accessible viewports=760x360,844x390,1280x720 locales=zh_CN,en text=100,130 renderer=normal" % count)
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func _capture(fixture: Dictionary, state: String) -> void:
var viewport := SubViewport.new()
viewport.size = Vector2i(int(fixture.width), int(fixture.height))
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
root.add_child(viewport)
var shell := EntryShell.new()
shell.auto_start = false
viewport.add_child(shell)
await _frames(3)
var setup := SettingsStore.new().defaults()
setup.locale = String(fixture.locale)
setup.text_scale = float(fixture.scale)
if state == "accessible":
setup.safe_area = 48
setup.text_scale = 1.3
setup.reduced_motion = true
setup.reduced_flashes = true
setup.captions = true
shell.settings = setup
shell.show_first_launch()
await _frames(5)
_verify(shell, fixture, state)
await RenderingServer.frame_post_draw
var image := viewport.get_texture().get_image()
var file_name := "first-launch-%s-%dx%d-%s-%d.png" % [state, int(fixture.width), int(fixture.height), String(fixture.locale), int(round(float(setup.text_scale) * 100.0))]
var error := image.save_png(output_root.path_join(file_name))
if error != OK:
failures.append("capture %s failed: %s" % [file_name, error])
viewport.queue_free()
await _frames(4)
func _verify(shell: Control, fixture: Dictionary, state: String) -> void:
var bounds := Rect2(Vector2.ZERO, Vector2(float(fixture.width), float(fixture.height)))
for node_name in ["FirstLaunchPreviewFrame", "FirstLaunchControls", "SetupApply"]:
var control := shell.find_child(node_name, true, false) as Control
if control == null or not bounds.encloses(control.get_global_rect()):
failures.append("%s %s outside %s" % [state, node_name, bounds])
for node_name in ["SetupLanguage", "SetupSafeArea", "SetupTextScale", "SetupReducedMotion", "SetupReducedFlashes", "SetupCaptions"]:
var row := shell.find_child(node_name, true, false) as Control
if row == null or row.get_global_rect().size.y < 48.0:
failures.append("%s %s lost minimum touch height" % [state, node_name])
if state == "accessible":
var safe_value := shell.find_child("SetupSafeArea", true, false).get_node("ValuePlate/ValueLabel") as Label
var scale_value := shell.find_child("SetupTextScale", true, false).get_node("ValuePlate/ValueLabel") as Label
if safe_value.text != "48 px" or scale_value.text != "130%":
failures.append("accessible state values are not reflected in runtime text")
func _frames(count: int) -> void:
for frame in range(count):
await process_frame