Files
aetherbound-guild/runtime/tests/p10_0/runtime_front_door_test.gd
T

94 lines
4.1 KiB
GDScript

extends SceneTree
const Controller = preload("res://p10_0/runtime_controller.gd")
const VIEWPORT := Vector2i(844, 390)
var failures: Array[String] = []
var experience
var parsed_touches := 0
func _initialize() -> void:
call_deferred("run_test")
func run_test() -> 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)
root.add_child(experience)
await settle_frames()
expect(experience.screen == "title" and experience.find_child("P100Title", true, false) != null, "fresh runtime opens the game Title")
expect(experience.find_child("P100NewExpeditionButton", true, false) != null, "Title exposes one New Expedition action")
expect(experience.find_children("*", "Panel", true, false).is_empty(), "Title uses no app Panel surfaces")
await tap("P100Difficulty_wayfinder")
expect(experience.selected_difficulty == "wayfinder", "difficulty changes through parsed touch")
await tap("P100NewExpeditionButton")
expect(experience.screen == "opening" and experience.market.state.run_creation_draft.opening_offers.size() == 4, "New Expedition opens four fixed provisional Recruits")
var ids: Array[String] = []
for offer in experience.market.state.run_creation_draft.opening_offers:
ids.append(String(offer.source_offer_id))
await tap("P100OpeningTarget_%s" % ids[0])
await tap("P100OpeningTarget_%s" % ids[1])
expect(experience.opening_selection == [ids[0], ids[1]], "two touches select exactly two Recruits")
await tap("P100CommitRunButton")
expect(experience.screen == "market" and int(experience.market.state.current_run.market_index) == 1, "Company commit opens canonical Market 1")
expect(experience.market.state.current_run.company.size() == 2 and experience.market.state.current_run.deployed_recruit_ids.size() == 2, "automatic formation orders the chosen pair")
expect(experience.find_children("P100RecruitTarget_*", "Button", true, false).size() == 3, "Market shows three Recruit world targets")
expect(experience.find_children("P100EquipmentTarget_*", "Button", true, false).size() == 4, "Market shows four equipment world targets")
expect(experience.find_children("P100BattleTarget_*", "Button", true, false).size() == 3, "Market shows three disclosed risk gates")
await tap("P100SettingsButton")
expect(experience.settings_open and experience.find_child("P100SettingsBand", true, false) != null, "Settings remains reachable from Market")
await tap("P100CloseSettingsButton")
expect(not experience.settings_open and experience.find_child("P100SettingsBand", true, false) == null, "Settings returns to the same Market")
expect(experience.input_touch_count == parsed_touches and parsed_touches == 7, "all front-door commands use parsed ScreenTouch")
experience.queue_free()
for _index in 45:
await process_frame
if failures.is_empty():
print("ABG_P10_0_RUNTIME_FRONT_DOOR_OK title=true difficulty=wayfinder opening=4 selected=2 market=3,4,3 formation=automatic settings=true touch=%d fallback=0 direct=0 panels=0" % parsed_touches)
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 before 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 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("P10.0 runtime front door: %s" % message)