135 lines
4.8 KiB
GDScript
135 lines
4.8 KiB
GDScript
extends SceneTree
|
|
|
|
const Controller = preload("res://campaign/fg2_graybox_controller.gd")
|
|
const Fixture = preload("res://campaign/fg2_fixture.gd")
|
|
|
|
const VIEWPORT := Vector2i(844, 390)
|
|
const MIN_CONTENT_FRAMES := 450
|
|
const TARGET_CONTENT_FRAMES := 570
|
|
const MAX_CONTENT_FRAMES := 900
|
|
|
|
var failures: Array[String] = []
|
|
var experience
|
|
var parsed_touches := 0
|
|
var parsed_drags := 0
|
|
var recording_frames := 0
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_recording")
|
|
|
|
|
|
func run_recording() -> void:
|
|
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
|
|
experience = Controller.new()
|
|
experience.battle_auto_advance = false
|
|
experience.size = Vector2(VIEWPORT)
|
|
experience.configure_entry(Fixture.canonical_market_state())
|
|
root.add_child(experience)
|
|
await hold(60)
|
|
var order: Array = Array(experience.adapter.market.state.current_run.deployed_recruit_ids).duplicate()
|
|
await drag("FG2CompanyTarget_%s" % String(order[-1]), "FG2CompanyTarget_%s" % String(order[0]))
|
|
await hold(30)
|
|
var route_id := Fixture.route_id(experience.adapter.snapshot(), 0)
|
|
await tap("FG2Route_%s" % route_id)
|
|
await hold(30)
|
|
await tap("FG2DepartButton")
|
|
while not experience.battle_result_visible and recording_frames < 650:
|
|
experience.advance_battle_ticks(3)
|
|
await next_frame()
|
|
await hold(45)
|
|
if experience.battle_result_visible:
|
|
await tap("FG2SettleButton")
|
|
await hold(45)
|
|
if experience.screen == Controller.SCREEN_REWARD:
|
|
await tap("FG2RewardButton")
|
|
while recording_frames < TARGET_CONTENT_FRAMES:
|
|
await next_frame()
|
|
expect(recording_frames >= MIN_CONTENT_FRAMES and recording_frames <= MAX_CONTENT_FRAMES, "recording stays inside the 15-30 second fixed-fps window")
|
|
expect(experience.screen == Controller.SCREEN_MARKET and int(experience.view.market_index) == 2, "recording ends on visible saved Market 2")
|
|
expect(experience.persistent_change_visible, "recording ends with a persistent world change")
|
|
for kind in ["wave_arrived", "damage", "outcome"]:
|
|
expect(int(experience.presented_event_counts.get(kind, 0)) > 0, "recording presents %s" % kind)
|
|
expect(experience.input_touch_count == parsed_touches and experience.input_drag_count == parsed_drags, "recording commands are parsed touch/drag only")
|
|
expect(experience.fallback_input_count == 0 and experience.direct_command_count == 0, "recording has no fallback or direct player command")
|
|
await hold(45)
|
|
expect(recording_frames <= MAX_CONTENT_FRAMES, "cleanup hold preserves the final Market frame inside 30 seconds")
|
|
if failures.is_empty():
|
|
print("ABG_FG2_GRAYBOX_RECORDING_OK frames=%d seconds=%.6f touch=%d drag=%d fallback=0 direct=0 grid=422x195@2x battle=authoritative reward=coin terminal=market2" % [recording_frames, float(recording_frames) / 30.0, parsed_touches, parsed_drags])
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func tap(node_name: String) -> void:
|
|
var control := experience.find_child(node_name, true, false) as Control
|
|
expect(control != null, "%s exists" % node_name)
|
|
if control == null:
|
|
return
|
|
var point := root.get_final_transform() * control.get_global_rect().get_center()
|
|
var down := InputEventScreenTouch.new()
|
|
down.index = 0
|
|
down.position = point
|
|
down.pressed = true
|
|
Input.parse_input_event(down)
|
|
parsed_touches += 1
|
|
await next_frame()
|
|
var up := InputEventScreenTouch.new()
|
|
up.index = 0
|
|
up.position = point
|
|
up.pressed = false
|
|
Input.parse_input_event(up)
|
|
await hold(4)
|
|
|
|
|
|
func drag(source_name: String, target_name: String) -> void:
|
|
var source := experience.find_child(source_name, true, false) as Control
|
|
var target := experience.find_child(target_name, true, false) as Control
|
|
expect(source != null and target != null, "recording drag targets exist")
|
|
if source == null or target == null:
|
|
return
|
|
var start := root.get_final_transform() * source.get_global_rect().get_center()
|
|
var finish := root.get_final_transform() * target.get_global_rect().get_center()
|
|
var down := InputEventScreenTouch.new()
|
|
down.index = 1
|
|
down.position = start
|
|
down.pressed = true
|
|
Input.parse_input_event(down)
|
|
parsed_touches += 1
|
|
await next_frame()
|
|
for index in range(1, 7):
|
|
var motion := InputEventScreenDrag.new()
|
|
motion.index = 1
|
|
motion.position = start.lerp(finish, float(index) / 6.0)
|
|
motion.relative = (finish - start) / 6.0
|
|
Input.parse_input_event(motion)
|
|
if index == 1:
|
|
parsed_drags += 1
|
|
await next_frame()
|
|
var up := InputEventScreenTouch.new()
|
|
up.index = 1
|
|
up.position = finish
|
|
up.pressed = false
|
|
Input.parse_input_event(up)
|
|
await hold(4)
|
|
|
|
|
|
func hold(frames: int) -> void:
|
|
for _index in frames:
|
|
await next_frame()
|
|
|
|
|
|
func next_frame() -> void:
|
|
recording_frames += 1
|
|
await process_frame
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("FG-2 graybox recording: %s" % message)
|