69 lines
3.5 KiB
GDScript
69 lines
3.5 KiB
GDScript
extends SceneTree
|
|
|
|
const BootstrapScript := preload("res://scripts/bootstrap.gd")
|
|
|
|
const DESIGN_SIZE := Vector2(640.0, 960.0)
|
|
const BACKGROUND_SOURCE_SIZE := Vector2(941.0, 1672.0)
|
|
const BAR_SOURCE_SIZE := Vector2(1117.0, 223.0)
|
|
const BAR_WIDTH := 500.0
|
|
const BAR_SIZE := Vector2(BAR_WIDTH, BAR_WIDTH * BAR_SOURCE_SIZE.y / BAR_SOURCE_SIZE.x)
|
|
const BAR_POSITION := Vector2((DESIGN_SIZE.x - BAR_SIZE.x) * 0.5, 792.0)
|
|
|
|
var _failures: Array[String] = []
|
|
|
|
|
|
func _init() -> void:
|
|
_run.call_deferred()
|
|
|
|
|
|
func _run() -> void:
|
|
await process_frame
|
|
var bootstrap := BootstrapScript.new()
|
|
bootstrap.call("_build_loading_ui")
|
|
var layer := bootstrap.get_node_or_null("LoadingLayer") as Control
|
|
_expect(layer != null, "loading layer should be created")
|
|
if layer != null:
|
|
var background := layer.get_node_or_null("Background") as TextureRect
|
|
_expect(background != null and background.texture != null, "loading background should render texture")
|
|
var expected_bg_size := _cover_size(BACKGROUND_SOURCE_SIZE, DESIGN_SIZE)
|
|
_expect(background != null and background.stretch_mode == TextureRect.STRETCH_SCALE, "loading background should use computed source-size fit")
|
|
_expect(background != null and _near(background.size.x, expected_bg_size.x), "loading background width should match source-size fit: %.2f expected %.2f" % [background.size.x if background != null else -1.0, expected_bg_size.x])
|
|
_expect(background != null and _near(background.size.y, expected_bg_size.y), "loading background height should match source-size fit: %.2f expected %.2f" % [background.size.y if background != null else -1.0, expected_bg_size.y])
|
|
_expect(background != null and _near(background.position.y, (DESIGN_SIZE.y - expected_bg_size.y) * 0.5), "loading background should remain vertically centered")
|
|
var bar := layer.get_node_or_null("ProgressBar") as Control
|
|
_expect(bar != null, "loading progress bar should exist")
|
|
_expect(bar != null and _near(bar.position.x, BAR_POSITION.x), "loading progress bar should be centered")
|
|
_expect(bar != null and _near(bar.position.y, BAR_POSITION.y), "loading progress bar y should match loading layout")
|
|
_expect(bar != null and _near(bar.size.x, BAR_SIZE.x), "loading progress bar width should use adapted source ratio")
|
|
_expect(bar != null and _near(bar.size.y, BAR_SIZE.y), "loading progress bar height should use adapted source ratio")
|
|
var clip := layer.get_node_or_null("ProgressBar/FillClip") as Control
|
|
var percent := layer.get_node_or_null("ProgressBar/Percent") as Label
|
|
bootstrap.call("_set_loading_progress", 0.5)
|
|
_expect(clip != null and _near(clip.size.x, BAR_SIZE.x * 0.5), "loading fill width should match 50 percent")
|
|
_expect(percent != null and percent.text == "50%", "loading percent text should show 50%")
|
|
bootstrap.call("_set_loading_progress", 1.0)
|
|
_expect(clip != null and _near(clip.size.x, BAR_SIZE.x), "loading fill width should match 100 percent")
|
|
_expect(percent != null and percent.text == "100%", "loading percent text should show 100%")
|
|
bootstrap.queue_free()
|
|
if not _failures.is_empty():
|
|
for failure in _failures:
|
|
push_error(failure)
|
|
quit(1)
|
|
return
|
|
print("Loading screen verification passed.")
|
|
quit()
|
|
|
|
|
|
func _expect(condition: bool, message: String) -> void:
|
|
if not condition:
|
|
_failures.append(message)
|
|
|
|
|
|
func _near(value: float, expected: float) -> bool:
|
|
return absf(value - expected) <= 0.5
|
|
|
|
|
|
func _cover_size(source_size: Vector2, target_size: Vector2) -> Vector2:
|
|
var scale := maxf(target_size.x / source_size.x, target_size.y / source_size.y)
|
|
return source_size * scale
|