131 lines
4.6 KiB
GDScript
131 lines
4.6 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 DRAFT_PATH := "user://dev4_risk_capture_draft.json"
|
|
const COMPANY_PATH := "user://dev4_risk_capture_company.json"
|
|
const SEED := "11223344556677889900aabbccddeeff"
|
|
const CONTRACT_OP := "00112233445566778899aabbccddeeff"
|
|
const HIRE_OP_1 := "102132435465768798a9bacbdcedfe0f"
|
|
const HIRE_OP_2 := "f0e0d0c0b0a090807060504030201000"
|
|
const ORDER_OP := "01230123012301230123012301230123"
|
|
const READY_OP := "32103210321032103210321032103210"
|
|
|
|
var output_root := ""
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_capture")
|
|
|
|
|
|
func run_capture() -> void:
|
|
output_root = OS.get_environment("ABG_EVIDENCE_DIR")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-dev4-risk-capture"
|
|
output_root = output_root.path_join("risk")
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
_cleanup()
|
|
var company := _create_prepared_company()
|
|
if company.is_empty():
|
|
quit(1)
|
|
return
|
|
var viewport := SubViewport.new()
|
|
viewport.size = Vector2i(844, 390)
|
|
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(3)
|
|
var settings := SettingsStore.new().defaults()
|
|
settings.setup_completed = true
|
|
settings.locale = "en"
|
|
settings.text_scale = 1.3
|
|
shell.settings = settings
|
|
shell.setup_draft = settings.duplicate(true)
|
|
shell.show_risk_board(company)
|
|
await _capture(viewport, "01-risk-no-selection")
|
|
var option_id := String(company.active_contract.formation.risk_options[1].risk_option_id)
|
|
shell.risk_selected_id = option_id
|
|
shell.show_risk_board(company)
|
|
await _capture(viewport, "02-risk-selected")
|
|
shell.show_risk_commitment(company)
|
|
await _capture(viewport, "03-risk-commitment")
|
|
shell.queue_free()
|
|
viewport.queue_free()
|
|
await _frames(100)
|
|
_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_DEV4_RISK_CAPTURE_OK frames=3 viewport=844x390 locale=en text_130=true root=%s" % output_root)
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _capture(viewport: SubViewport, state: String) -> void:
|
|
await _frames(6)
|
|
await RenderingServer.frame_post_draw
|
|
if viewport.get_texture().get_image().save_png(output_root.path_join(state + ".png")) != OK:
|
|
failures.append("capture failed: %s" % state)
|
|
|
|
|
|
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[1].offer_id)])
|
|
var committed: Dictionary = _draft_service().commit_company()
|
|
if not committed.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 _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)
|