254 lines
11 KiB
GDScript
254 lines
11 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_candidate_draft.json"
|
|
const COMPANY_PATH := "user://dev4_candidate_company.json"
|
|
const SEED := "ffeeddccbbaa00998877665544332211"
|
|
const CONTRACT_OP := "a1b2c3d4e5f60718273645aabbccddee"
|
|
const HIRE_OP_1 := "11111111222222223333333344444444"
|
|
const HIRE_OP_2 := "55555555666666667777777788888888"
|
|
const ORDER_OP := "99999999aaaaaaaabbbbbbbbcccccccc"
|
|
const READY_OP := "ddddddddeeeeeeeeffffffff00000000"
|
|
|
|
const STATES := ["market_ready", "party_line", "party_swapped", "readiness", "risk_board", "risk_commitment"]
|
|
|
|
var output_root := ""
|
|
var failures: Array[String] = []
|
|
var fixture_index := 0
|
|
var viewport_size := Vector2i(844, 390)
|
|
var locale := "en"
|
|
var text_scale := 1.0
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_capture")
|
|
|
|
|
|
func run_capture() -> void:
|
|
fixture_index = int(OS.get_environment("ABG_CAPTURE_FIXTURE_INDEX"))
|
|
var fixtures := [
|
|
{"size": Vector2i(760, 360), "locale": "zh_CN", "scale": 1.0},
|
|
{"size": Vector2i(844, 390), "locale": "en", "scale": 1.3},
|
|
{"size": Vector2i(1280, 720), "locale": "zh_CN", "scale": 1.0},
|
|
{"size": Vector2i(1280, 720), "locale": "en", "scale": 1.3},
|
|
]
|
|
if fixture_index < 0 or fixture_index >= fixtures.size():
|
|
push_error("unknown DEV-4 fixture index %d" % fixture_index)
|
|
quit(1)
|
|
return
|
|
viewport_size = fixtures[fixture_index].size
|
|
locale = fixtures[fixture_index].locale
|
|
text_scale = fixtures[fixture_index].scale
|
|
var scale_override := OS.get_environment("ABG_CAPTURE_TEXT_SCALE")
|
|
if not scale_override.is_empty():
|
|
text_scale = float(scale_override)
|
|
var locale_override := OS.get_environment("ABG_CAPTURE_LOCALE")
|
|
if not locale_override.is_empty():
|
|
locale = locale_override
|
|
output_root = OS.get_environment("ABG_EVIDENCE_DIR")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-dev4-candidate"
|
|
output_root = output_root.path_join("captures")
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
_cleanup()
|
|
var company := _create_company()
|
|
if company.is_empty():
|
|
quit(1)
|
|
return
|
|
var viewport := SubViewport.new()
|
|
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(3)
|
|
var settings := SettingsStore.new().defaults()
|
|
settings.setup_completed = true
|
|
settings.locale = locale
|
|
settings.text_scale = text_scale
|
|
shell.settings = settings
|
|
shell.setup_draft = settings.duplicate(true)
|
|
for state in STATES:
|
|
_apply_state(shell, company, String(state))
|
|
await _frames(6)
|
|
_verify_buttons(shell, String(state))
|
|
if state in ["party_line", "party_swapped"]:
|
|
_verify_party_line_ui(shell, String(state))
|
|
await RenderingServer.frame_post_draw
|
|
var image := viewport.get_texture().get_image()
|
|
var path := output_root.path_join("fixture%d-%s.png" % [fixture_index, String(state)])
|
|
if image.save_png(path) != OK:
|
|
failures.append("capture failed: %s" % state)
|
|
shell.queue_free()
|
|
viewport.queue_free()
|
|
await _frames(100)
|
|
_cleanup()
|
|
if failures.is_empty():
|
|
print("ABG_DEV4_CAPTURE_OK fixture=%d viewport=%dx%d locale=%s text_%d=true frames=6 root=%s" % [fixture_index, viewport_size.x, viewport_size.y, locale, int(round(text_scale * 100.0)), output_root])
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _apply_state(shell: Control, company: Dictionary, state: String) -> void:
|
|
match state:
|
|
"market_ready":
|
|
shell.party_draft_order.clear()
|
|
shell.party_selected_recruit_id = ""
|
|
shell.risk_selected_id = ""
|
|
shell.show_market(company)
|
|
"party_line":
|
|
shell.party_draft_order.clear()
|
|
shell.party_selected_recruit_id = ""
|
|
shell.risk_selected_id = ""
|
|
shell.show_party_line(company)
|
|
"party_swapped":
|
|
var order: Array = shell.party_draft_order.duplicate()
|
|
var temporary = order[0]
|
|
order[0] = order[3]
|
|
order[3] = temporary
|
|
shell.party_draft_order.assign(order)
|
|
shell.party_selected_recruit_id = String(order[0])
|
|
shell.show_party_line(company)
|
|
"readiness":
|
|
var loaded: Dictionary = _formation_service().load_company()
|
|
var formation: Dictionary = loaded.company.active_contract.formation
|
|
var saved: Dictionary = _formation_service().save_order(ORDER_OP, formation.draft_front_to_rear_ids)
|
|
shell.party_draft_order.assign(saved.company.active_contract.formation.saved_front_to_rear_ids)
|
|
shell.show_readiness_review(saved.company)
|
|
"risk_board":
|
|
var loaded: Dictionary = _formation_service().load_company()
|
|
var formation: Dictionary = loaded.company.active_contract.formation
|
|
var order_hash := String(formation.order_receipts.back().order_hash)
|
|
_formation_service().accept_readiness(READY_OP, order_hash)
|
|
shell.risk_selected_id = ""
|
|
shell.show_risk_board(_formation_service().load_company().company)
|
|
"risk_commitment":
|
|
var loaded: Dictionary = _formation_service().load_company()
|
|
var options: Array = loaded.company.active_contract.formation.risk_options
|
|
shell.risk_selected_id = String(options[1].risk_option_id)
|
|
shell.show_risk_commitment(loaded.company)
|
|
|
|
|
|
func _verify_buttons(node: Node, state: String) -> void:
|
|
for child in node.get_children():
|
|
if child is BaseButton and child.is_visible_in_tree():
|
|
# The Market mode ledger uses compact authored plates; its category
|
|
# focus/input boundaries are covered by the current M09 runtime test,
|
|
# while this legacy DEV-4 capture helper owns Party/Readiness/Risk
|
|
# command targets. Do not apply the retired 44px visual-plate check to
|
|
# those shared Market mode controls.
|
|
if String(child.name).begins_with("MarketCategory"):
|
|
_verify_buttons(child, state)
|
|
continue
|
|
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])
|
|
if rect.size.x < 44.0 or rect.size.y < 44.0:
|
|
failures.append("%s button %s below 44px: %s" % [state, child.name, rect.size])
|
|
_verify_buttons(child, state)
|
|
|
|
|
|
func _verify_party_line_ui(shell: Control, state: String) -> void:
|
|
var canvas_height := minf(float(viewport_size.y), float(viewport_size.x) / (16.0 / 9.0))
|
|
var canvas_scale := clampf(canvas_height / 360.0, 1.0, 2.0)
|
|
var expected_summary_size := mini(16, int(round(10.0 * canvas_scale * text_scale)))
|
|
var expected_command_size := mini(16, int(round(11.0 * canvas_scale * text_scale)))
|
|
var cord := shell.find_child("PartyFormationCord", true, false) as Control
|
|
var effects := shell.find_child("PartyFormationEffects", true, false) as Control
|
|
for position in range(4):
|
|
var actor := shell.find_child("PartyPosition%d" % position, true, false) as Control
|
|
if actor == null:
|
|
failures.append("%s missing PartyPosition%d" % [state, position])
|
|
continue
|
|
if actor.size.x < 48.0 or actor.size.y < 48.0:
|
|
failures.append("%s PartyPosition%d below 48px: %s" % [state, position, actor.size])
|
|
if cord == null or effects == null or not (cord.z_index < actor.z_index and actor.z_index < effects.z_index):
|
|
failures.append("%s PartyPosition%d is not between cord and effects" % [state, position])
|
|
for node_name in ["PartyRelationSummary", "PartyFirstThreat"]:
|
|
var label := shell.find_child(node_name, true, false) as Label
|
|
_verify_text_fit(label, expected_summary_size, "%s %s" % [state, node_name])
|
|
for node_name in ["PartyUndo", "PartyReset", "PartySaveReview", "PartyBack"]:
|
|
var command := shell.find_child(node_name, true, false) as Button
|
|
if command == null:
|
|
failures.append("%s missing %s" % [state, node_name])
|
|
continue
|
|
if command.size.x < 48.0 or command.size.y < 48.0:
|
|
failures.append("%s %s below 48px: %s" % [state, node_name, command.size])
|
|
_verify_text_fit(command.get_node_or_null("ButtonLabel") as Label, expected_command_size, "%s %s" % [state, node_name])
|
|
|
|
|
|
func _verify_text_fit(label: Label, expected_font_size: int, context: String) -> void:
|
|
if label == null:
|
|
failures.append("%s label missing" % context)
|
|
return
|
|
var font := label.get_theme_font("font")
|
|
var font_size := label.get_theme_font_size("font_size")
|
|
if font_size < expected_font_size:
|
|
failures.append("%s font %d below expected %d" % [context, font_size, expected_font_size])
|
|
var lines := label.text.split("\n")
|
|
var required_height := float(font.get_height(font_size) * lines.size())
|
|
if required_height > label.size.y + 1.0:
|
|
failures.append("%s text height %.1f exceeds %.1f" % [context, required_height, label.size.y])
|
|
for line in lines:
|
|
var required_width := font.get_string_size(line, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x
|
|
if required_width > label.size.x + 1.0:
|
|
failures.append("%s line width %.1f exceeds %.1f: %s" % [context, required_width, label.size.x, line])
|
|
|
|
|
|
func _create_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)])
|
|
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)
|
|
return hired.company if hired.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)
|