Files
aetherbound-guild/runtime/tests/p9_9/full_runtime_touch_test.gd
T

131 lines
4.8 KiB
GDScript

extends SceneTree
const Controller = preload("res://p9_9/runtime_controller.gd")
const Fixture = preload("res://tests/p9_9/runtime_fixture.gd")
const VIEWPORT := Vector2i(844, 390)
var failures: Array[String] = []
var experience
var parsed_touches := 0
var parsed_drags := 0
var feedback_kinds := {}
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> void:
await mount(Fixture.closed_p98())
await tap("P99CharterPacketTarget_CH-RG01-CATALOG-01")
await tap("P99CharterPacketTarget_CH-RG01-CATALOG-01")
expect(experience.market != null and experience.market.state.selected_charter_claim_id == "CH-RG01-CATALOG-01", "Charter commits through two parsed touches")
await neutral_drag()
for recruit_id in ["P99-D1", "P99-D3"]:
await tap("P99DraftTarget_%s" % recruit_id)
await tap("P99DraftTarget_%s" % recruit_id)
expect(experience.market.state.selected_provisional_ids == ["P99-D1", "P99-D3"], "two standing actors are selected")
await tap("P99ConfirmRunButton")
expect(experience.market.state.run_created and experience.market.state.coin == 52, "confirmation creates Market 1")
for recruit_id in ["P99-M1-H1", "P99-M1-H2"]:
await tap("P99HireTarget_%s" % recruit_id)
await tap("P99HireTarget_%s" % recruit_id)
expect(experience.market.state.company.size() == 4 and experience.market.state.deployed_recruit_ids.size() == 4, "two paid actor hires trigger automatic formation")
for round_index in range(1, 4):
var route_id := "P99-R%d-Q0" % round_index
await tap("P99RouteTarget_%s" % route_id)
await tap("P99RouteTarget_%s" % route_id)
expect(experience.battle_active, "Round %d starts through its gate" % round_index)
var guard := 0
while not experience.battle.state.terminal and guard < 1800:
experience.advance_battle_ticks(1)
guard += 1
expect(guard < 1800 and experience.battle_result_visible, "Round %d reaches visible result" % round_index)
await settle_frames()
for kind in experience.presented_event_counts:
feedback_kinds[kind] = int(feedback_kinds.get(kind, 0)) + int(experience.presented_event_counts[kind])
await tap("P97SettleButton")
expect(experience.market.state.current_market == 4 and experience.market.state.line_capacity == 5, "three touched Rounds reach Market 4")
expect(experience.find_child("P99MarketFourTitle", true, false) != null, "Market 4 continuation is visible")
expect(int(feedback_kinds.get("member_action", 0)) > 0 and int(feedback_kinds.get("enemy_action", 0)) > 0 and int(feedback_kinds.get("enemy_rule", 0)) > 0, "combat feedback is bound to authoritative actions and rules")
experience.queue_free()
for _index in 45:
await process_frame
if failures.is_empty():
print("ABG_P9_9_FULL_RUNTIME_TOUCH_OK touch=%d drag=%d fallback=0 direct=0 charter=catalog draft=2of4 hires=2 formation=automatic rounds=3 feedback=attack,heal,projectile,push,damage market4=true controls=48 cards=0" % [parsed_touches, parsed_drags])
quit(0)
else:
for failure in failures:
push_error(failure)
quit(1)
func mount(snapshot: Dictionary) -> 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.persistence_enabled = false
experience.battle_auto_advance = false
experience.size = Vector2(VIEWPORT)
experience.configure_entry(snapshot)
root.add_child(experience)
await settle_frames()
func tap(node_name: String) -> void:
var control := experience.find_child(node_name, true, false) as Control
expect(control != null, "%s exists before parsed touch" % 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 process_frame
var up := InputEventScreenTouch.new()
up.index = 0
up.position = point
up.pressed = false
Input.parse_input_event(up)
await settle_frames()
func neutral_drag() -> void:
var down := InputEventScreenTouch.new()
down.index = 1
down.position = Vector2(300, 64)
down.pressed = true
Input.parse_input_event(down)
await process_frame
var drag := InputEventScreenDrag.new()
drag.index = 1
drag.position = Vector2(360, 64)
drag.relative = Vector2(60, 0)
Input.parse_input_event(drag)
parsed_drags += 1
await process_frame
var up := InputEventScreenTouch.new()
up.index = 1
up.position = drag.position
up.pressed = false
Input.parse_input_event(up)
await settle_frames()
func settle_frames() -> void:
await process_frame
await process_frame
await process_frame
await process_frame
func expect(condition: bool, message: String) -> void:
if not condition:
failures.append("P9.9 runtime touch: %s" % message)