176 lines
8.0 KiB
GDScript
176 lines
8.0 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 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)
|
|
var formation_button := shell.find_child("MarketFormation", true, false) as Button
|
|
expect(formation_button != null and not formation_button.disabled, "%s Market exposes an enabled Establish Line action" % locale)
|
|
await _touch(formation_button)
|
|
expect(shell.current_screen == "party_line", "%s Market reaches Party Line" % 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 >= 44.0 and member.get_global_rect().size.y >= 44.0, "%s position %d keeps 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)
|
|
expect(shell.find_child("PartySaveReview", true, false) != null and not shell.find_child("PartySaveReview", true, false).disabled, "%s enables the atomic Save & Review action" % locale)
|
|
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 _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)
|