547 lines
26 KiB
GDScript
547 lines
26 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://dev5_battle_live_capture_draft.json"
|
|
const COMPANY_PATH := "user://dev5_battle_live_capture_company.json"
|
|
const SEED := "2468ace013579bdf2468ace013579bdf"
|
|
const CONTRACT_OP := "abcdef0123456789abcdef0123456789"
|
|
const HIRE_OP_1 := "11111111222222223333333344444444"
|
|
const HIRE_OP_2 := "55555555666666667777777788888888"
|
|
const ORDER_OP := "99999999aaaaaaaabbbbbbbbcccccccc"
|
|
const READY_OP := "ddddddddeeeeeeeeffffffff00000000"
|
|
const BATTLE_OP := "1234567890abcdef1234567890abcdef"
|
|
const INTERRUPT_BATTLE_OP := "fedcba0987654321fedcba0987654321"
|
|
|
|
var failures: Array[String] = []
|
|
var capture_count := 0
|
|
var output_root := ""
|
|
var viewport_size := Vector2i(1280, 720)
|
|
var fixture_index := 0
|
|
var locale := "en"
|
|
var state_records: Array = []
|
|
var evidence_records: Array = []
|
|
var capture_by_name := {}
|
|
var non_opening_kind := ""
|
|
var non_opening_phase := -1
|
|
var action_event_id := ""
|
|
var waiting_copy := ""
|
|
|
|
|
|
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"},
|
|
{"size": Vector2i(844, 390), "locale": "en"},
|
|
{"size": Vector2i(1280, 720), "locale": "zh_CN"},
|
|
{"size": Vector2i(1280, 720), "locale": "en"},
|
|
]
|
|
if fixture_index < 0 or fixture_index >= fixtures.size():
|
|
push_error("unknown BAT-002 live capture fixture %d" % fixture_index)
|
|
quit(1)
|
|
return
|
|
viewport_size = fixtures[fixture_index].size
|
|
locale = fixtures[fixture_index].locale
|
|
root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS
|
|
root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND
|
|
root.size = viewport_size
|
|
output_root = OS.get_environment("ABG_EVIDENCE_DIR")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-bat002-live-candidate"
|
|
output_root = output_root.path_join("captures")
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
_cleanup()
|
|
var prepared := _create_prepared_company()
|
|
var started: Dictionary = _battle_service().begin_battle(BATTLE_OP, String(prepared.active_contract.formation.risk_options[1].risk_option_id)) if not prepared.is_empty() else {}
|
|
_expect(bool(started.get("ok", false)), "capture fixture creates one battle receipt")
|
|
if started.is_empty() or not bool(started.get("ok", false)):
|
|
_finish()
|
|
return
|
|
var viewport := SubViewport.new()
|
|
viewport.name = "BattleLiveTimelineCaptureViewport"
|
|
viewport.size = viewport_size
|
|
viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
|
root.add_child(viewport)
|
|
var shell := await _new_shell(viewport)
|
|
shell.show_battle(started.company, false)
|
|
await _frames(5)
|
|
_expect(shell.battle_live_state == "waiting_for_next_event", "capture opens at waiting boundary")
|
|
var waiting := shell.find_child("BattleWaitingForNextEvent", true, false) as Label
|
|
_expect(waiting != null and not waiting.text.is_empty(), "waiting boundary keeps a nonblank reserved event slot")
|
|
if locale == "en" and waiting != null:
|
|
_expect(waiting.text == "Waiting for next event", "waiting boundary copy is exact")
|
|
waiting_copy = waiting.text if waiting != null else ""
|
|
|
|
# M107-P2 diagnosis: the previous harness advanced four steps straight from
|
|
# the waiting boundary, so forecast/committed/resolving all belonged to the
|
|
# phase-0 opening event. Its chrome is suppressed, so those three frames were
|
|
# byte-identical. Sample the opening boundary once, resolve it, then sample
|
|
# the first non-opening event for the four action states.
|
|
shell.toggle_battle_pause()
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
_expect(shell.battle_live_state == "event_forecast", "opening forecast is reached")
|
|
_expect(String(shell.battle_live_event.get("kind", "")) == "opening", "the first sampled event is the phase-0 opening")
|
|
await _capture(viewport, shell, "01-opening", "boundary", {
|
|
"matrix_state": "",
|
|
"action_coverage": false,
|
|
"note": "phase-0 opening (BAT-001 to BAT-002 boundary); state word hidden by existing design (M106 F2 product decision); not counted toward forecast/committed/resolving coverage",
|
|
})
|
|
|
|
for _step in range(3):
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
_expect(shell.battle_live_state == "event_resolved", "the opening event resolves")
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
_expect(shell.battle_live_state == "waiting_for_next_event", "observation returns to the waiting boundary")
|
|
var waiting_again := shell.find_child("BattleWaitingForNextEvent", true, false) as Label
|
|
_expect(waiting_again != null and not waiting_again.text.is_empty() and waiting_again.text == waiting_copy, "waiting boundary reappears with the same nonblank copy")
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
_expect(shell.battle_live_state == "event_forecast", "the first non-opening forecast is reached")
|
|
non_opening_kind = String(shell.battle_live_event.get("kind", ""))
|
|
non_opening_phase = int(shell.battle_live_event.get("phase", -1))
|
|
_expect(non_opening_kind != "" and non_opening_kind != "opening", "the first action event is not the opening beat")
|
|
_expect(non_opening_phase >= 1, "the first action event has a non-opening phase")
|
|
await _capture(viewport, shell, "02-forecast")
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
await _capture(viewport, shell, "03-committed")
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
await _capture(viewport, shell, "04-resolving")
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
_expect(shell.battle_live_state == "event_resolved", "capture reaches resolved event boundary")
|
|
await _capture(viewport, shell, "05-resolved")
|
|
var opening_hash := String(Dictionary(capture_by_name.get("01-opening", {})).get("sha256", ""))
|
|
var action_hash := String(Dictionary(capture_by_name.get("02-forecast", {})).get("sha256", ""))
|
|
_expect(not opening_hash.is_empty() and not action_hash.is_empty() and opening_hash != action_hash, "the first action state differs from the opening capture")
|
|
var committed_hash := String(Dictionary(capture_by_name.get("03-committed", {})).get("sha256", ""))
|
|
var resolving_hash := String(Dictionary(capture_by_name.get("04-resolving", {})).get("sha256", ""))
|
|
_expect(not (action_hash == committed_hash and committed_hash == resolving_hash), "forecast/committed/resolving are no longer one repeated opening frame")
|
|
|
|
# M107 per-state evidence (product review 2026-09-21 §2.1): each action state
|
|
# must prove its own window and ownership, not just a pixel difference.
|
|
var forecast := Dictionary(capture_by_name.get("02-forecast", {}))
|
|
var committed := Dictionary(capture_by_name.get("03-committed", {}))
|
|
var resolving := Dictionary(capture_by_name.get("04-resolving", {}))
|
|
var resolved := Dictionary(capture_by_name.get("05-resolved", {}))
|
|
action_event_id = String(forecast.get("event_id", ""))
|
|
_expect(not action_event_id.is_empty(), "the action event carries an event_id")
|
|
_expect(String(committed.get("event_id", "")) == action_event_id, "committed keeps the forecast reservation id")
|
|
_expect(bool(forecast.get("state_word_visible", false)) and bool(committed.get("state_word_visible", false)) and bool(resolving.get("state_word_visible", false)), "forecast/committed/resolving expose a visible state word")
|
|
_expect(String(forecast.get("state_word", "")) != String(committed.get("state_word", "")), "committed state word is identifiable from forecast")
|
|
_expect(bool(forecast.get("event_id_visible", false)) and bool(committed.get("event_id_visible", false)), "forecast/committed keep the event identity visible")
|
|
_expect(String(forecast.get("target_id", "")) != "", "forecast names a target")
|
|
_expect(String(resolving.get("source_id", "")) != "" and String(resolving.get("target_id", "")) != "", "resolving keeps source and target")
|
|
_expect(not bool(forecast.get("delta_visible", false)) and not bool(committed.get("delta_visible", false)) and not bool(resolving.get("delta_visible", false)), "forecast/committed/resolving do not claim a settled result")
|
|
_expect(bool(resolved.get("delta_visible", false)) and String(resolved.get("delta_text", "")) != "", "resolved exposes a delta value with non-color glyphs")
|
|
_expect(int(forecast.get("next_phase_index", -1)) == int(forecast.get("phase", -2)), "forecast sits in the pre-commit window")
|
|
_expect(int(committed.get("next_phase_index", -1)) == int(committed.get("phase", -2)), "committed sits before the authoritative resolve")
|
|
_expect(int(resolving.get("next_phase_index", -1)) == int(resolving.get("phase", -2)), "resolving is the authoritative contact window")
|
|
_expect(int(resolved.get("next_phase_index", -1)) == int(resolved.get("phase", -2)) + 1, "resolved is post-commit")
|
|
var art := shell.find_child("BattleLiveArt", true, false)
|
|
_expect(art != null and String(art.get("event_kind")) == String(resolving.get("event_kind", "")) and String(art.get("source_side")) != "" and String(art.get("target_side")) != "", "resolving owns a source-to-target relation path")
|
|
await _frames(10)
|
|
var settled := _state_evidence(shell)
|
|
_expect(String(shell.battle_live_state) == "event_resolved", "resolved persists for inspection frames")
|
|
_expect(bool(settled.get("delta_visible", false)) and String(settled.get("delta_text", "")) == String(resolved.get("delta_text", "")), "resolved delta persists across frames")
|
|
forecast["changed_ownership"] = ["matrix_state:event_forecast", "state_word:%s" % String(forecast.get("state_word", "")), "event_id_visible", "target:%s" % String(forecast.get("target_id", ""))]
|
|
committed["changed_ownership"] = ["matrix_state:action_committed", "state_word:%s" % String(committed.get("state_word", "")), "reservation_id:%s" % action_event_id]
|
|
resolving["changed_ownership"] = ["matrix_state:event_resolving", "state_word:%s" % String(resolving.get("state_word", "")), "relation_path:%s->%s" % [String(resolving.get("source_id", "")), String(resolving.get("target_id", ""))]]
|
|
resolved["changed_ownership"] = ["matrix_state:event_resolved", "state_word:%s" % String(resolved.get("state_word", "")), "delta:%s" % String(resolved.get("delta_text", "")), "post_commit"]
|
|
resolved["persistence_frames"] = 10
|
|
resolved["non_color_shape"] = "text glyphs: state word + delta label"
|
|
|
|
# M107-P2: static ownership and dynamic-on-neutral evidence views, taken from
|
|
# the resolved non-opening state through existing nodes only.
|
|
await _capture_static_only(viewport, shell)
|
|
await _capture_dynamic_neutral(viewport, shell)
|
|
|
|
shell.toggle_battle_pause()
|
|
await _frames(2)
|
|
_expect(shell.battle_live_state == "paused" and shell.battle_paused, "capture freezes paused state")
|
|
await _capture(viewport, shell, "06-paused")
|
|
shell.toggle_battle_pause()
|
|
|
|
while shell.battle_live_state != "event_resolving":
|
|
shell.advance_battle_phase()
|
|
await _frames(1)
|
|
if shell.battle_live_state == "outcome_locked":
|
|
break
|
|
_expect(shell.battle_live_state == "event_resolving", "capture reaches an authoritative resolving event")
|
|
if shell.battle_live_state == "event_resolving":
|
|
shell.battle_live_event.event_hash = "0".repeat(64)
|
|
shell.advance_battle_phase()
|
|
await _frames(2)
|
|
_expect(shell.battle_live_state == "invalid_event_data" and shell.battle_paused, "capture exposes invalid-event pause")
|
|
await _capture(viewport, shell, "07-invalid")
|
|
shell._battle_live_retry_snapshot()
|
|
await _frames(1)
|
|
_expect(shell.battle_live_state == "loading_resume", "capture exposes loading-resume validation")
|
|
await _capture(viewport, shell, "08-loading")
|
|
await _frames(3)
|
|
_expect(shell.battle_live_state == "event_resolved" and shell.battle_paused, "capture retry returns to the last verified event boundary")
|
|
shell.toggle_battle_pause()
|
|
|
|
var guard := 0
|
|
while shell.battle_live_state != "outcome_locked" and guard < 90:
|
|
if shell.battle_paused:
|
|
shell.toggle_battle_pause()
|
|
shell.advance_battle_phase()
|
|
await _frames(1)
|
|
guard += 1
|
|
_expect(shell.battle_live_state == "outcome_locked", "capture reaches immutable outcome")
|
|
await _capture(viewport, shell, "10-outcome")
|
|
shell.queue_free()
|
|
viewport.queue_free()
|
|
await _frames(12)
|
|
|
|
_cleanup()
|
|
var interrupted := _create_prepared_company()
|
|
var interrupted_start: Dictionary = _battle_service().begin_battle(INTERRUPT_BATTLE_OP, String(interrupted.active_contract.formation.risk_options[1].risk_option_id)) if not interrupted.is_empty() else {}
|
|
_expect(bool(interrupted_start.get("ok", false)), "interruption fixture creates a second isolated receipt")
|
|
if bool(interrupted_start.get("ok", false)):
|
|
var interrupt_viewport := SubViewport.new()
|
|
interrupt_viewport.name = "BattleLiveInterruptCaptureViewport"
|
|
interrupt_viewport.size = viewport_size
|
|
interrupt_viewport.render_target_update_mode = SubViewport.UPDATE_ALWAYS
|
|
root.add_child(interrupt_viewport)
|
|
var interrupt_shell := await _new_shell(interrupt_viewport)
|
|
interrupt_shell.show_battle(interrupted_start.company, false)
|
|
await _frames(4)
|
|
interrupt_shell._battle_live_interrupt("capture_background")
|
|
await _frames(2)
|
|
_expect(interrupt_shell.battle_live_state == "interrupted_background" and interrupt_shell.battle_paused, "capture exposes BAT-006 interruption handoff")
|
|
await _capture(interrupt_viewport, interrupt_shell, "09-interrupted")
|
|
interrupt_shell.queue_free()
|
|
interrupt_viewport.queue_free()
|
|
await _frames(12)
|
|
_finish()
|
|
|
|
|
|
func _finish() -> void:
|
|
_cleanup()
|
|
var manifest_path := _write_manifest()
|
|
if failures.is_empty():
|
|
var state_names: Array = []
|
|
for record in state_records:
|
|
state_names.append(String(Dictionary(record).get("name", "")))
|
|
state_names.sort()
|
|
print("ABG_DEV5_BATTLE_LIVE_CAPTURE_OK fixture=%d viewport=%dx%d locale=%s text_100=true states=%s state_captures=%d views=%d captures=%d source=runtime" % [fixture_index, viewport_size.x, viewport_size.y, locale, ",".join(state_names), state_records.size(), evidence_records.size(), capture_count])
|
|
print("ABG_M107_BAT002_CAPTURE_MANIFEST_OK fixture=%d viewport=%dx%d locale=%s opening=phase0 action_kind=%s action_phase=%d states=%d views=%d manifest=%s" % [fixture_index, viewport_size.x, viewport_size.y, locale, non_opening_kind, non_opening_phase, state_records.size(), evidence_records.size(), manifest_path.get_file()])
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _write_manifest() -> String:
|
|
var opening := Dictionary(capture_by_name.get("01-opening", {}))
|
|
var manifest := {
|
|
"schema": "m107.bat002.capture_manifest.v2",
|
|
"source": "runtime",
|
|
"fixture_index": fixture_index,
|
|
"viewport": "%dx%d" % [viewport_size.x, viewport_size.y],
|
|
"locale": locale,
|
|
"text_scale": 1.0,
|
|
"boundaries": {
|
|
"waiting_for_next_event": {
|
|
"asserted": not waiting_copy.is_empty(),
|
|
"copy": waiting_copy,
|
|
"never_blank": not waiting_copy.is_empty(),
|
|
"matrix_state": "waiting_for_next_event",
|
|
},
|
|
"opening": {
|
|
"coverage": "boundary_pre_roll",
|
|
"matrix_state": "",
|
|
"action_coverage": false,
|
|
"state_word_visible": bool(opening.get("state_word_visible", false)),
|
|
"note": "phase-0 opening (BAT-001 to BAT-002 boundary); state word hidden by existing design (M106 F2 product decision); not counted toward forecast/committed/resolving coverage",
|
|
},
|
|
},
|
|
"action_event": {
|
|
"phase": non_opening_phase,
|
|
"kind": non_opening_kind,
|
|
"event_id": action_event_id,
|
|
"states": ["forecast", "committed", "resolving", "resolved"],
|
|
},
|
|
"states": state_records,
|
|
"evidence_views": evidence_records,
|
|
"failures": failures.duplicate(),
|
|
}
|
|
var path := output_root.path_join("bat002-capture-manifest-%dx%d-%s.json" % [viewport_size.x, viewport_size.y, locale])
|
|
var file := FileAccess.open(path, FileAccess.WRITE)
|
|
if file == null:
|
|
failures.append("manifest write failed: %s" % path)
|
|
return ""
|
|
file.store_string(JSON.stringify(manifest, " "))
|
|
file.close()
|
|
return path
|
|
|
|
|
|
func _new_shell(parent: Node) -> 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, shell: Control, state_name: String, role := "state", extra := {}) -> Dictionary:
|
|
_verify_layout(shell, state_name)
|
|
await RenderingServer.frame_post_draw
|
|
var image := viewport.get_texture().get_image()
|
|
var path := output_root.path_join("battle-live-timeline-%dx%d-%s-100-%s.png" % [viewport_size.x, viewport_size.y, locale, state_name])
|
|
if image.is_empty() or image.get_width() != viewport_size.x or image.get_height() != viewport_size.y:
|
|
failures.append("invalid capture image for %s" % state_name)
|
|
return {}
|
|
if image.save_png(path) != OK:
|
|
failures.append("capture failed for %s" % state_name)
|
|
return {}
|
|
capture_count += 1
|
|
var record := {
|
|
"name": state_name,
|
|
"role": role,
|
|
"state": String(shell.battle_live_state),
|
|
"phase": int(shell.battle_live_event.get("phase", -1)),
|
|
"event_kind": String(shell.battle_live_event.get("kind", "")),
|
|
"file": path.get_file(),
|
|
"sha256": _file_sha256(path),
|
|
}
|
|
record.merge(_state_evidence(shell), true)
|
|
record.merge(extra, true)
|
|
capture_by_name[state_name] = record
|
|
if role == "state" or role == "boundary":
|
|
state_records.append(record)
|
|
else:
|
|
evidence_records.append(record)
|
|
return record
|
|
|
|
|
|
func _state_evidence(shell: Control) -> Dictionary:
|
|
var state_word := shell.find_child("BattleLiveEventState", true, false) as Label
|
|
var event_id_label := shell.find_child("BattleLiveEventId", true, false) as Label
|
|
var delta := shell.find_child("BattleLiveEventDelta", true, false) as Label
|
|
return {
|
|
"matrix_state": _matrix_state_for(String(shell.battle_live_state)),
|
|
"next_phase_index": int(shell.battle_live_observation.get("next_phase_index", -1)),
|
|
"event_id": String(shell.battle_live_event.get("event_id", "")),
|
|
"source_id": String(shell.battle_live_event.get("actor_id", "")),
|
|
"target_id": String(shell.battle_live_event.get("target_id", "")),
|
|
"state_word": state_word.text if state_word != null else "",
|
|
"state_word_visible": state_word != null and state_word.visible,
|
|
"event_id_visible": event_id_label != null and event_id_label.visible,
|
|
"delta_text": delta.text if delta != null else "",
|
|
"delta_visible": delta != null and delta.visible,
|
|
}
|
|
|
|
|
|
func _matrix_state_for(engine_state: String) -> String:
|
|
match engine_state:
|
|
"waiting_for_next_event", "event_forecast", "action_committed", "event_resolving", "event_resolved":
|
|
return engine_state
|
|
return ""
|
|
|
|
|
|
func _capture_static_only(viewport: SubViewport, shell: Control) -> void:
|
|
# M107-P2: authored/static ownership evidence. World, actors and rails stay;
|
|
# engine text and command controls hide through existing node visibility.
|
|
var hidden: Array[Node] = []
|
|
_set_engine_text_visible(shell, false, hidden)
|
|
_expect(not hidden.is_empty(), "static-only isolates at least one engine text or control node")
|
|
await _frames(2)
|
|
await _capture(viewport, shell, "static-only", "view", {
|
|
"hidden_kinds": ["Label", "BaseButton"],
|
|
"hidden_nodes": hidden.size(),
|
|
"kept": ["BattleLiveWorld", "BattleLiveArt", "BattleActors", "BattleEnemies", "rails", "actor_bars"],
|
|
})
|
|
_set_visible(hidden, true)
|
|
await _frames(1)
|
|
var restored := true
|
|
for node in hidden:
|
|
if is_instance_valid(node) and not (node as CanvasItem).visible:
|
|
restored = false
|
|
_expect(restored, "static-only capture restores every hidden node")
|
|
Dictionary(capture_by_name.get("static-only", {})).set("restored", restored)
|
|
|
|
|
|
func _capture_dynamic_neutral(viewport: SubViewport, shell: Control) -> void:
|
|
# M107-P2: dynamic state on a neutral surface. Scene art hides through
|
|
# existing node visibility; the neutral plate is a harness-only ColorRect and
|
|
# is removed before the next capture. No runtime chrome is added.
|
|
var hidden: Array[Node] = []
|
|
for node_name in ["BattleLiveWorld", "BattleLiveArt", "BattleActors", "BattleEnemies"]:
|
|
var node := shell.find_child(node_name, true, false) as CanvasItem
|
|
if node != null and node.visible:
|
|
node.visible = false
|
|
hidden.append(node)
|
|
var neutral := ColorRect.new()
|
|
neutral.name = "M107CaptureNeutralField"
|
|
neutral.color = Color("#5b6165")
|
|
neutral.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
neutral.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
shell.add_child(neutral)
|
|
shell.move_child(neutral, 0)
|
|
await _frames(2)
|
|
await _capture(viewport, shell, "dynamic-neutral", "view", {
|
|
"hidden_nodes": hidden.size(),
|
|
"hidden": ["BattleLiveWorld", "BattleLiveArt", "BattleActors", "BattleEnemies"],
|
|
"neutral": "#5b6165 harness ColorRect, removed after capture",
|
|
})
|
|
_expect(hidden.size() == 4, "dynamic-neutral isolates world, field art, actors and enemies")
|
|
neutral.queue_free()
|
|
_set_visible(hidden, true)
|
|
await _frames(2)
|
|
var restored := true
|
|
for node in hidden:
|
|
if is_instance_valid(node) and not (node as CanvasItem).visible:
|
|
restored = false
|
|
_expect(restored and not is_instance_valid(neutral), "dynamic-neutral restores the scene and removes the neutral plate")
|
|
Dictionary(capture_by_name.get("dynamic-neutral", {})).set("restored", restored)
|
|
Dictionary(capture_by_name.get("dynamic-neutral", {})).set("neutral_removed", not is_instance_valid(neutral))
|
|
|
|
|
|
func _set_engine_text_visible(node: Node, visible: bool, hidden: Array[Node]) -> void:
|
|
for child in node.get_children():
|
|
if child is Label or child is BaseButton:
|
|
var item := child as CanvasItem
|
|
if item.visible != visible:
|
|
item.visible = visible
|
|
if not visible:
|
|
hidden.append(child)
|
|
_set_engine_text_visible(child, visible, hidden)
|
|
|
|
|
|
func _set_visible(nodes: Array[Node], visible: bool) -> void:
|
|
for node in nodes:
|
|
if is_instance_valid(node):
|
|
(node as CanvasItem).visible = visible
|
|
|
|
|
|
func _file_sha256(path: String) -> String:
|
|
var file := FileAccess.open(path, FileAccess.READ)
|
|
if file == null:
|
|
return ""
|
|
var context := HashingContext.new()
|
|
context.start(HashingContext.HASH_SHA256)
|
|
var remaining := file.get_length()
|
|
while remaining > 0:
|
|
var chunk := mini(65536, remaining)
|
|
context.update(file.get_buffer(chunk))
|
|
remaining -= chunk
|
|
file.close()
|
|
return context.finish().hex_encode()
|
|
|
|
|
|
func _verify_layout(shell: Control, state_name: String) -> void:
|
|
var canvas := shell.find_child("BattleLiveCanvas", true, false) as Control
|
|
if canvas == null:
|
|
failures.append("%s has no contained live canvas" % state_name)
|
|
return
|
|
var actors := shell.find_child("BattleActors", true, false) as Control
|
|
var enemies := shell.find_child("BattleEnemies", true, false) as Control
|
|
if actors == null or actors.get_child_count() != 4:
|
|
failures.append("%s loses the complete Party line" % state_name)
|
|
if enemies == null or enemies.get_child_count() != 3:
|
|
failures.append("%s loses the complete enemy line" % state_name)
|
|
_verify_buttons(shell, state_name)
|
|
|
|
|
|
func _verify_buttons(node: Node, state_name: String) -> void:
|
|
for child in node.get_children():
|
|
if child is BaseButton and child.is_visible_in_tree():
|
|
var rect := (child as Control).get_global_rect()
|
|
if rect.size.x < 47.9 or rect.size.y < 47.9:
|
|
failures.append("%s button %s below 48px" % [state_name, child.name])
|
|
if rect.position.x < -1.0 or rect.position.y < -1.0 or rect.end.x > viewport_size.x + 1.0 or rect.end.y > viewport_size.y + 1.0:
|
|
failures.append("%s button %s outside viewport" % [state_name, child.name])
|
|
_verify_buttons(child, state_name)
|
|
|
|
|
|
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[2].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 _expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append(message)
|
|
|
|
|
|
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)
|