Files
aetherbound-guild/runtime/tests/fg3/campaign_runtime_capture.gd
T

135 lines
3.9 KiB
GDScript

extends SceneTree
const Controller = preload("res://campaign/fg3_runtime_controller.gd")
const Fixture = preload("res://tests/fg3/contract1_fixture.gd")
const VIEWPORT := Vector2i(844, 390)
var failures: Array[String] = []
var experience
var output_dir := ""
var captures: Array[Dictionary] = []
func _initialize() -> void:
call_deferred("run_capture")
func run_capture() -> void:
output_dir = OS.get_environment("ABG_FG3_CAPTURE_DIR")
if output_dir.is_empty():
output_dir = ProjectSettings.globalize_path("user://fg3-captures")
DirAccess.make_dir_recursive_absolute(output_dir)
root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND
root.content_scale_size = VIEWPORT
root.size = VIEWPORT
await capture_market_plan_and_battle()
await capture_first_boss_and_record()
await capture_second_boss_and_close()
if is_instance_valid(experience):
experience.queue_free()
for _index in 45:
await process_frame
if failures.is_empty():
var manifest := {
"kind": "abg-fg3-development-captures",
"viewport": [VIEWPORT.x, VIEWPORT.y],
"captures": captures,
}
var file := FileAccess.open(output_dir.path_join("capture-manifest.json"), FileAccess.WRITE)
file.store_string(JSON.stringify(manifest, " ") + "\n")
file.close()
print("ABG_FG3_CAMPAIGN_CAPTURE_OK frames=%d viewport=844x390 root=%s" % [captures.size(), output_dir])
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func capture_market_plan_and_battle() -> void:
await mount(Fixture.new().fg3_market_8_snapshot())
await capture("01-market8")
experience._depart_pressed()
await settle_frames()
await capture("02-route-plan")
experience._depart_pressed()
await settle_frames()
experience.advance_battle_ticks(5)
await settle_frames()
await capture("03-ordinary-battle")
func capture_first_boss_and_record() -> void:
await mount(Fixture.new().boss_muster_snapshot())
await capture("04-boss1-muster")
experience._depart_pressed()
await settle_frames()
experience.advance_battle_ticks(3)
await settle_frames()
await capture("05-boss1-disclosure")
while not experience.battle_result_visible:
experience.advance_battle_ticks(8)
await process_frame
experience._settle_pressed()
await settle_frames()
await capture("06-contract1-record")
func capture_second_boss_and_close() -> void:
await mount(Fixture.new().contract2_boss_muster_snapshot())
await capture("07-boss2-muster")
experience._depart_pressed()
await settle_frames()
experience.advance_battle_ticks(4)
await settle_frames()
await capture("08-boss2-disclosure")
while not experience.battle_result_visible:
experience.advance_battle_ticks(8)
await process_frame
experience._settle_pressed()
await settle_frames()
await capture("09-region-record")
experience._reward_pressed()
await settle_frames()
await capture("10-rg03-unlocked")
func mount(snapshot_value: Dictionary) -> void:
if is_instance_valid(experience):
experience.queue_free()
await settle_frames(12)
experience = Controller.new()
experience.battle_auto_advance = false
experience.locale = "zh_CN"
experience.text_scale = 1.0
experience.muted = true
experience.size = Vector2(VIEWPORT)
experience.configure_entry(snapshot_value)
root.add_child(experience)
await settle_frames(10)
func capture(capture_id: String) -> void:
await RenderingServer.frame_post_draw
var image := root.get_texture().get_image()
var path := output_dir.path_join("%s.png" % capture_id)
var error := image.save_png(path)
if error != OK:
failures.append("capture %s failed: %s" % [capture_id, error])
return
captures.append({
"id": capture_id,
"path": path,
"width": image.get_width(),
"height": image.get_height(),
"mode": String(experience.view.get("mode", "")),
"screen": String(experience.screen),
})
func settle_frames(count := 6) -> void:
for _index in count:
await process_frame