186 lines
6.7 KiB
GDScript
186 lines
6.7 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 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"},
|
|
]
|
|
const DRAFT_PATH := "user://bat34_capture_draft.json"
|
|
const COMPANY_PATH := "user://bat34_capture_company.json"
|
|
const SEED := "11223344556677889900aabbccddeeff"
|
|
const CONTRACT_OP := "fedcba9876543210fedcba9876543210"
|
|
const HIRE_OP_1 := "11112222333344445555666677778888"
|
|
const HIRE_OP_2 := "88887777666655554444333322221111"
|
|
const ORDER_OP := "abcdefabcdefabcdefabcdefabcdefab"
|
|
const READY_OP := "fedcbafedcbafedcbafedcbafedcbafe"
|
|
const BATTLE_OP := "1234567890abcdef1234567890abcdef"
|
|
|
|
var failures: Array[String] = []
|
|
var output_root := ""
|
|
var fixture_index := 0
|
|
var capture_count := 0
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_capture")
|
|
|
|
|
|
func run_capture() -> void:
|
|
var requested := OS.get_environment("ABG_CAPTURE_FIXTURE_INDEX")
|
|
fixture_index = requested.to_int() if not requested.is_empty() else -1
|
|
if fixture_index < 0 or fixture_index >= FIXTURES.size():
|
|
push_error("BAT-003/004 capture requires ABG_CAPTURE_FIXTURE_INDEX 0..3")
|
|
quit(2)
|
|
return
|
|
var fixture: Dictionary = FIXTURES[fixture_index]
|
|
output_root = OS.get_environment("ABG_EVIDENCE_DIR")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-bat34-captures"
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
_cleanup()
|
|
root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
|
|
root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND
|
|
root.size = fixture.size
|
|
var company := _prepare_company()
|
|
if company.is_empty():
|
|
failures.append("fixture could not prepare Company")
|
|
_finish()
|
|
return
|
|
var started: Dictionary = _battle_service().begin_battle(BATTLE_OP, String(company.active_contract.formation.risk_options[1].risk_option_id))
|
|
if not started.ok:
|
|
failures.append("fixture could not begin Battle")
|
|
_finish()
|
|
return
|
|
var viewport := SubViewport.new()
|
|
viewport.size = fixture.size
|
|
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
|
root.add_child(viewport)
|
|
var shell := await _new_shell(viewport, String(fixture.locale))
|
|
shell.show_battle(started.company, false)
|
|
await _frames(4)
|
|
# Seed one committed observation event so BAT-003 shows a real causal chain
|
|
# and BAT-004's log is not an empty shell.
|
|
shell.battle_paused = false
|
|
shell._clear_battle_playback_timer()
|
|
for _step in range(4):
|
|
shell.advance_battle_phase()
|
|
await _frames(1)
|
|
shell.battle_paused = true
|
|
shell._clear_battle_playback_timer()
|
|
shell._battle_live_toggle_inspect()
|
|
await _frames(3)
|
|
await _capture(viewport, "bat003-inspect")
|
|
shell._battle_live_cancel_handoff()
|
|
shell._battle_live_open_retreat_entry()
|
|
await _frames(3)
|
|
await _capture(viewport, "bat004-pause")
|
|
shell.queue_free()
|
|
viewport.queue_free()
|
|
await _frames(5)
|
|
_finish()
|
|
|
|
|
|
func _finish() -> void:
|
|
_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_BAT003_BAT004_CAPTURE_OK fixture=%d captures=%d states=inspect,pause viewport=%dx%d locale=%s text_100=true" % [fixture_index, capture_count, int(FIXTURES[fixture_index].size.x), int(FIXTURES[fixture_index].size.y), String(FIXTURES[fixture_index].locale)])
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _new_shell(parent: Node, locale: String) -> Control:
|
|
var shell := EntryShell.new()
|
|
shell.auto_start = false
|
|
shell.initial_company_service.path = DRAFT_PATH
|
|
shell.initial_company_service.company_path = COMPANY_PATH
|
|
parent.add_child(shell)
|
|
await _frames(3)
|
|
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 _capture(viewport: SubViewport, state_name: String) -> void:
|
|
var file_name := "bat003-004-%dx%d-%s-100-%s.png" % [viewport.size.x, viewport.size.y, String(FIXTURES[fixture_index].locale), state_name]
|
|
await RenderingServer.frame_post_draw
|
|
var image := viewport.get_texture().get_image()
|
|
if image.is_empty() or image.get_width() != viewport.size.x or image.get_height() != viewport.size.y:
|
|
failures.append("invalid %s frame" % state_name)
|
|
return
|
|
if image.save_png(output_root.path_join(file_name)) != OK:
|
|
failures.append("could not save %s" % state_name)
|
|
else:
|
|
capture_count += 1
|
|
|
|
|
|
func _prepare_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[1].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)
|
|
var hired: Dictionary = _contract_service().hire_recruit(HIRE_OP_2, String(offers[1].source_offer_id), 14)
|
|
if not hired.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 _frames(count: int) -> void:
|
|
for _index in range(count):
|
|
await process_frame
|
|
|
|
|
|
func _cleanup() -> void:
|
|
for path in [DRAFT_PATH, COMPANY_PATH, "%s.bak" % DRAFT_PATH, "%s.bak" % COMPANY_PATH, "%s.candidate" % DRAFT_PATH, "%s.candidate" % COMPANY_PATH, "%s.bak.candidate" % DRAFT_PATH, "%s.bak.candidate" % COMPANY_PATH, "%s.corrupt" % COMPANY_PATH]:
|
|
if FileAccess.file_exists(path):
|
|
DirAccess.remove_absolute(path)
|