130 lines
4.3 KiB
GDScript
130 lines
4.3 KiB
GDScript
extends SceneTree
|
|
|
|
const MainScene = preload("res://main.tscn")
|
|
const STATES := ["guild_unselected", "guild_recruit_selected", "third_retain", "third_recruit_action", "result_retain", "result_recruit"]
|
|
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_0R5_CAPTURE_ROOT")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-p9-0r5-preview"
|
|
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)
|
|
game.locale = "zh_CN"
|
|
game.text_scale = 1.0
|
|
game.reduced_motion = false
|
|
game.muted = true
|
|
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(120)
|
|
if failures.is_empty():
|
|
print("ABG_P9_0R5_PREVIEW_CAPTURE_OK frames=6 viewport=844x390 locale=zh_CN 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.front_choice = "Hearthguard"
|
|
game.rear_choice = "Farstring"
|
|
game.coin = 20
|
|
game.first_reward_committed = true
|
|
game.adaptation_choice = "EQ-002"
|
|
game.adaptation_committed = true
|
|
match state_name:
|
|
"guild_unselected":
|
|
game.page = game.AppPage.GUILD_RETURN
|
|
"guild_recruit_selected":
|
|
game.page = game.AppPage.GUILD_RETURN
|
|
game.guild_choice = "recruit_rear"
|
|
"third_retain":
|
|
prepare_third(game, "retain_item", "EQ-002", "", 2, 90, 130)
|
|
game.emit_battle_feedback(2, "front", -10, "装备抗推", "item resisted", "medium")
|
|
game.battle_feedback_clock = 0.16
|
|
"third_recruit_action":
|
|
prepare_third(game, "recruit_rear", "", "Kindhand", 4, 82, 94)
|
|
game.emit_battle_feedback(4, "front", 12, "新治疗支援", "new Healer support", "medium")
|
|
game.battle_feedback_clock = 0.16
|
|
"result_retain":
|
|
game.page = game.AppPage.SESSION_RESULT
|
|
game.guild_choice = "retain_item"
|
|
game.guild_committed = true
|
|
game.retained_item = "EQ-002"
|
|
game.coin = 8
|
|
game.front_hp = 90
|
|
game.enemy_hp = 0
|
|
game.third_result_time = 7.60
|
|
"result_recruit":
|
|
game.page = game.AppPage.SESSION_RESULT
|
|
game.guild_choice = "recruit_rear"
|
|
game.guild_committed = true
|
|
game.added_rear = "Kindhand"
|
|
game.coin = 6
|
|
game.front_hp = 82
|
|
game.enemy_hp = 0
|
|
game.third_result_time = 7.00
|
|
|
|
|
|
func prepare_third(game: Control, choice: String, item: String, recruit: String, phase: int, front_health: int, enemy_health: int) -> void:
|
|
game.page = game.AppPage.THIRD_BATTLE
|
|
game.guild_choice = choice
|
|
game.guild_committed = true
|
|
game.retained_item = item
|
|
game.added_rear = recruit
|
|
game.coin = 8 if choice == "retain_item" else 6
|
|
game.battle_playing = false
|
|
game.battle_phase = phase
|
|
game.battle_clock = 0.22
|
|
game.front_hp = front_health
|
|
game.enemy_hp = enemy_health
|
|
|
|
|
|
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
|