329 lines
16 KiB
GDScript
329 lines
16 KiB
GDScript
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://m12_runtime_draft.json"
|
|
const COMPANY_PATH := "user://m12_runtime_company.json"
|
|
const SEED := "97531eca86420bdf97531eca86420bdf"
|
|
const CONTRACT_OP := "abcdef0123456789abcdef0123456789"
|
|
const HIRE_OP_1 := "11112222333344445555666677778888"
|
|
const HIRE_OP_2 := "88887777666655554444333322221111"
|
|
const ORDER_OP := "fedcba9876543210fedcba9876543210"
|
|
const READY_OP := "0123456789abcdef0123456789abcdef"
|
|
const BATTLE_OP := "2468ace013579bdf2468ace013579bdf"
|
|
|
|
const FIXTURES := [
|
|
{"size": Vector2i(760, 360), "locale": "zh_CN"},
|
|
{"size": Vector2i(844, 390), "locale": "en"},
|
|
{"size": Vector2i(1280, 720), "locale": "zh_CN"},
|
|
{"size": Vector2i(1280, 720), "locale": "en"},
|
|
]
|
|
|
|
var failures: Array[String] = []
|
|
var parsed_touches := 0
|
|
var fixture_count := 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
|
|
var prepared := _create_prepared_company()
|
|
_expect(not prepared.is_empty(), "fixture prepares a four-member Company")
|
|
if not prepared.is_empty():
|
|
await _run_route(prepared)
|
|
_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_M12_RUNTIME_OK route=BAT002,OUT001,OUT002,OUT003,OUT004 market=true restart=true fixtures=%d input=true targets=48 strict=0 locale=zh_CN,en scale=100" % fixture_count)
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _run_route(prepared: Dictionary) -> void:
|
|
var option_id := String(prepared.active_contract.formation.risk_options[1].risk_option_id)
|
|
var service := _battle_service()
|
|
var started: Dictionary = service.begin_battle(BATTLE_OP, option_id)
|
|
_expect(started.ok, "fixture starts one battle receipt")
|
|
if not started.ok:
|
|
return
|
|
var observed: Dictionary = service.begin_observation(BATTLE_OP, String(started.battle.snapshot_hash))
|
|
_expect(observed.ok, "BAT-002 observation opens without settlement")
|
|
if not observed.ok:
|
|
return
|
|
var shell := await _new_shell(FIXTURES[1].size, String(FIXTURES[1].locale))
|
|
shell.show_battle(observed.company, false)
|
|
shell.battle_paused = false
|
|
shell._schedule_battle_playback(shell.battle_playback_generation)
|
|
await _frames(4)
|
|
_expect(shell.current_screen == "battle" and not shell.battle_opening_mode, "BAT-002 opens the live battlefield")
|
|
_expect(shell.find_child("BattleLiveNextBoundary", true, false) != null, "BAT-002 exposes the OUT-001 boundary")
|
|
_verify_buttons(shell, FIXTURES[1].size, "live")
|
|
|
|
var guard := 0
|
|
while shell.battle_live_state != "outcome_locked" and guard < 60:
|
|
if shell.battle_paused:
|
|
shell.battle_paused = false
|
|
shell.advance_battle_phase()
|
|
await _frames(1)
|
|
guard += 1
|
|
_expect(shell.battle_live_state == "outcome_locked", "BAT-002 reaches an immutable outcome lock")
|
|
var locked_before: Dictionary = service.load_company()
|
|
_expect(locked_before.ok and String(locked_before.company.active_contract.battle_state.status) == "outcome_locked", "outcome lock persists before settlement")
|
|
var locked_observation: Dictionary = locked_before.company.active_contract.battle_state.observation if locked_before.ok else {}
|
|
var locked_hash := String(locked_observation.get("observation_hash", ""))
|
|
var next_boundary := shell.find_child("BattleLiveNextBoundary", true, false) as Button
|
|
_expect(next_boundary != null and not next_boundary.disabled, "OUT-001 boundary is actionable")
|
|
if next_boundary != null:
|
|
await _touch(next_boundary)
|
|
_expect(shell.current_screen == "battle_result", "OUT-001 opens Result after explicit settlement")
|
|
var settled: Dictionary = service.load_company()
|
|
_expect(settled.ok and String(settled.company.active_contract.battle_state.status) == "result", "settlement enters Result state")
|
|
if settled.ok:
|
|
var current_observation: Dictionary = settled.company.active_contract.battle_state.observation
|
|
_expect(String(current_observation.get("observation_hash", "")) == locked_hash, "settlement preserves the immutable observation hash")
|
|
_expect(shell.find_child("BattleResultObjective", true, false) != null, "OUT-001 binds objective")
|
|
_expect(shell.find_child("BattleResultDecisive", true, false) != null, "OUT-001 binds decisive event")
|
|
_expect(shell.find_child("BattleResultChain", true, false) != null, "OUT-001 binds causal chain")
|
|
_verify_buttons(shell, FIXTURES[1].size, "result")
|
|
var continue_button := shell.find_child("BattleResultContinue", true, false) as Button
|
|
_expect(continue_button != null and not continue_button.disabled, "Result Continue is actionable")
|
|
if continue_button != null:
|
|
await _touch(continue_button)
|
|
var battle: Dictionary = shell.guild_company.active_contract.battle_state
|
|
var knocked: Array = battle.get("result", {}).get("knocked_out_ids", [])
|
|
if not knocked.is_empty():
|
|
_expect(shell.current_screen == "battle_knockout_review", "OUT-002 opens for a knocked-out Recruit")
|
|
_expect(shell.find_child("BattleKnockoutCurrentGap", true, false) != null, "OUT-002 explains the battle-local gap")
|
|
_expect(shell.find_child("BattleKnockoutReturnRule", true, false) != null, "OUT-002 preserves the return rule")
|
|
_verify_buttons(shell, FIXTURES[1].size, "knockout")
|
|
var acknowledge := shell.find_child("BattleKnockoutAcknowledge", true, false) as Button
|
|
_expect(acknowledge != null and not acknowledge.disabled, "OUT-002 acknowledgement is actionable")
|
|
if acknowledge != null:
|
|
await _touch(acknowledge)
|
|
else:
|
|
_expect(shell.current_screen == "battle_reward_choice", "no-knockout Result routes directly to OUT-003")
|
|
if shell.current_screen == "battle_knockout_review":
|
|
_expect(shell.current_screen == "battle_reward_choice", "OUT-002 advances to OUT-003")
|
|
_expect(shell.current_screen == "battle_reward_choice", "OUT-003 reward choice is reachable")
|
|
_expect(shell.app_services.has_service(&"reward_choice_page_controller") and shell.battle_reward_view_data.ok, "OUT-003 crosses the explicit Controller/AppServices boundary")
|
|
_expect(shell.battle_reward_view_data.reward.options_count >= 2 and not shell.battle_reward_view_data.commands.claim_enabled and shell.battle_reward_view_data.commands.skip_enabled, "OUT-003 consumes controller draft and Claim/Skip facts")
|
|
_expect(shell.find_child("BattleRewardOptions", true, false) != null, "OUT-003 renders equal decision options")
|
|
var reward_buttons := _reward_buttons(shell)
|
|
_expect(reward_buttons.size() >= 2, "OUT-003 provides at least two deterministic options")
|
|
_verify_buttons(shell, FIXTURES[1].size, "reward")
|
|
if not reward_buttons.is_empty():
|
|
var first_reward := reward_buttons[0] as Button
|
|
var claim := shell.find_child("BattleRewardClaim", true, false) as Button
|
|
_expect(claim != null and claim.disabled, "Reward claim is disabled before selection")
|
|
await _touch(first_reward)
|
|
claim = shell.find_child("BattleRewardClaim", true, false) as Button
|
|
_expect(claim != null and not claim.disabled, "Reward claim enables after selection")
|
|
if claim != null:
|
|
await _touch(claim)
|
|
_expect(shell.current_screen == "battle_recovery", "OUT-003 advances to OUT-004 after one claim")
|
|
_expect(shell.app_services.has_service(&"recovery_page_controller") and shell.battle_recovery_view_data.ok, "OUT-004 crosses the explicit Controller/AppServices boundary")
|
|
_expect(shell.battle_recovery_view_data.knockouts.ids == knocked and shell.battle_recovery_view_data.commands.commit_enabled and shell.battle_recovery_view_data.continuation.target == "market", "OUT-004 consumes controller identity and Commit/Market facts")
|
|
_expect(shell.find_child("BattleRecoveryRule", true, false) != null, "OUT-004 binds recovery rule")
|
|
_verify_buttons(shell, FIXTURES[1].size, "recovery")
|
|
var recovery_commit := shell.find_child("BattleRecoveryCommit", true, false) as Button
|
|
_expect(recovery_commit != null and not recovery_commit.disabled, "OUT-004 commit is actionable")
|
|
if recovery_commit != null:
|
|
await _touch(recovery_commit)
|
|
_expect(shell.current_screen == "market", "OUT-004 opens the next-stage Market")
|
|
_expect(shell.find_child("MarketMasterCanvas", true, false) != null, "next-stage Market renders its layout")
|
|
var recovered: Dictionary = service.load_company()
|
|
_expect(recovered.ok and String(recovered.company.active_contract.status) == "market", "recovery persists Market status")
|
|
_expect(recovered.ok and recovered.company.active_contract.get("recovery_receipts", []).size() == 1, "recovery writes one receipt")
|
|
var stable_ids := _recruit_ids(prepared)
|
|
_expect(recovered.ok and _recruit_ids(recovered.company) == stable_ids, "recovery preserves Recruit identities")
|
|
for fixture in FIXTURES:
|
|
await _verify_fixture_pages(recovered.company if recovered.ok else shell.guild_company, fixture)
|
|
shell.queue_free()
|
|
await _frames(5)
|
|
var resumed_host := await _new_fixture_shell(FIXTURES[0].size, String(FIXTURES[0].locale))
|
|
var resumed: Control = resumed_host.shell
|
|
resumed._open_company_destination(recovered.company if recovered.ok else shell.guild_company)
|
|
await _frames(4)
|
|
_expect(resumed.current_screen == "market" and resumed.find_child("MarketMasterCanvas", true, false) != null, "restart resumes at the next-stage Market")
|
|
resumed.queue_free()
|
|
(resumed_host.viewport as SubViewport).queue_free()
|
|
await _frames(5)
|
|
|
|
|
|
func _verify_fixture_pages(company: Dictionary, fixture: Dictionary) -> void:
|
|
var size: Vector2i = fixture.size
|
|
var locale := String(fixture.locale)
|
|
var host := await _new_fixture_shell(size, locale)
|
|
var shell: Control = host.shell
|
|
var battle: Dictionary = company.active_contract.get("battle_state", {})
|
|
shell.show_battle_result(company)
|
|
await _frames(2)
|
|
_expect(shell.current_screen == "battle_result", "%s %s Result fits" % [size, locale])
|
|
_verify_buttons(shell, size, "result %s %s" % [size, locale])
|
|
shell.show_battle_knockout_review(company)
|
|
await _frames(2)
|
|
_verify_buttons(shell, size, "knockout %s %s" % [size, locale])
|
|
if String(battle.get("reward_draft", {}).get("status", "")) == "claimed":
|
|
# Use the same committed state to verify the post-claim recovery page.
|
|
shell.show_battle_recovery(company)
|
|
await _frames(2)
|
|
_verify_buttons(shell, size, "recovery %s %s" % [size, locale])
|
|
shell.show_market(company)
|
|
await _frames(2)
|
|
_expect(shell.current_screen == "market", "%s %s Market fits" % [size, locale])
|
|
_verify_buttons(shell, size, "market %s %s" % [size, locale])
|
|
fixture_count += 1
|
|
shell.queue_free()
|
|
(host.viewport as SubViewport).queue_free()
|
|
await _frames(3)
|
|
|
|
|
|
func _new_shell(viewport_size: Vector2i, locale: String) -> Control:
|
|
root.size = viewport_size
|
|
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(2)
|
|
var settings := SettingsStore.new().defaults()
|
|
settings.setup_completed = true
|
|
settings.locale = locale
|
|
settings.text_scale = 1.0
|
|
shell.settings = settings
|
|
shell.setup_draft = settings.duplicate(true)
|
|
return shell
|
|
|
|
|
|
func _new_fixture_shell(viewport_size: Vector2i, locale: String) -> Dictionary:
|
|
var viewport := SubViewport.new()
|
|
viewport.name = "M12FixtureViewport"
|
|
viewport.size = viewport_size
|
|
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
|
root.add_child(viewport)
|
|
var shell := EntryShell.new()
|
|
shell.auto_start = false
|
|
shell.initial_company_service.path = DRAFT_PATH
|
|
shell.initial_company_service.company_path = COMPANY_PATH
|
|
viewport.add_child(shell)
|
|
await _frames(2)
|
|
var settings := SettingsStore.new().defaults()
|
|
settings.setup_completed = true
|
|
settings.locale = locale
|
|
settings.text_scale = 1.0
|
|
shell.settings = settings
|
|
shell.setup_draft = settings.duplicate(true)
|
|
return {"viewport": viewport, "shell": shell}
|
|
|
|
|
|
func _reward_buttons(shell: Control) -> Array[Button]:
|
|
var result: Array[Button] = []
|
|
var options := shell.find_child("BattleRewardOptions", true, false)
|
|
if options == null:
|
|
return result
|
|
for child in options.get_children():
|
|
if child is Button and String(child.name).begins_with("BattleRewardOption_"):
|
|
result.append(child)
|
|
return result
|
|
|
|
|
|
func _verify_buttons(node: Node, viewport_size: Vector2i, state: String) -> void:
|
|
for child in node.get_children():
|
|
if child is BaseButton and child.is_visible_in_tree():
|
|
if state.begins_with("market") and String(child.name).begins_with("MarketCategory"):
|
|
_verify_buttons(child, viewport_size, state)
|
|
continue
|
|
var rect := (child as Control).get_global_rect()
|
|
_expect(rect.size.x >= 47.9 and rect.size.y >= 47.9, "%s button %s is at least 48px (rect=%s)" % [state, child.name, rect])
|
|
_expect(rect.position.x >= -1.0 and rect.position.y >= -1.0 and rect.end.x <= viewport_size.x + 1.0 and rect.end.y <= viewport_size.y + 1.0, "%s button %s stays inside viewport (rect=%s)" % [state, child.name, rect])
|
|
_verify_buttons(child, viewport_size, state)
|
|
|
|
|
|
func _create_prepared_company() -> Dictionary:
|
|
var draft_service := DraftService.new()
|
|
draft_service.path = DRAFT_PATH
|
|
draft_service.company_path = COMPANY_PATH
|
|
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[1].offer_id)])
|
|
if not draft_service.commit_company().ok:
|
|
return {}
|
|
var contract_service := ContractService.new()
|
|
contract_service.company_path = COMPANY_PATH
|
|
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)
|
|
var hired: Dictionary = contract_service.hire_recruit(HIRE_OP_2, String(offers[1].source_offer_id), 14)
|
|
if not hired.ok:
|
|
return {}
|
|
var formation_service := FormationService.new()
|
|
formation_service.company_path = COMPANY_PATH
|
|
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 _battle_service() -> RefCounted:
|
|
var service := BattleService.new()
|
|
service.company_path = COMPANY_PATH
|
|
return service
|
|
|
|
|
|
func _recruit_ids(company: Dictionary) -> Array[String]:
|
|
var result: Array[String] = []
|
|
for recruit in company.get("owned_recruits", []):
|
|
result.append(String(recruit.get("recruit_id", "")))
|
|
return result
|
|
|
|
|
|
func _touch(control: Control) -> void:
|
|
if control == null:
|
|
_expect(false, "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 _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:
|
|
failures.append("M12 Runtime: %s" % message)
|