97 lines
3.0 KiB
GDScript
97 lines
3.0 KiB
GDScript
extends SceneTree
|
|
|
|
const MainScene = preload("res://main.tscn")
|
|
const STATES := ["boot_ready", "title", "main_menu", "introduction", "settings_zh", "settings_en_130"]
|
|
const VIEWPORT_SIZE := Vector2i(844, 390)
|
|
|
|
var output_root := ""
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
output_root = OS.get_environment("ABG_P9_0R8_CAPTURE_ROOT")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-p9-0r8-front-door"
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
var viewport := SubViewport.new()
|
|
viewport.size = VIEWPORT_SIZE
|
|
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
|
root.add_child(viewport)
|
|
var game := MainScene.instantiate()
|
|
game.auto_boot = false
|
|
game.audio_enabled = false
|
|
viewport.add_child(game)
|
|
await settle(12)
|
|
for index in range(STATES.size()):
|
|
apply_state(game, STATES[index])
|
|
game.render()
|
|
await settle(7)
|
|
verify_interactive_bounds(game, Rect2(Vector2.ZERO, Vector2(VIEWPORT_SIZE)), STATES[index])
|
|
await RenderingServer.frame_post_draw
|
|
var image := viewport.get_texture().get_image()
|
|
var path := output_root.path_join("%02d-%s.png" % [index + 1, STATES[index]])
|
|
var error := image.save_png(path)
|
|
if error != OK:
|
|
failures.append("capture %s failed with %s" % [STATES[index], error])
|
|
game.queue_free()
|
|
viewport.queue_free()
|
|
await settle(100)
|
|
if failures.is_empty():
|
|
print("ABG_P9_0R8_FRONT_DOOR_CAPTURE_OK frames=6 viewport=844x390 locales=zh_CN,en text_130=true min_touch=44 root=%s" % output_root)
|
|
call_deferred("finish", 0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
call_deferred("finish", 1)
|
|
|
|
|
|
func apply_state(game: Control, state_name: String) -> void:
|
|
game.clear_experience()
|
|
game.locale = "zh_CN"
|
|
game.text_scale = 1.0
|
|
game.reduced_motion = false
|
|
game.muted = true
|
|
game.boot_verified = true
|
|
game.boot_index = game.active_boot_paths().size()
|
|
match state_name:
|
|
"boot_ready":
|
|
game.page = game.AppPage.BOOT
|
|
"title":
|
|
game.page = game.AppPage.TITLE
|
|
"main_menu":
|
|
game.page = game.AppPage.MAIN_MENU
|
|
"introduction":
|
|
game.page = game.AppPage.GAME_INTRO
|
|
"settings_zh":
|
|
game.page = game.AppPage.SETTINGS
|
|
"settings_en_130":
|
|
game.locale = "en"
|
|
game.text_scale = 1.3
|
|
game.reduced_motion = true
|
|
game.muted = false
|
|
game.page = game.AppPage.SETTINGS
|
|
|
|
|
|
func verify_interactive_bounds(node: Node, bounds: Rect2, label: String) -> void:
|
|
if node is BaseButton and node.is_visible_in_tree():
|
|
var rect: Rect2 = node.get_global_rect()
|
|
if rect.position.x < -0.5 or rect.position.y < -0.5 or rect.end.x > bounds.end.x + 0.5 or rect.end.y > bounds.end.y + 0.5:
|
|
failures.append("%s button %s outside viewport: %s" % [label, node.name, rect])
|
|
if rect.size.x < 44.0 or rect.size.y < 44.0:
|
|
failures.append("%s button %s below 44px: %s" % [label, node.name, rect.size])
|
|
for child in node.get_children():
|
|
verify_interactive_bounds(child, bounds, label)
|
|
|
|
|
|
func finish(exit_code: int) -> void:
|
|
quit(exit_code)
|
|
|
|
|
|
func settle(frames: int) -> void:
|
|
for frame in range(frames):
|
|
await process_frame
|