134 lines
4.7 KiB
GDScript
134 lines
4.7 KiB
GDScript
extends SceneTree
|
|
|
|
const MainScene = preload("res://main.tscn")
|
|
const STATES := ["victory_counter", "adaptation_exposed", "adaptation_safe", "battle_counter", "battle_healing", "result_safe_counter", "result_tempo_healing", "result_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_0R10_CAPTURE_ROOT")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-p9-0r10-pair-adaptation"
|
|
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_0R10_PAIR_ADAPTATION_CAPTURE_OK frames=8 viewport=844x390 pairs=standard,counter,exposed_healing 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.coin = 20
|
|
game.first_reward_committed = true
|
|
match state_name:
|
|
"victory_counter":
|
|
prepare_pair(game, ["Hearthguard", "Wayrunner"])
|
|
game.page = game.AppPage.VICTORY
|
|
game.front_hp = 82
|
|
game.enemy_hp = 0
|
|
"adaptation_exposed":
|
|
prepare_pair(game, ["Farstring", "Kindhand"])
|
|
game.page = game.AppPage.ADAPTATION
|
|
"adaptation_safe":
|
|
prepare_pair(game, ["Farstring", "Kindhand"])
|
|
game.adaptation_choice = "EQ-002"
|
|
game.page = game.AppPage.ADAPTATION
|
|
"battle_counter":
|
|
prepare_battle(game, ["Hearthguard", "Wayrunner"], "EQ-002", 3, 90, 70, "侧翼反击", "flank counter")
|
|
"battle_healing":
|
|
prepare_battle(game, ["Farstring", "Kindhand"], "EQ-061", 3, 82, 72, "治疗", "healing")
|
|
"result_safe_counter":
|
|
prepare_result(game, ["Hearthguard", "Wayrunner"], "EQ-002", 90, 7.05)
|
|
"result_tempo_healing":
|
|
prepare_result(game, ["Farstring", "Kindhand"], "EQ-061", 82, 6.00)
|
|
"result_en_130":
|
|
game.locale = "en"
|
|
game.text_scale = 1.3
|
|
prepare_result(game, ["Wayrunner", "Farstring"], "EQ-061", 70, 6.00)
|
|
|
|
|
|
func prepare_pair(game: Control, recruits: Array) -> void:
|
|
game.selected_recruits.assign(recruits)
|
|
game.assign_automatic_formation()
|
|
|
|
|
|
func prepare_battle(game: Control, recruits: Array, item: String, phase: int, lead_hp: int, enemy_health: int, qualifier_zh: String, qualifier_en: String) -> void:
|
|
prepare_pair(game, recruits)
|
|
game.page = game.AppPage.SECOND_BATTLE
|
|
game.adaptation_choice = item
|
|
game.adaptation_committed = true
|
|
game.battle_phase = phase
|
|
game.battle_clock = 0.16
|
|
game.front_hp = lead_hp
|
|
game.enemy_hp = enemy_health
|
|
game.battle_playing = false
|
|
game.emit_battle_feedback(phase, "front" if qualifier_zh == "治疗" else "enemy", 12 if qualifier_zh == "治疗" else -30, qualifier_zh, qualifier_en, "medium")
|
|
game.battle_feedback_clock = 0.16
|
|
|
|
|
|
func prepare_result(game: Control, recruits: Array, item: String, lead_hp: int, elapsed: float) -> void:
|
|
prepare_pair(game, recruits)
|
|
game.page = game.AppPage.SECOND_RESULT
|
|
game.adaptation_choice = item
|
|
game.adaptation_committed = true
|
|
game.front_hp = lead_hp
|
|
game.enemy_hp = 0
|
|
game.second_result_time = elapsed
|
|
|
|
|
|
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
|