Files
aetherbound-guild/runtime/tests/p9_1_fixture_capture.gd
T

108 lines
3.2 KiB
GDScript

extends SceneTree
const MainScene = preload("res://main.tscn")
const STATES := ["contract", "offers", "market", "equipment", "order", "ready"]
var game: Control
var capture_viewport: SubViewport
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_1_CAPTURE_ROOT")
if output_root.is_empty():
output_root = "/tmp/abg-p9-1-fixture-captures"
DirAccess.make_dir_recursive_absolute(output_root)
var locale := OS.get_environment("ABG_P9_1_LOCALE") if not OS.get_environment("ABG_P9_1_LOCALE").is_empty() else "zh_CN"
var text_scale := float(OS.get_environment("ABG_P9_1_TEXT_SCALE")) if not OS.get_environment("ABG_P9_1_TEXT_SCALE").is_empty() else 1.0
for index in range(STATES.size()):
await capture_state(index + 1, STATES[index], locale, text_scale)
if failures.is_empty():
print("ABG_P9_1_FIXTURE_CAPTURE_OK frames=6 locale=%s text_scale=%.1f input_claim=none setup=domain_fixture root=%s" % [locale, text_scale, output_root])
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func capture_state(index: int, state: String, locale: String, text_scale: float) -> void:
capture_viewport = SubViewport.new()
capture_viewport.size = Vector2i(
int(OS.get_environment("ABG_P9_1_VIEWPORT_WIDTH")) if not OS.get_environment("ABG_P9_1_VIEWPORT_WIDTH").is_empty() else 1280,
int(OS.get_environment("ABG_P9_1_VIEWPORT_HEIGHT")) if not OS.get_environment("ABG_P9_1_VIEWPORT_HEIGHT").is_empty() else 720
)
capture_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
capture_viewport.transparent_bg = false
root.add_child(capture_viewport)
game = MainScene.instantiate()
game.auto_boot = false
capture_viewport.add_child(game)
await settle()
game.boot_verified = true
game.page = game.AppPage.RUN
game.locale = locale
game.text_scale = text_scale
game.reduced_motion = true
game.muted = true
advance_to(state)
game.render()
await settle()
await RenderingServer.frame_post_draw
var image := capture_viewport.get_texture().get_image()
var path := output_root.path_join("%02d-%s.png" % [index, state])
var error := image.save_png(path)
if error != OK:
failures.append("capture %s failed with %s" % [state, error])
game.queue_free()
game = null
capture_viewport.queue_free()
capture_viewport = null
await drain_cleanup()
func advance_to(target: String) -> void:
if target == "contract":
return
game.run.select_contract()
game.run.select_difficulty("standard")
game.run.open_offers()
for id in ["OFF-01", "OFF-02", "OFF-03", "OFF-04"]:
game.run.inspect_offer(id)
game.run.toggle_offer("OFF-03")
game.run.toggle_offer("OFF-04")
if target == "offers":
return
game.run.review_opening()
game.run.commit_opening()
game.run.open_market()
if target == "market":
return
game.run.hire("MKT-R1-01")
game.run.hire("MKT-R1-02")
if target == "equipment":
return
game.run.purchase_equipment()
game.run.equip_member("OFF-03")
if target == "order":
return
game.run.choose_order_unit("OFF-03")
game.run.choose_order_unit("MKT-R1-01")
game.run.commit_order()
func settle() -> void:
for frame in range(8):
await process_frame
func drain_cleanup() -> void:
for frame in range(30):
await process_frame