diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2015-12-09 08:38:23 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2015-12-09 08:38:23 +0100 |
commit | 8639cecf4cedd56452b47503be19c44b304cd02f (patch) | |
tree | e2a795da15e40c7d9d5b82e33378f8dbf0eaf67a /demos/misc/autoload | |
parent | efbb834936fdc9da9789ad37c9cc61e0b90cda95 (diff) |
Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions:
- space after a comma in lists of arguments
- space around weak operators (+, -), no space around strong operators (*, /)
- space after a comment start (#)
- removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
- function blocks separate by two newlines
The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
Diffstat (limited to 'demos/misc/autoload')
-rw-r--r-- | demos/misc/autoload/global.gd | 20 | ||||
-rw-r--r-- | demos/misc/autoload/scene_a.gd | 3 | ||||
-rw-r--r-- | demos/misc/autoload/scene_a.scn | bin | 1459 -> 1660 bytes | |||
-rw-r--r-- | demos/misc/autoload/scene_b.gd | 3 | ||||
-rw-r--r-- | demos/misc/autoload/scene_b.scn | bin | 1448 -> 1639 bytes |
5 files changed, 11 insertions, 15 deletions
diff --git a/demos/misc/autoload/global.gd b/demos/misc/autoload/global.gd index d1bd45461f..126cbc0ab7 100644 --- a/demos/misc/autoload/global.gd +++ b/demos/misc/autoload/global.gd @@ -1,35 +1,33 @@ extends Node - +# member variables var current_scene = null 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. + # 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) @@ -38,6 +36,6 @@ func _ready(): # Get the current scene, the first time. # it is always the last child of root, # after the autoloaded nodes. - + var root = get_tree().get_root() - current_scene = root.get_child( root.get_child_count() -1 ) + current_scene = root.get_child(root.get_child_count() - 1) diff --git a/demos/misc/autoload/scene_a.gd b/demos/misc/autoload/scene_a.gd index 21a6a84eb9..b95ce7dc6e 100644 --- a/demos/misc/autoload/scene_a.gd +++ b/demos/misc/autoload/scene_a.gd @@ -5,13 +5,12 @@ extends Panel # var a=2 # var b="textvar" + func _ready(): # Initalization here pass - - func _on_goto_scene_pressed(): get_node("/root/global").goto_scene("res://scene_b.scn") pass # replace with function body diff --git a/demos/misc/autoload/scene_a.scn b/demos/misc/autoload/scene_a.scn Binary files differindex 61727a57ba..eff314e29d 100644 --- a/demos/misc/autoload/scene_a.scn +++ b/demos/misc/autoload/scene_a.scn diff --git a/demos/misc/autoload/scene_b.gd b/demos/misc/autoload/scene_b.gd index 4a88fddda9..599058848b 100644 --- a/demos/misc/autoload/scene_b.gd +++ b/demos/misc/autoload/scene_b.gd @@ -5,13 +5,12 @@ extends Panel # var a=2 # var b="textvar" + func _ready(): # Initalization here pass - - func _on_goto_scene_pressed(): get_node("/root/global").goto_scene("res://scene_a.scn") pass # replace with function body diff --git a/demos/misc/autoload/scene_b.scn b/demos/misc/autoload/scene_b.scn Binary files differindex ae09eeff88..4cdb03e90e 100644 --- a/demos/misc/autoload/scene_b.scn +++ b/demos/misc/autoload/scene_b.scn |