Files
puzzle-quest/scripts/Global.gd
T
Vaillant Jeremy 01ea3af253 Run godot --convert-3to4 (automated conversion)
Apply Godot 4.6 automated conversion: renames Spatial.translate->position,
margin_*->offset_*, tool->@tool, .empty()->.is_empty(), DynamicFont->FontFile,
onready->@onready, export()->@export, and many more.

127 files changed by the tool. Manual fixes still required for:
 - godot_db_manager plugin (incompatible APIs: WindowDialog, Tabs, etc.)
 - lod plugin (Spatial -> Node3D renames)
 - ResourceLoader.load_interactive removed -> load_threaded_request
 - OS.set_window_fullscreen removed -> DisplayServer
 - Viewport.set_size_override removed

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 19:18:27 +02:00

81 lines
2.1 KiB
GDScript

extends Control
const TICKS_TIME_MAX = 100 # msec
@onready var current_scene = null
@onready var current_scene_int = null
@onready var loader = null
@onready var wait_frames = 1
@onready var database = null
@onready var loaded = false
@onready var animation = Loading.get_node("AnimLoading")
func _ready():
database = load("res://scripts/Database.gd").new().initialize()
_initialize_current_scene()
_initialize_loading_scene()
func _initialize_loading_scene():
animation.connect("animation_started", Callable(Event, "_loading_is_started"))
animation.connect("animation_finished", Callable(Event, "_loading_is_finished"))
func goto_scene(path):
print("[global#goto_scene] : load scene "+String(path))
loader = ResourceLoader.load_threaded_request(path)
if loader == null:
print("Error loading ....")
return
Loading.show()
animation.play("BorderAnim")
set_process(true)
current_scene.queue_free()
wait_frames = 1
Loading.get_node("LoadingBare/VBoxContainer/HBoxContainer/ProgressBar").set_max(loader.get_stage_count())
func _process(_delta):
if loader == null:
set_process(false)
return
if wait_frames > 0:
wait_frames -= 1
var tick = Time.get_ticks_msec()
# Use "TICKS_TIME_MAX" to control for how long we block this thread
while Time.get_ticks_msec() < tick + TICKS_TIME_MAX:
if loaded:
var err = loader.poll()
if err == ERR_FILE_EOF: # Finished loading.
_set_new_scene()
break
elif err == OK:
_update_progress()
else:
loader = null
break
## PRIVATE
func _initialize_current_scene():
print("[global#_initialize_current_scene]")
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() - 1)
if current_scene.name != "Main":
get_node("/root/Loading").hide()
func _update_progress():
Loading.visible = true
Loading.get_node("LoadingBare/VBoxContainer/HBoxContainer/ProgressBar").set_value(loader.get_stage())
func _set_new_scene():
var resource = loader.get_resource()
loader = null
current_scene = resource.instantiate()
get_node("/root").add_child(current_scene)
Loading.hide()