Untitled

Anonymous
plain_text
02/22/2026 10:53 PM
1.6 KB
11
Indexable
func load_scene(path: String, spawn_from: String = "left") -> void:

	if dialogue_ui and dialogue_ui.is_open():
		dialogue_ui.hide_dialogue()

	# --- Fade Out ---
	if fade_rect:
		fade_rect.visible = true
		fade_rect.modulate.a = 0.0
		var t_out := create_tween()
		t_out.tween_property(fade_rect, "modulate:a", 1.0, 0.25)
		await t_out.finished

	clear_scene()

	var packed := ResourceLoader.load(path)
	if packed == null:
		push_error("Main.load_scene: Failed to load: " + path)
		return
	if not (packed is PackedScene):
		push_error("Main.load_scene: Resource is not a PackedScene: " + path)
		return

	current_scene = (packed as PackedScene).instantiate()
	if current_scene == null:
		push_error("Main.load_scene: instantiate() failed: " + path)
		return

	# Bind UI BEFORE adding to tree so _ready() can use it.
	if current_scene.has_method("bind_ui"):
		current_scene.call("bind_ui", dialogue_ui, note_ui, fade_rect, item_get_overlay, self)

	if current_scene.has_method("set_spawn_from"):
		current_scene.call("set_spawn_from", spawn_from)

	scene_root.add_child(current_scene)

	# --- Fade In ---
	if fade_rect:
		var t_in := create_tween()
		t_in.tween_property(fade_rect, "modulate:a", 0.0, 0.25)
		await t_in.finished
		fade_rect.visible = false
Editor is loading...
Leave a Comment