extends SceneTree const MainScene = preload("res://main.tscn") const PAGES := ["boot", "title"] 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_0_CAPTURE_ROOT") if output_root.is_empty(): output_root = "/tmp/abg-p9-0-captures" DirAccess.make_dir_recursive_absolute(output_root) var locale := OS.get_environment("ABG_P9_0_LOCALE") if not OS.get_environment("ABG_P9_0_LOCALE").is_empty() else "zh_CN" var text_scale := float(OS.get_environment("ABG_P9_0_TEXT_SCALE")) if not OS.get_environment("ABG_P9_0_TEXT_SCALE").is_empty() else 1.0 for index in range(PAGES.size()): await capture_page(index + 1, PAGES[index], locale, text_scale) if failures.is_empty(): print("ABG_P9_0_RUNTIME_CAPTURE_OK frames=2 locale=%s text_scale=%.1f input_claim=none renderer=normal root=%s" % [locale, text_scale, output_root]) quit(0) else: for failure in failures: push_error(failure) quit(1) func capture_page(index: int, page_name: String, locale: String, text_scale: float) -> void: var viewport := SubViewport.new() viewport.size = Vector2i( int(OS.get_environment("ABG_P9_0_VIEWPORT_WIDTH")) if not OS.get_environment("ABG_P9_0_VIEWPORT_WIDTH").is_empty() else 1280, int(OS.get_environment("ABG_P9_0_VIEWPORT_HEIGHT")) if not OS.get_environment("ABG_P9_0_VIEWPORT_HEIGHT").is_empty() else 720 ) viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS root.add_child(viewport) var game := MainScene.instantiate() game.auto_boot = false viewport.add_child(game) await settle() game.locale = locale game.text_scale = text_scale game.reduced_motion = true game.muted = true game.page = game.AppPage.BOOT if page_name == "boot" else game.AppPage.TITLE game.boot_verified = page_name == "title" game.render() await settle() await RenderingServer.frame_post_draw var image := viewport.get_texture().get_image() var path := output_root.path_join("%02d-%s.png" % [index, page_name]) var error := image.save_png(path) if error != OK: failures.append("capture %s failed with %s" % [page_name, error]) viewport.queue_free() await process_frame await RenderingServer.frame_post_draw await create_timer(0.5).timeout await drain_cleanup() func settle() -> void: for frame in range(8): await process_frame func drain_cleanup() -> void: for frame in range(30): await process_frame