ajout d'un script autoload.

This commit is contained in:
osquallo 2018-08-06 17:43:56 +02:00
parent 0d72211bd6
commit 927753f6d1
4 changed files with 51 additions and 3 deletions

View file

@ -15,6 +15,10 @@ run/main_scene="res://scenes/Main.tscn"
boot_splash/image="res://assets/GUI/images/new_launcher_bg_0-1.png" boot_splash/image="res://assets/GUI/images/new_launcher_bg_0-1.png"
config/icon="res://icon.png" config/icon="res://icon.png"
[autoload]
global="*res://scenes/global.gd"
[display] [display]
window/size/test_width=1024 window/size/test_width=1024

View file

@ -11,7 +11,7 @@ func _ready():
get_tree().get_root().connect("size_changed", self, "on_window_size_changed") get_tree().get_root().connect("size_changed", self, "on_window_size_changed")
# $GUI.pause() # $GUI.pause()
$GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/camera.make_current() global.character_creation_camera.make_current()
$Game.hide() $Game.hide()
# BugGodot?: Meme si tous les nodes parent sont caché les gridmaps s'affichent quand meme :/ # BugGodot?: Meme si tous les nodes parent sont caché les gridmaps s'affichent quand meme :/
@ -40,6 +40,6 @@ func _on_GUI_character_creation_finished():
$Game/World/GridMaps/Ground.show() $Game/World/GridMaps/Ground.show()
$Game/World/GridMaps/wall.show() $Game/World/GridMaps/wall.show()
$Game/World/GridMaps/ceilling.show() $Game/World/GridMaps/ceilling.show()
$Game/Character/Camera_rotation_helper/Camera.make_current() global.character_camera.make_current()
$GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene.hide() $GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene.hide()
$Game/Character/MeshInstance.get_surface_material(0).albedo_color = $GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/mesh_instance.get_surface_material(0).albedo_color $Game/Character/MeshInstance.get_surface_material(0).albedo_color = $GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/mesh_instance.get_surface_material(0).albedo_color

View file

@ -4,7 +4,7 @@
[ext_resource path="res://scenes/Game/Game.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/Game/Game.tscn" type="PackedScene" id=2]
[ext_resource path="res://scenes/GUI/GUI.tscn" type="PackedScene" id=3] [ext_resource path="res://scenes/GUI/GUI.tscn" type="PackedScene" id=3]
[node name="Main" type="Node"] [node name="Main" type="Node" index="0"]
script = ExtResource( 1 ) script = ExtResource( 1 )
_sections_unfolded = [ "Pause" ] _sections_unfolded = [ "Pause" ]

44
scenes/global.gd Normal file
View file

@ -0,0 +1,44 @@
extends Node
var current_scene = null
var character = null
var character_camera = null
var character_creation_camera = null
func _ready():
var root = get_tree().get_root()
current_scene = root.get_child(root.get_child_count() -1)
character = get_tree().get_root().get_node( "Main/Game/Character" )
character_camera = get_tree().get_root().get_node( "Main/Game/Character/Camera_rotation_helper/Camera" )
character_creation_camera = get_tree().get_root().get_node( "Main/GUI/character_creation_menu/v_box_container/h_box_container/center_container/character_creation_scene/camera" )
func goto_scene(path):
# This function will usually be called from a signal callback,
# or some other function from the running scene.
# Deleting the current scene at this point might be
# a bad idea, because it may be inside of a callback or function of it.
# The worst case will be a crash or unexpected behavior.
# The way around this is deferring the load to a later time, when
# it is ensured that no code from the current scene is running:
call_deferred("_deferred_goto_scene", path)
func _deferred_goto_scene(path):
# Immediately free the current scene,
# there is no risk here.
current_scene.free()
# Load new scene.
var s = ResourceLoader.load(path)
# Instance the new scene.
current_scene = s.instance()
# Add it to the active scene, as child of root.
get_tree().get_root().add_child(current_scene)
# Optional, to make it compatible with the SceneTree.change_scene() API.
get_tree().set_current_scene(current_scene)