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 DRAFT_PATH := "user://dev4_party_draft.json" const COMPANY_PATH := "user://dev4_party_company.json" const SEED := "abcdef0123456789fedcba9876543210" const CONTRACT_OP := "a0a0a0a0b1b1b1b1c2c2c2c2d3d3d3d3" const HIRE_OP_1 := "01010101212121213232323243434343" const HIRE_OP_2 := "45454545656565657676767687878787" var failures: Array[String] = [] var parsed_touches := 0 func _initialize() -> void: call_deferred("run_test") func run_test() -> void: _cleanup() root.content_scale_mode = Window.CONTENT_SCALE_MODE_CANVAS_ITEMS root.content_scale_aspect = Window.CONTENT_SCALE_ASPECT_EXPAND root.size = Vector2i(844, 390) var company := _create_company() if not company.is_empty(): await verify_party_line(company, "en") await verify_party_line(company, "zh_CN") _cleanup() if failures.is_empty(): print("ABG_DEV4_PARTY_OK screen=party_line members=4 orientation=rear_left_front_right position0=front select_destination=true drag=false preview_only=true undo=true reset=true back=guild restart=party_line locales=zh_CN,en text_130=true parsed_touch=%d" % parsed_touches) quit(0) else: for failure in failures: push_error(failure) quit(1) func verify_party_line(company: Dictionary, locale: String) -> void: var settings := SettingsStore.new().defaults() settings.setup_completed = true settings.locale = locale settings.text_scale = 1.3 var shell := EntryShell.new() shell.auto_start = false shell.initial_company_service.path = DRAFT_PATH shell.initial_company_service.company_path = COMPANY_PATH root.add_child(shell) await _frames(3) shell.settings = settings shell.setup_draft = settings.duplicate(true) shell.show_market(company) await _frames(4) # The current Market is inspect-only. Party ordering is a Guild-owned # destination, so follow the approved Market -> Guild -> Party route rather # than expecting a retired MarketFormation command. var market_back := shell.find_child("MarketBackGuild", true, false) as Button expect(market_back != null and not market_back.disabled, "%s Market exposes Back to Guild" % locale) await _touch(market_back) expect(shell.current_screen == "guild_handoff", "%s Market returns to Guild before Party" % locale) var formation_button := shell.find_child("GuildParty", true, false) as Button expect(formation_button != null and not formation_button.disabled, "%s Guild exposes an enabled Party destination" % locale) await _touch(formation_button) expect(shell.current_screen == "party_line", "%s Market reaches Party Line" % locale) expect(shell.party_view_data.ok and shell.party_view_data.page_id == "party_line", "%s Party Line consumes controller view data" % locale) expect(shell.app_services.resolve_service(&"party_line_page_controller") == shell.party_line_page_controller, "%s AppServices exposes the Party controller" % locale) expect(shell.party_view_data.order.front_to_rear_ids == shell.party_draft_order, "%s controller preserves the current draft order" % locale) await _frames(3) var order: Array[String] = shell.party_draft_order.duplicate() expect(order.size() == 4, "%s Party Line has four members" % locale) var positions: Array[float] = [] for position in range(4): var member := shell.find_child("PartyPosition%d" % position, true, false) as Button expect(member != null and member.find_child("PartyPortrait", true, false) != null, "%s position %d is a person-bearing control" % [locale, position]) if member != null: positions.append(member.get_global_rect().position.x) expect(member.get_global_rect().size.x >= 48.0 and member.get_global_rect().size.y >= 48.0, "%s position %d keeps 48px touch size" % [locale, position]) expect(member.get_global_rect().position.x >= -0.5 and member.get_global_rect().position.y >= -0.5 and member.get_global_rect().end.x <= 844.5 and member.get_global_rect().end.y <= 390.5, "%s position %d stays inside the landscape viewport" % [locale, position]) expect(positions.size() == 4 and positions[3] < positions[2] and positions[2] < positions[1] and positions[1] < positions[0], "%s visual order places rear left and position 0 right" % locale) expect("0" in shell.find_child("PartyOrientation", true, false).text and shell.find_child("PartyFirstThreat", true, false) != null, "%s exposes position zero and first threat" % locale) var cord := shell.find_child("PartyFormationCord", true, false) as Control var effects := shell.find_child("PartyFormationEffects", true, false) as Control var overlay := shell.find_child("PartyMasterOverlay", true, false) as Control expect(cord != null and effects != null and overlay != null and cord.get_index() < effects.get_index(), "%s separates cord and effect layers" % locale) for position in range(4): var actor := shell.find_child("PartyPosition%d" % position, true, false) as Control expect(actor != null and cord.get_index() < actor.get_index() and actor.get_index() < effects.get_index() and cord.z_index < actor.z_index and actor.z_index < effects.z_index, "%s actor %d is between cord and effects" % [locale, position]) for node_name in ["PartyRelationSummary", "PartyFirstThreat"]: var summary := shell.find_child(node_name, true, false) as Label expect(summary != null and summary.get_theme_font_size("font_size") >= 10, "%s %s uses readable actual-size copy" % [locale, node_name]) if summary != null: expect(summary.text_overrun_behavior == TextServer.OVERRUN_NO_TRIMMING, "%s %s avoids ellipsis" % [locale, node_name]) expect_text_lines_fit(summary, "%s %s" % [locale, node_name]) for node_name in ["PartyUndo", "PartyReset", "PartySaveReview", "PartyBack"]: var command := shell.find_child(node_name, true, false) as Button var label := command.get_node_or_null("ButtonLabel") as Label if command != null else null expect(command != null and command.get_global_rect().size.x >= 48.0 and command.get_global_rect().size.y >= 48.0, "%s %s keeps 48px command target" % [locale, node_name]) expect(label != null and label.get_theme_font_size("font_size") >= 11 and label.text_overrun_behavior == TextServer.OVERRUN_NO_TRIMMING, "%s %s keeps readable command label" % [locale, node_name]) if label != null: expect_text_lines_fit(label, "%s %s" % [locale, node_name]) var save := shell.find_child("PartySaveReview", true, false) as Button expect(save != null and String(save.get_meta("party_command_role", "")) == "primary", "%s Save is marked as primary" % locale) for node_name in ["PartyUndo", "PartyReset"]: var command := shell.find_child(node_name, true, false) as Button expect(command != null and bool(command.get_meta("party_command_disabled_emphasis", false)) == command.disabled, "%s %s disabled emphasis is truthful" % [locale, node_name]) await _frames(2) expect(shell.get_viewport().gui_get_focus_owner() == shell.find_child("PartyPosition3", true, false), "%s focuses the rear-left member first" % locale) for expected_name in ["PartyPosition2", "PartyPosition1", "PartyPosition0", "PartyUndo", "PartyReset", "PartySaveReview", "PartyBack"]: await _focus_next() var focus_owner := shell.get_viewport().gui_get_focus_owner() expect(focus_owner == shell.find_child(expected_name, true, false), "%s keyboard/controller focus reaches %s, got %s" % [locale, expected_name, focus_owner.name if focus_owner != null else "none"]) var before_hash := String(_draft_service().load_company().company.company_hash) var front := shell.find_child("PartyPosition0", true, false) as Button await _touch(front) await _touch(shell.find_child("PartyPosition3", true, false) as Button) var swapped: Array[String] = shell.party_draft_order.duplicate() expect(swapped[0] == order[3] and swapped[3] == order[0], "%s select-then-destination swaps two positions" % locale) expect(not shell.party_notice.is_empty() and shell.find_child("PartyRelationSummary", true, false) != null, "%s swap names changed relation preview" % locale) expect(String(_draft_service().load_company().company.company_hash) == before_hash, "%s preview does not persist an uncommitted move" % locale) await _touch(shell.find_child("PartyUndo", true, false)) expect(shell.party_draft_order == order, "%s Undo restores the prior order" % locale) await _touch(shell.find_child("PartyPosition0", true, false)) await _touch(shell.find_child("PartyPosition3", true, false)) await _touch(shell.find_child("PartyReset", true, false)) expect(shell.party_draft_order == order, "%s Reset restores automatic order" % locale) await _touch(shell.find_child("PartyBack", true, false)) expect(shell.current_screen == "guild_handoff", "%s Back returns to Guild" % locale) shell.queue_free() await _frames(3) var resumed := EntryShell.new() resumed.auto_start = false resumed.initial_company_service.path = DRAFT_PATH resumed.initial_company_service.company_path = COMPANY_PATH root.add_child(resumed) await _frames(2) resumed.settings = settings resumed.setup_draft = settings.duplicate(true) resumed._open_company_destination(_draft_service().load_company().company) await _frames(3) expect(resumed.current_screen == "party_line" and resumed.find_child("PartyPosition0", true, false) != null, "%s Continue restores the Party Line after restart" % locale) resumed.queue_free() await _frames(3) func _create_company() -> Dictionary: var draft: Dictionary = _draft_service().begin_or_load(SEED) if not draft.ok: expect(false, "fixture creates Initial Company draft") 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: expect(false, "fixture commits Company") return {} var created: Dictionary = _contract_service().create_contract(CONTRACT_OP, "CTR-R1-01", "standard") if not created.ok: expect(false, "fixture creates Contract") return {} var offers: Array = created.company.active_contract.market_board.recruit_offers var first: Dictionary = _contract_service().hire_recruit(HIRE_OP_1, String(offers[0].source_offer_id), 14) var second: Dictionary = _contract_service().hire_recruit(HIRE_OP_2, String(offers[1].source_offer_id), 14) expect(first.ok and second.ok, "fixture completes two hires") return second.company if second.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 _touch(control: Control) -> void: if control == null: expect(false, "touch target exists") return var center := control.get_global_rect().get_center() var press := InputEventScreenTouch.new() press.position = center press.pressed = true press.index = 0 Input.parse_input_event(press) await _frames(2) var release := InputEventScreenTouch.new() release.position = center release.pressed = false release.index = 0 Input.parse_input_event(release) parsed_touches += 1 await _frames(5) func _focus_next() -> void: var press := InputEventAction.new() press.action = "ui_focus_next" press.pressed = true Input.parse_input_event(press) await _frames(2) var release := InputEventAction.new() release.action = "ui_focus_next" release.pressed = false Input.parse_input_event(release) await _frames(2) 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) func expect(condition: bool, message: String) -> void: if not condition: failures.append("DEV-4 Party Line: %s" % message) func expect_text_lines_fit(label: Label, context: String) -> void: var font := label.get_theme_font("font") var font_size := label.get_theme_font_size("font_size") var lines := label.text.split("\n") var required_height := float(font.get_height(font_size) * lines.size()) expect(required_height <= label.size.y + 1.0, "%s text height fits: required=%.1f available=%.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 expect(required_width <= label.size.x + 1.0, "%s line fits: required=%.1f available=%.1f text=%s" % [context, required_width, label.size.x, line])