Game build tree structure sim -------------------- -------------------

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Game build tree structure sim
#----------------------------------------------------------------------
# Global gd attached to AutoLoad as name:GLOBAL
extends Node
var moduleName
var moduleDim
var moduleToLoad
var module1 = preload("res://gameModes/test_child1.tscn")
var module2 = preload("res://gameModes/test_child2.tscn")
var module3 = preload("res://gameModes/test_child3.tscn")
func loadModule():
get_node("/root/BUILD/currentModule").get_child(0).queue_free()
get_node("/root/BUILD/currentModule").add_child(moduleToLoad.instance())
moduleName = get_node("/root/BUILD/currentModule").get_child(1).name
moduleDim = get_node("/root/BUILD/currentModule").get_child(1).get_node("Panel").rect_size
get_node("/root/BUILD/currentModule").get_child(1).position = (get_viewport().size / 2) - (moduleDim / 2)
#print(moduleName)
#----------------------------------------------------------------------
# BUILD gd attached to container's node
extends Node
func _ready():
$currentModule.add_child(GLOBAL.module1.instance())
GLOBAL.moduleName = $currentModule.get_child(0).name
GLOBAL.moduleDim = $currentModule.get_child(0).get_node("Panel").rect_size
$currentModule.get_child(0).position = (get_viewport().size / 2) - (GLOBAL.moduleDim / 2)
#print(GLOBAL.moduleName)
#----------------------------------------------------------------------
# Script attached to module's buttons
extends Node2D
func _on_bttn_toScene1_button_up():
GLOBAL.moduleToLoad = GLOBAL.module1
get_tree().root.get_node("GLOBAL").loadModule()
func _on_bttn_toScene3_button_up():
GLOBAL.moduleToLoad = GLOBAL.module3
get_tree().root.get_node("GLOBAL").loadModule()
#----------------------------------------------------------------------