102 lines
4.5 KiB
GDScript
102 lines
4.5 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 DRAFT_PATH := "user://dev3_responsive_layout_draft.json"
|
|
const COMPANY_PATH := "user://dev3_responsive_layout_company.json"
|
|
const SEED := "abcdef0123456789abcdef0123456789"
|
|
const DESIGN_ASPECT := 16.0 / 9.0
|
|
const SIZES := [Vector2i(800, 500), Vector2i(960, 540), Vector2i(1280, 600)]
|
|
|
|
var failures: Array[String] = []
|
|
|
|
|
|
func _initialize() -> void:
|
|
call_deferred("run_test")
|
|
|
|
|
|
func run_test() -> void:
|
|
_cleanup()
|
|
var company := _create_company()
|
|
var viewport := SubViewport.new()
|
|
viewport.size = SIZES[0]
|
|
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 = "en"
|
|
shell.settings = settings
|
|
shell.show_guild_handoff(company)
|
|
await _frames(4)
|
|
for viewport_size in SIZES:
|
|
viewport.size = viewport_size
|
|
await _frames(3)
|
|
_verify_layout(shell, viewport_size)
|
|
if failures.is_empty():
|
|
print("ABG_DEV3_GUILD_RESPONSIVE_OK sizes=800x500,960x540,1280x600 canvas=16:9 centered world=full resize=true")
|
|
quit(0)
|
|
else:
|
|
for failure in failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
|
|
|
|
func _verify_layout(shell: Control, viewport_size: Vector2i) -> void:
|
|
var bounds := Rect2(Vector2.ZERO, Vector2(viewport_size))
|
|
var world := shell.find_child("GuildMasterWorldExtension", true, false) as TextureRect
|
|
var canvas := shell.find_child("GuildMasterDesignCanvas", true, false) as Control
|
|
var layered_world := shell.find_child("GuildMasterLayeredWorld", true, false) as TextureRect
|
|
var top_rail := shell.find_child("GuildTopRail", true, false) as Control
|
|
var bottom_rail := shell.find_child("GuildBottomRail", true, false) as Control
|
|
expect(world != null and canvas != null and layered_world != null and top_rail != null and bottom_rail != null, "%dx%d layered composition layers exist" % [viewport_size.x, viewport_size.y])
|
|
if world == null or canvas == null or layered_world == null:
|
|
return
|
|
var canvas_rect := canvas.get_global_rect()
|
|
expect(bounds.encloses(canvas_rect), "%dx%d canvas is fully visible" % [viewport_size.x, viewport_size.y])
|
|
expect(is_equal_approx(canvas_rect.size.x / canvas_rect.size.y, DESIGN_ASPECT), "%dx%d canvas preserves 16:9" % [viewport_size.x, viewport_size.y])
|
|
expect(canvas_rect.get_center().is_equal_approx(bounds.get_center()), "%dx%d canvas is centered" % [viewport_size.x, viewport_size.y])
|
|
expect(world.get_global_rect().is_equal_approx(bounds), "%dx%d World fills the viewport" % [viewport_size.x, viewport_size.y])
|
|
expect(layered_world.get_global_rect().is_equal_approx(canvas_rect), "%dx%d layered world stays inside the canvas" % [viewport_size.x, viewport_size.y])
|
|
var viewport_aspect := float(viewport_size.x) / float(viewport_size.y)
|
|
if viewport_aspect < DESIGN_ASPECT:
|
|
expect(is_equal_approx(canvas_rect.size.x, float(viewport_size.x)) and canvas_rect.position.y > 0.0, "%dx%d uses vertical World extension" % [viewport_size.x, viewport_size.y])
|
|
elif is_equal_approx(viewport_aspect, DESIGN_ASPECT):
|
|
expect(canvas_rect.is_equal_approx(bounds), "%dx%d uses the complete device frame" % [viewport_size.x, viewport_size.y])
|
|
else:
|
|
expect(is_equal_approx(canvas_rect.size.y, float(viewport_size.y)) and canvas_rect.position.x > 0.0, "%dx%d uses horizontal World extension" % [viewport_size.x, viewport_size.y])
|
|
|
|
|
|
func _create_company() -> Dictionary:
|
|
var service := DraftService.new()
|
|
service.path = DRAFT_PATH
|
|
service.company_path = COMPANY_PATH
|
|
var draft: Dictionary = service.begin_or_load(SEED)
|
|
service.set_selection([String(draft.draft.offers[0].offer_id), String(draft.draft.offers[2].offer_id)])
|
|
return service.commit_company().company
|
|
|
|
|
|
func _cleanup() -> void:
|
|
for base in [DRAFT_PATH, COMPANY_PATH]:
|
|
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)
|
|
|
|
|
|
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-3 responsive: %s" % message)
|