seeding-planets/common/scene_manager/scene_manager.gd
Zacharie Guet 9c449b234f developpement d'écran de chargement et d'écran de sélection de niveau
* modification de certains assets
* optimisation de chunks
* ajout d'un SceneManager
* ajout d'un premier dialogue avec Demeter
* changement des jour en charge
* mise en place d'un système de run
* etc...
2026-01-10 13:04:33 +01:00

70 lines
2.4 KiB
GDScript

extends Node
const TITLE_SCREEN = "res://stages/title_screen/title_screen.tscn"
const PLANET_SCENE = "res://stages/terrain/planet/planet.tscn"
const TRUCK_SCENE = "res://stages/terrain/truck/truck.tscn"
const INTRO_SCENE = "res://stages/intro/intro.tscn"
const REGION_SELECTION_SCREEN = "res://stages/region_selection/region_selection.tscn"
signal scene_loaded
signal scene_node_ready
var loading_scene = false
var generating_node = false
var scene_to_load := ""
var next_scene_node : Node
@onready var current_scene_node : Node = get_tree().root.get_children().back()
func change_scene(scene_path : String, with_loading = true):
loading_scene = true
scene_to_load = scene_path
ResourceLoader.load_threaded_request(scene_to_load)
LoadingScreen.loading_text = "LOADING_SCENE"
var scene_to_hide = current_scene_node
if with_loading:
await LoadingScreen.show_loading_screen()
if scene_to_hide != null and scene_to_hide.has_method("hide"):
scene_to_hide.hide()
if loading_scene:
await scene_loaded
next_scene_node = ResourceLoader.load_threaded_get(scene_to_load).instantiate()
if next_scene_node.has_method("hide"):
next_scene_node.hide()
get_tree().root.add_child(next_scene_node)
generating_node = true
if next_scene_node is Planet:
LoadingScreen.loading_text = "GENERATING_TERRAIN"
if generating_node:
await scene_node_ready
if current_scene_node:
current_scene_node.queue_free()
current_scene_node = next_scene_node
if current_scene_node.has_method("show"):
current_scene_node.show()
if with_loading:
LoadingScreen.hide_loading_screen()
func _process(_delta):
if loading_scene:
var progress = []
var load_status := ResourceLoader.load_threaded_get_status(scene_to_load, progress)
LoadingScreen.loading_value = progress[0]
if load_status == ResourceLoader.THREAD_LOAD_LOADED:
loading_scene = false
scene_loaded.emit()
elif generating_node:
if next_scene_node is Planet:
LoadingScreen.loading_value = next_scene_node.generated_value
if next_scene_node.is_generated:
generating_node = false
scene_node_ready.emit()
elif next_scene_node.is_node_ready():
generating_node = false
scene_node_ready.emit()