Files
seeding-planets/common/scene_manager/scripts/scene_manager.gd
Zacharie Guet d45fab6a3d Feature pour l'alpha 1.3
* Ajout d'un mode infini (pour nos hard core gamers)
* Ajout d'un message de découverte d'un nouvel outil
* Séparation de la pelle en deux outils : la pioche et la fourche
* Amélioration de la lisibilité des capsules d'énergies
* Changement léger des texture du sol et de la pierre
* Correction d'un bug lors du clic frénétique sur le porte de sortie du vaisseau
* Ajout d'un icône de recharge
* Fix de la mutation Ancien qui ne s'améliorait pas au niveau 4

+ début de dev des artefacts avec un distributeur
2026-03-27 17:28:20 +01:00

100 lines
3.2 KiB
GDScript

extends Node
@export var scenes : Array[Scene]
signal scene_loaded(scene : Scene)
signal scene_node_ready(scene : Scene)
var actual_scene = null
var loading_scene = false
var generating_node = false
var next_scene_node : Node
@onready var current_scene_node : Node = get_tree().root.get_children().back()
func search_scenes(scene_id : String) -> Scene:
var scene_pos : int = scenes.find_custom(
func (s : Scene):
return s.scene_id == scene_id
)
if scene_pos == -1:
return null
else :
return scenes[scene_pos]
func change_to_scene_id(scene_id : String, with_loading = true):
var scene = search_scenes(scene_id)
if not scene:
printerr("Scene %s not found" % scene_id)
return
if not loading_scene:
change_to_scene(scene, with_loading)
func change_to_scene(scene : Scene, with_loading = true):
if loading_scene or generating_node:
await scene_node_ready
actual_scene = scene
loading_scene = true
var scene_path_to_load = scene.scene_path
ResourceLoader.load_threaded_request(scene_path_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_path_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 scene.need_terrain_generated:
LoadingScreen.loading_text = "GENERATING_TERRAIN"
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()
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED if scene.mouse_captured else Input.MOUSE_MODE_VISIBLE
GameInfo.update_inputs()
if actual_scene.need_to_be_saved:
GameInfo.game_data.last_game_scene = scene
GameInfo.save_game_data()
if with_loading:
LoadingScreen.hide_loading_screen()
func _process(_delta):
if loading_scene:
var progress = []
var load_status := ResourceLoader.load_threaded_get_status(actual_scene.scene_path, progress)
LoadingScreen.loading_value = progress[0]
if load_status == ResourceLoader.THREAD_LOAD_LOADED:
loading_scene = false
scene_loaded.emit(actual_scene)
if load_status == ResourceLoader.THREAD_LOAD_FAILED or load_status == ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
printerr()
elif generating_node:
if next_scene_node is Region:
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(actual_scene)