189 lines
8.1 KiB
GDScript
189 lines
8.1 KiB
GDScript
extends SceneTree
|
|
|
|
const EntryShell = preload("res://entry/entry_shell.gd")
|
|
const InitialCompanyArt = preload("res://entry/initial_company_art.gd")
|
|
const SettingsStore = preload("res://entry/settings_store.gd")
|
|
const DraftService = preload("res://entry/initial_company_draft_service.gd")
|
|
|
|
const SEED := "1234567890abcdeffedcba0987654321"
|
|
const FIXTURES := [
|
|
{"width": 1280, "height": 720, "locale": "zh_CN", "scale": 1.0},
|
|
{"width": 1280, "height": 720, "locale": "en", "scale": 1.0},
|
|
{"width": 1280, "height": 720, "locale": "zh_CN", "scale": 1.3},
|
|
]
|
|
const STATES := ["choice", "choice_selected", "inspect", "compare", "review", "guild"]
|
|
|
|
var failures: Array[String] = []
|
|
var output_root := ""
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
output_root = OS.get_environment("ABG_EVIDENCE_DIR")
|
|
if output_root.is_empty():
|
|
output_root = "/tmp/abg-dev2-choice-captures"
|
|
DirAccess.make_dir_recursive_absolute(output_root)
|
|
var fixture_indexes := range(FIXTURES.size())
|
|
var requested_fixture := OS.get_environment("ABG_CAPTURE_FIXTURE_INDEX")
|
|
if not requested_fixture.is_empty():
|
|
var fixture_index := requested_fixture.to_int()
|
|
if fixture_index < 0 or fixture_index >= FIXTURES.size() or str(fixture_index) != requested_fixture:
|
|
push_error("invalid ABG_CAPTURE_FIXTURE_INDEX: %s" % requested_fixture)
|
|
quit(2)
|
|
return
|
|
fixture_indexes = [fixture_index]
|
|
var count := 0
|
|
for fixture_index in fixture_indexes:
|
|
var fixture: Dictionary = FIXTURES[fixture_index]
|
|
for state in STATES:
|
|
await capture_fixture(fixture, state, count)
|
|
count += 1
|
|
if failures.is_empty():
|
|
var fixture_scope := requested_fixture if not requested_fixture.is_empty() else "all"
|
|
print("ABG_DEV2_INITIAL_COMPANY_CAPTURE_OK frames=%d fixture_scope=%s states=choice,choice_selected,inspect,compare,review,guild matrix=1280x720:zh_CN,en:100,130 renderer=normal" % [count, fixture_scope])
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func capture_fixture(fixture: Dictionary, state: String, ordinal: int) -> void:
|
|
var draft_path := "user://dev2_choice_capture_%d.json" % ordinal
|
|
_cleanup_path(draft_path)
|
|
var service = DraftService.new()
|
|
service.path = draft_path
|
|
service.company_path = "%s.company" % draft_path
|
|
service.begin_or_load(SEED)
|
|
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 = "%s.company" % draft_path
|
|
viewport.add_child(shell)
|
|
await _frames(3)
|
|
shell.settings = SettingsStore.new().defaults()
|
|
shell.settings.setup_completed = true
|
|
shell.settings.locale = String(fixture.locale)
|
|
shell.settings.text_scale = float(fixture.scale)
|
|
shell.show_initial_company()
|
|
await _frames(4)
|
|
var page = shell.initial_company_page
|
|
match state:
|
|
"choice_selected":
|
|
page.toggle_candidate(0)
|
|
page.toggle_candidate(1)
|
|
"inspect": page.inspect_candidate(1)
|
|
"compare":
|
|
page.inspected_index = 0
|
|
page.set_compare_a()
|
|
page.inspected_index = 2
|
|
page.set_compare_b()
|
|
page.show_compare()
|
|
"review":
|
|
page.toggle_candidate(0)
|
|
page.toggle_candidate(1)
|
|
page.request_review()
|
|
"guild":
|
|
page.toggle_candidate(0)
|
|
page.toggle_candidate(1)
|
|
page.request_review()
|
|
page.create_company()
|
|
await _frames(5)
|
|
verify_controls_inside(shell, fixture, state)
|
|
if state == "guild":
|
|
verify_guild_layout(shell)
|
|
else:
|
|
verify_primary_layout(page, state)
|
|
await RenderingServer.frame_post_draw
|
|
var image := viewport.get_texture().get_image()
|
|
var name := "%s-%dx%d-%s-%d.png" % [state, int(fixture.width), int(fixture.height), String(fixture.locale), int(round(float(fixture.scale) * 100.0))]
|
|
var error := image.save_png(output_root.path_join(name))
|
|
if error != OK:
|
|
failures.append("capture %s failed: %s" % [name, error])
|
|
viewport.queue_free()
|
|
await _frames(4)
|
|
_cleanup_path(draft_path)
|
|
|
|
|
|
func verify_primary_layout(page: Control, state: String) -> void:
|
|
if state in ["choice", "choice_selected"]:
|
|
var row: HBoxContainer = page.find_child("CandidateRow", true, false)
|
|
expect(row != null and row.get_child_count() == 4, "choice has four columns")
|
|
var previous_end := -1.0
|
|
for index in range(row.get_child_count()):
|
|
var child: Control = row.get_child(index)
|
|
var rect: Rect2 = child.get_global_rect()
|
|
expect(rect.size.x > 100.0 and rect.size.y > 120.0, "candidate plate keeps stable readable dimensions")
|
|
expect(rect.position.x >= previous_end, "candidate plates do not overlap")
|
|
previous_end = rect.end.x
|
|
var portrait := page.find_child("CandidatePortrait_%d" % index, true, false) as TextureRect
|
|
expect(portrait != null and portrait.texture == InitialCompanyArt.texture_for(page.draft.offers[index]), "candidate person-button shows its Profession sticker")
|
|
if state == "choice_selected":
|
|
expect(not page.find_child("ReviewCompany", true, false).disabled, "selected fixture visibly enables Review")
|
|
elif state == "inspect":
|
|
expect(page.find_child("InspectPortraitStagePortrait", true, false) != null and page.find_child("InspectSelect", true, false).size.y >= 48.0, "Inspect portrait and 48px action fit")
|
|
elif state == "compare":
|
|
expect(page.find_child("ComparePortraitAPortrait", true, false) != null and page.find_child("ComparePortraitBPortrait", true, false) != null, "Compare portrait columns fit")
|
|
else:
|
|
expect(page.find_child("ReviewSelectedPortrait_0Portrait", true, false) != null and page.find_child("ReviewSelectedPortrait_1Portrait", true, false) != null, "Review shows exactly two selected members")
|
|
expect(page.find_child("ReviewUnchosen", true, false).get_child_count() >= 4, "Review names both unchosen offers and their consequence")
|
|
|
|
|
|
func verify_guild_layout(shell: Control) -> void:
|
|
expect(shell.current_screen == "guild_handoff", "Create Company reaches Guild handoff")
|
|
expect(shell.find_child("GuildRoster", true, false).get_child_count() == 2, "Guild shows exactly two persistent members")
|
|
expect(shell.find_child("GuildMemberPortraitTexture_0", true, false) != null and shell.find_child("GuildMemberPortraitTexture_1", true, false) != null, "Guild keeps the persistent pair visible as standing Recruit stickers")
|
|
expect(shell.find_child("GuildContractSticker", true, false) != null and shell.find_child("GuildMarketSticker", true, false) != null, "Guild future destinations use illustrated object stickers")
|
|
expect(not shell.find_child("GuildContractBoard", true, false).disabled and shell.find_child("GuildMarketUnavailable", true, false).disabled, "Guild enables Contract Board while Market waits for Contract creation")
|
|
|
|
|
|
func verify_controls_inside(shell: Control, fixture: Dictionary, state: String) -> void:
|
|
var bounds := Rect2(Vector2.ZERO, Vector2(float(fixture.width), float(fixture.height)))
|
|
for node in _all_controls(shell):
|
|
if not node.visible or node is TextureRect or node is ColorRect or node is Container:
|
|
continue
|
|
var rect := node.get_global_rect()
|
|
if rect.size.x <= 0.0 or rect.size.y <= 0.0:
|
|
continue
|
|
if not bounds.encloses(rect):
|
|
failures.append("%s %dx%d %s outside bounds: %s" % [state, int(fixture.width), int(fixture.height), node.name, rect])
|
|
|
|
|
|
func _all_controls(root_control: Control) -> Array[Control]:
|
|
var result: Array[Control] = []
|
|
var pending: Array[Node] = [root_control]
|
|
while not pending.is_empty():
|
|
var node: Node = pending.pop_back()
|
|
if node is Control:
|
|
result.append(node)
|
|
for child in node.get_children():
|
|
pending.append(child)
|
|
return result
|
|
|
|
|
|
func _cleanup_path(base: String) -> void:
|
|
for suffix in ["", ".bak", ".candidate", ".bak.candidate", ".corrupt"]:
|
|
var file_path := "%s%s" % [base, suffix]
|
|
if FileAccess.file_exists(file_path):
|
|
DirAccess.remove_absolute(file_path)
|
|
var company_file := "%s.company%s" % [base, suffix]
|
|
if FileAccess.file_exists(company_file):
|
|
DirAccess.remove_absolute(company_file)
|
|
|
|
|
|
func _frames(count: int) -> void:
|
|
for frame in range(count):
|
|
await process_frame
|
|
|
|
|
|
func expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
failures.append("DEV-2 Recruit choice capture: %s" % message)
|