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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
extends Node
var ineditor = false
var state = Globals.PlayerState.PICK
var statetype = Globals.StateType.TURRET
var selected = ""
var editing_turret = ""
var gui : Node
var pointer : Node
var turret_holder : Node
var load_turrets : Node
var path : Node
var world : VoxelMesh
func fetch ():
if load_turrets != null: return
var root = get_tree().root.get_node("world")
gui = root.get_node("gui")
pointer = root.get_node("pointer")
world = root.get_node("world")
path = root.get_node("path")
turret_holder = root.get_node("turrets")
var saveload = root.get_node("saveload")
load_turrets = saveload.get_node("load_turrets")
if !load_turrets.loaded: yield(load_turrets, "done_loading")
func _ready ():
fetch()
_refresh()
build_option (state, statetype)
func build_option (st, sttype):
var opts = []
match st:
Globals.PlayerState.PICK, Globals.PlayerState.PLACE:
match sttype:
Globals.StateType.TURRET:
for t in load_turrets.get_base_turrets():
opts += [ { "type": "turret buy", "name": t.name } ]
Globals.StateType.ATTACH:
opts += [ { "type": "text", "name": "attach" } ]
Globals.StateType.PATH:
opts += [ { "type": "text", "name": "start path" } ]
opts += [ { "type": "text", "name": "path" } ]
opts += [ { "type": "text", "name": "end path" } ]
Globals.StateType.VOXEL:
for i in world.voxel_set.size():
var details = world.voxel_set.get_voxel(i)
var color = Color(1, 0, 1)
if details.has("color"):
color = details.color
opts += [ { "type": "color", "name": i, "color": color} ]
Globals.PlayerState.EDIT:
match sttype:
Globals.StateType.TURRET:
var tname = turret_holder.get_node(editing_turret).info.name
for t in load_turrets.get_upg_turrets(tname):
opts += [ { "type": "turret upg", "name": t.name } ]
opts += [ { "type": "text", "name": "sell" } ]
opts += [ { "type": "text", "name": "priority" } ]
opts += [ { "type": "text", "name": "modules" } ]
opts += [ { "type": "text", "name": "back" } ]
gui.bottom_bar.picker.build(opts)
func _refresh ():
gui.refresh(ineditor)
pointer.refresh(state, statetype, selected)
func to_pick ():
selected = ""
editing_turret = ""
state = Globals.PlayerState.PICK
build_option(state, statetype)
func do (action, par = {}):
print(str(action) + " " + str(par))
fetch()
match state:
Globals.PlayerState.PICK:
match action:
Globals.PlayerActions.PICK:
selected = par.selected
state = Globals.PlayerState.PLACE
Globals.PlayerActions.SELECT:
match statetype:
Globals.StateType.TURRET:
selected = ""
editing_turret = par.selected
state = Globals.PlayerState.EDIT
build_option(state, statetype)
_: to_pick()
Globals.PlayerActions.CHANGE_TYPE:
selected = ""
editing_turret = ""
state = Globals.PlayerState.PICK
statetype = par.statetype
build_option(state, statetype)
Globals.PlayerState.PLACE:
match action:
Globals.PlayerActions.PLACE:
match statetype:
Globals.StateType.TURRET:
editing_turret = par.placed
state = Globals.PlayerState.EDIT
build_option(state, statetype)
Globals.PlayerActions.DELETE: pass
Globals.PlayerActions.CANCEL: to_pick()
Globals.PlayerActions.CHANGE_TYPE:
selected = ""
editing_turret = ""
state = Globals.PlayerState.PICK
statetype = par.statetype
build_option(state, statetype)
Globals.PlayerState.EDIT:
match action:
Globals.PlayerActions.PICK:
match statetype:
Globals.StateType.TURRET:
selected = par.selected
match par.selected:
"back":
to_pick()
_: to_pick()
Globals.PlayerActions.CANCEL: to_pick()
Globals.PlayerActions.CHANGE_TYPE:
selected = ""
editing_turret = ""
state = Globals.PlayerState.PICK
statetype = par.statetype
build_option(state, statetype)
_refresh()
func gui_editor_toggle_event ():
ineditor = !ineditor
gui.refresh(ineditor)
path.refresh_path(ineditor)
func gui_start_wave_event ():
path.refresh_path(ineditor)
#_enemies.spawn()
gui.refresh(ineditor)
|