140 lines
5.7 KiB
GDScript
140 lines
5.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")
|
|
|
|
# Single authoritative size (owner policy): two shipped locales at 1280x720.
|
|
const FIXTURES := [
|
|
{"width": 1280, "height": 720, "locale": "zh_CN"},
|
|
{"width": 1280, "height": 720, "locale": "en"},
|
|
]
|
|
const STATES := ["roster", "recruit_detail"]
|
|
const SEED := "99887766554433221100ffeeddccbbaa"
|
|
const CONTRACT_OP := "abcdefabcdefabcdefabcdefabcdefab"
|
|
const HIRE_OP_1 := "11112222333344445555666677778888"
|
|
const HIRE_OP_2 := "88887777666655554444333322221111"
|
|
|
|
var failures: Array[String] = []
|
|
var fixture_index := -1
|
|
var output_root := ""
|
|
|
|
|
|
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
|
|
output_root = OS.get_environment("ABG_EVIDENCE_DIR")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-m16-company-capture"
|
|
output_root = output_root.path_join("captures")
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
var indexes := range(FIXTURES.size()) if fixture_index < 0 else [fixture_index]
|
|
for index in indexes:
|
|
if index < 0 or index >= FIXTURES.size():
|
|
failures.append("unknown fixture index %d" % index)
|
|
continue
|
|
for state in STATES:
|
|
await _capture_state(index, state, FIXTURES[index])
|
|
if failures.is_empty():
|
|
print("ABG_M16_COMPANY_CAPTURE_OK fixtures=%d states=roster,recruit_detail frames=%d matrix=1280x720:zh_CN,en:100 targets=authored44 renderer=normal" % [indexes.size(), indexes.size() * STATES.size()])
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _capture_state(index: int, state: String, fixture: Dictionary) -> void:
|
|
var draft_path := "user://m16_company_capture_%d_%s.json" % [index, state]
|
|
var company_path := "%s.company" % draft_path
|
|
_cleanup_path(draft_path)
|
|
var company := _create_company(draft_path, company_path)
|
|
if company.is_empty():
|
|
failures.append("%s fixture could not create Company" % state)
|
|
return
|
|
var viewport := SubViewport.new()
|
|
viewport.size = Vector2i(int(fixture.width), int(fixture.height))
|
|
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 = String(fixture.locale)
|
|
settings.text_scale = 1.0
|
|
shell.settings = settings
|
|
shell.setup_draft = settings.duplicate(true)
|
|
if state == "roster":
|
|
shell.show_roster(company)
|
|
else:
|
|
shell.show_recruit_detail(String(company.owned_recruits[0].recruit_id))
|
|
await _frames(6)
|
|
_verify_buttons(shell, state, viewport.size)
|
|
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("%s returns a complete %dx%d frame" % [state, viewport.size.x, viewport.size.y])
|
|
else:
|
|
var path := output_root.path_join("fixture%d-%s.png" % [index, state])
|
|
if image.save_png(path) != OK:
|
|
failures.append("capture failed: %s" % path)
|
|
shell.queue_free()
|
|
viewport.queue_free()
|
|
await _frames(5)
|
|
_cleanup_path(draft_path)
|
|
|
|
|
|
func _verify_buttons(node: Node, state: String, viewport_size: Vector2i) -> void:
|
|
for child in node.get_children():
|
|
if child is BaseButton and child.is_visible_in_tree():
|
|
var rect: Rect2 = child.get_global_rect()
|
|
if rect.position.x < -0.5 or rect.position.y < -0.5 or rect.end.x > viewport_size.x + 0.5 or rect.end.y > viewport_size.y + 0.5:
|
|
failures.append("%s button %s outside viewport: %s" % [state, child.name, rect])
|
|
# This pilot preserves the historical DEV-6 composition; its short
|
|
# landscape footer uses the existing 44px authored target.
|
|
if rect.size.x < 44.0 or rect.size.y < 44.0:
|
|
failures.append("%s button %s below authored 44px target: %s" % [state, child.name, rect.size])
|
|
_verify_buttons(child, state, viewport_size)
|
|
|
|
|
|
func _create_company(draft_path: String, company_path: String) -> 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)])
|
|
var committed: Dictionary = draft_service.commit_company()
|
|
if not committed.ok:
|
|
return {}
|
|
var contract := ContractService.new()
|
|
contract.company_path = company_path
|
|
var created: Dictionary = contract.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.hire_recruit(HIRE_OP_1, String(offers[0].source_offer_id), 14)
|
|
var hired: Dictionary = contract.hire_recruit(HIRE_OP_2, String(offers[1].source_offer_id), 14)
|
|
return hired.company if hired.ok else {}
|
|
|
|
|
|
func _cleanup_path(path: String) -> void:
|
|
for candidate in [path, "%s.bak" % path, "%s.candidate" % path, "%s.bak.candidate" % path, "%s.company" % path, "%s.company.bak" % path, "%s.company.candidate" % path, "%s.company.bak.candidate" % path, "%s.corrupt" % path]:
|
|
if FileAccess.file_exists(candidate):
|
|
DirAccess.remove_absolute(candidate)
|
|
|
|
|
|
func _frames(count: int) -> void:
|
|
for _index in range(count):
|
|
await process_frame
|