extends SceneTree const EntryShell = preload("res://entry/entry_shell.gd") const SettingsStore = preload("res://entry/settings_store.gd") const DraftService = preload("res://entry/initial_company_draft_service.gd") const ContractService = preload("res://entry/guild_contract_service.gd") const FormationService = preload("res://entry/formation_risk_service.gd") const BattleService = preload("res://entry/battle_service.gd") const DRAFT_PATH := "user://dev5_battle_opening_draft.json" const COMPANY_PATH := "user://dev5_battle_opening_company.json" const SEED := "102030405060708090a0b0c0d0e0f000" const CONTRACT_OP := "abcdefabcdefabcdefabcdefabcdefab" const HIRE_OP_1 := "11112222333344445555666677778888" const HIRE_OP_2 := "88887777666655554444333322221111" const ORDER_OP := "fedcbafedcbafedcbafedcbafedcbafe" const READY_OP := "1234567890abcdef1234567890abcdef" const BATTLE_OP := "0123456789abcdef0123456789abcdef" var failures: Array[String] = [] var parsed_touches := 0 func _initialize() -> void: call_deferred("run_test") func run_test() -> void: _cleanup() root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND root.size = Vector2i(844, 390) var prepared := _create_prepared_company() if prepared.is_empty(): _fail("fixture creates a prepared Company") else: await _verify_opening(prepared) _cleanup() if failures.is_empty(): print("ABG_DEV5_BATTLE_OPENING_OK static=true actors=4 enemies=3 compact_field=true objective=true no_respawn=true no_reserve=true explicit_start=true phase_before=0 phase_after_handoff=0 receipt_count=1 duplicate_handoff=true settings_return=true parsed_touch=%d text_100=true" % parsed_touches) quit(0) else: for failure in failures: push_error(failure) quit(1) func _verify_opening(company: Dictionary) -> void: var settings := SettingsStore.new().defaults() settings.setup_completed = true settings.locale = "zh_CN" settings.text_scale = 1.0 var shell := EntryShell.new() shell.auto_start = false shell.initial_company_service.path = DRAFT_PATH shell.initial_company_service.company_path = COMPANY_PATH root.add_child(shell) await _frames(3) _expect(shell.app_services.has_service(&"battle_opening_page_controller"), "AppServices registers Battle Opening controller") shell.settings = settings shell.setup_draft = settings.duplicate(true) shell.risk_selected_id = String(company.active_contract.formation.risk_options[1].risk_option_id) shell.show_risk_commitment(company) await _frames(2) var acknowledge := shell.find_child("RiskCommitmentAcknowledge", true, false) as Button await _touch(acknowledge) var begin := shell.find_child("RiskBeginBattle", true, false) as Button await _touch(begin) await _frames(3) _expect(shell.current_screen == "battle" and shell.battle_opening_mode, "Risk Commitment opens static BAT-001") _expect(shell.battle_opening_view_data.ok and shell.battle_opening_view_data.page_id == "battle_opening", "controller snapshot reaches BAT-001 View") _expect(shell.battle_opening_view_data.state.phase_zero and shell.battle_opening_view_data.commands.start_observation_enabled, "controller preserves phase-zero and explicit handoff boundary") _expect(shell.find_child("BattleOpeningCanvas", true, false) != null, "contained Battle Opening canvas exists") _expect(shell.find_child("BattleOpeningArt", true, false) != null, "accepted field/rail art layer exists") var actors := shell.find_child("BattleActors", true, false) var enemies := shell.find_child("BattleEnemies", true, false) _expect(actors != null and actors.get_child_count() == 4, "exact four bound Party actors render") _expect(enemies != null and enemies.get_child_count() == 3, "exact committed enemy offer renders") _expect(shell.find_child("BattleOpeningObjective", true, false) != null, "objective is engine-owned") _expect(shell.find_child("BattleOpeningNoRespawn", true, false) != null, "no combat respawn rule is visible") _expect(shell.find_child("BattleOpeningNoReserve", true, false) != null, "no Reserve auto-entry rule is visible") _expect(shell.find_child("BattleOpeningSnapshotHash", true, false) != null, "immutable snapshot identity is visible") _expect(shell.find_child("BattleStartObservation", true, false) != null and not (shell.find_child("BattleStartObservation", true, false) as Button).disabled, "Start Observation is explicit and enabled") _expect(shell.battle_playback_timer == null and shell.find_child("BattleCurrentEvent", true, false) == null, "BAT-001 does not start a timeline") var before := _battle_snapshot() await _touch(shell.find_child("BattlePause", true, false) as Button) await _touch(shell.find_child("BattleSpeed", true, false) as Button) var after_review := _battle_snapshot() _expect(int(before.get("phase_index", -1)) == 0 and int(after_review.get("phase_index", -1)) == 0, "opening review controls do not advance time") var inspect := shell.find_child("BattleInspectOpening", true, false) as Button await _touch(inspect) _expect(shell.find_child("BattleOpeningReason", true, false) != null, "inspection reason remains in the authored slot") shell._battle_open_settings() await _frames(2) _expect(shell.current_screen == "settings", "Settings opens from BAT-001") shell.request_settings_back() await _frames(3) _expect(shell.current_screen == "battle" and shell.battle_opening_mode, "Settings returns to BAT-001 without changing state") var start := shell.find_child("BattleStartObservation", true, false) as Button await _touch(start) await _frames(3) _expect(shell.current_screen == "battle" and not shell.battle_opening_mode, "explicit Start Observation reaches BAT-002") _expect(shell.find_child("BattleLiveCanvas", true, false) != null, "handoff opens the contained live-battle field") _expect(not shell.battle_live_observation.is_empty() and not String(shell.battle_live_observation.get("receipt_hash", "")).is_empty(), "handoff binds the original battle receipt") var persisted := _battle_snapshot() _expect(int(persisted.get("phase_index", -1)) == 0, "handoff does not advance a hidden tick") _expect(int(persisted.get("receipt_count", 0)) == 1, "handoff does not create a second receipt") shell.start_observation_handoff() var duplicate := _battle_snapshot() _expect(int(duplicate.get("receipt_count", 0)) == 1 and int(duplicate.get("phase_index", -1)) == 0, "duplicate handoff is idempotent") shell.queue_free() await _timer_seconds(0.2) func _battle_snapshot() -> Dictionary: var loaded: Dictionary = _battle_service().load_company() if not loaded.ok: return {} var battle: Dictionary = loaded.company.active_contract.get("battle_state", {}) return {"phase_index": int(battle.get("phase_index", -1)), "receipt_count": loaded.company.active_contract.get("battle_receipts", []).size()} func _create_prepared_company() -> Dictionary: var draft: Dictionary = _draft_service().begin_or_load(SEED) if not draft.ok: return {} _draft_service().set_selection([String(draft.draft.offers[0].offer_id), String(draft.draft.offers[2].offer_id)]) if not _draft_service().commit_company().ok: return {} var created: Dictionary = _contract_service().create_contract(CONTRACT_OP, "CTR-R1-01", "standard") if not created.ok: return {} var offers: Array = created.company.active_contract.market_board.recruit_offers _contract_service().hire_recruit(HIRE_OP_1, String(offers[0].source_offer_id), 14) if not _contract_service().hire_recruit(HIRE_OP_2, String(offers[1].source_offer_id), 14).ok: return {} var begun: Dictionary = _formation_service().begin_formation() var saved: Dictionary = _formation_service().save_order(ORDER_OP, begun.formation.base_front_to_rear_ids) var ready: Dictionary = _formation_service().accept_readiness(READY_OP, String(saved.receipt.order_hash)) return ready.company if ready.ok else {} func _draft_service() -> RefCounted: var service := DraftService.new() service.path = DRAFT_PATH service.company_path = COMPANY_PATH return service func _contract_service() -> RefCounted: var service := ContractService.new() service.company_path = COMPANY_PATH return service func _formation_service() -> RefCounted: var service := FormationService.new() service.company_path = COMPANY_PATH return service func _battle_service() -> RefCounted: var service := BattleService.new() service.company_path = COMPANY_PATH return service func _touch(control: Control) -> void: if control == null: _fail("touch target exists") return var center := control.get_global_rect().get_center() var press := InputEventScreenTouch.new() press.position = center press.pressed = true press.index = 0 Input.parse_input_event(press) await _frames(2) var release := InputEventScreenTouch.new() release.position = center release.pressed = false release.index = 0 Input.parse_input_event(release) parsed_touches += 1 await _frames(5) func _frames(count: int) -> void: for _index in range(count): await process_frame func _timer_seconds(seconds: float) -> void: await create_timer(seconds).timeout func _cleanup() -> void: for path in [DRAFT_PATH, "%s.bak" % DRAFT_PATH, "%s.candidate" % DRAFT_PATH, "%s.bak.candidate" % DRAFT_PATH, COMPANY_PATH, "%s.bak" % COMPANY_PATH, "%s.candidate" % COMPANY_PATH, "%s.bak.candidate" % COMPANY_PATH, "%s.corrupt" % COMPANY_PATH]: if FileAccess.file_exists(path): DirAccess.remove_absolute(path) func _expect(condition: bool, message: String) -> void: if not condition: _fail(message) func _fail(message: String) -> void: failures.append("BAT-001 opening: %s" % message)