aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/control.gd86
-rw-r--r--scripts/enemies.gd20
-rw-r--r--scripts/gui.gd38
-rw-r--r--scripts/gui_bottom_bar.gd17
-rw-r--r--scripts/gui_button.gd2
-rw-r--r--scripts/gui_load_map.gd51
-rw-r--r--scripts/gui_picker.gd12
-rw-r--r--scripts/load_map.gd21
-rw-r--r--scripts/load_shapes.gd1
-rw-r--r--scripts/placer.gd13
10 files changed, 208 insertions, 53 deletions
diff --git a/scripts/control.gd b/scripts/control.gd
index a2d7d2b..0b94adb 100644
--- a/scripts/control.gd
+++ b/scripts/control.gd
@@ -15,24 +15,28 @@ var pointer : Node
var turret_holder : Node
var enemies_holder : Node
var load_turrets : Node
+var saveload_map : Node
var path : Node
var world : VoxelMesh
func fetch ():
if load_turrets != null: return
var root = get_tree().root.get_node("world")
- wave = root.get_node("wave")
player = root.get_node("player")
resources = player.get_node("resources")
placer = player.get_node("placer")
+
+ wave = root.get_node("wave")
pointer = root.get_node("pointer")
gui = root.get_node("gui")
world = root.get_node("world")
path = root.get_node("path")
turret_holder = root.get_node("turrets")
enemies_holder = root.get_node("enemies")
+
var saveload = root.get_node("saveload")
load_turrets = saveload.get_node("load_turrets")
+ saveload_map = saveload.get_node("saveload_map")
if !load_turrets.loaded: yield(load_turrets, "done_loading")
func _ready ():
@@ -59,16 +63,18 @@ func build_option (st, sttype):
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} ]
+ opts += [ { "type": "color", "name": str(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):
+ var tinfo = turret_holder.get_node(editing_turret).info
+ for t in load_turrets.get_upg_turrets(tinfo.name):
opts += [ { "type": "turret upg", "name": t.name } ]
- opts += [ { "type": "text", "name": "targeting" } ]
- opts += [ { "type": "text", "name": "modules" } ]
+ if tinfo.has("projectile"):
+ opts += [ { "type": "text", "name": "targeting" } ]
+ if tinfo.get("modules_max", 0) > 0:
+ opts += [ { "type": "text", "name": "modules" } ]
opts += [ { "type": "text", "name": "sell" } ]
opts += [ { "type": "text", "name": "back" } ]
@@ -106,7 +112,7 @@ func do (action, par = {}):
Globals.PlayerState.PICK:
match action:
Globals.PlayerActions.PICK:
- selected = par.selected
+ selected = par.name
state = Globals.PlayerState.PLACE
Globals.PlayerActions.SELECT:
@@ -143,10 +149,10 @@ func do (action, par = {}):
"path": placer.inst_path(par.pos, par.rot)
"end path": placer.inst_path_end(par.pos, par.rot)
Globals.StateType.VOXEL:
- placer.inst_voxel(par.pos, par.rot)
+ placer.inst_voxel(par.pos, par.rot, selected)
Globals.PlayerActions.PICK:
- selected = par.selected
+ selected = par.name
Globals.PlayerActions.DELETE:
placer.delete(statetype, par.pos, par.rot)
@@ -165,29 +171,40 @@ func do (action, par = {}):
Globals.PlayerActions.PICK:
match statetype:
Globals.StateType.TURRET:
- selected = par.selected
- match par.selected:
- "targeting":
- statetype = Globals.StateType.TARGETING
+ selected = par.name
+ match par.type:
+ "turret upg":
+ var prv = turret_holder.get_node(editing_turret)
+ var pos = prv.transform.origin
+ var rot = prv.transform.basis.get_rotation_quat()
+ placer.delete(statetype, pos, rot)
+ var obj = placer.inst_turret(pos, rot, par.name)
+ editing_turret = obj.name
+ state = Globals.PlayerState.EDIT
build_option(state, statetype)
- "modules":
- statetype = Globals.StateType.MODULES
- build_option(state, statetype)
- "sell":
- sell(editing_turret)
- to_pick()
- "back": to_pick()
+ _ :
+ match par.name:
+ "targeting":
+ statetype = Globals.StateType.TARGETING
+ build_option(state, statetype)
+ "modules":
+ statetype = Globals.StateType.MODULES
+ build_option(state, statetype)
+ "sell":
+ sell(editing_turret)
+ to_pick()
+ "back": to_pick()
Globals.StateType.TARGETING:
- selected = par.selected
- match par.selected:
+ selected = par.name
+ match par.name:
"back":
statetype = Globals.StateType.TURRET
build_option(state, statetype)
Globals.StateType.MODULES:
- selected = par.selected
- match par.selected:
+ selected = par.name
+ match par.name:
"back":
statetype = Globals.StateType.TURRET
build_option(state, statetype)
@@ -207,6 +224,10 @@ func do (action, par = {}):
func gui_editor_toggle_event ():
ineditor = !ineditor
+ if !ineditor:
+ statetype = Globals.StateType.TURRET
+ to_pick()
+
gui.refresh()
path.refresh_path(ineditor)
@@ -215,3 +236,20 @@ func gui_start_wave_event ():
path.refresh_path(ineditor)
wave.start()
gui.refresh()
+
+func gui_save_map_event (): saveload_map.map_save()
+
+func gui_save_as_map_event (mapname : String):
+ saveload_map.mapname = mapname
+ saveload_map.map_save()
+
+func gui_delete_map_event (mapname : String):
+ saveload_map.map_delete(mapname)
+
+func gui_change_map_event (mapname : String):
+ saveload_map.mapname = mapname
+ saveload_map.map_load()
+ gui.load_map.visible = false
+
+ path.refresh_path(ineditor)
+ gui.refresh()
diff --git a/scripts/enemies.gd b/scripts/enemies.gd
index 4a58198..fe5ae14 100644
--- a/scripts/enemies.gd
+++ b/scripts/enemies.gd
@@ -46,6 +46,7 @@ func _ready():
if !load_shapes.loaded: yield(load_shapes, "done_loading")
func spawn(name, node_cur=0, rel_pos=0):
+ print("spawned " + name)
var instance = _enemy_blue.instance()
add_child(instance)
instance.transform.origin = _path.nodes[0].transform.origin;
@@ -62,14 +63,21 @@ func spawn(name, node_cur=0, rel_pos=0):
"hp": info.lives,
"slowed_effect": 0,
"slowed_time": 0,
- "cur": 0,
- "rel": 0,
+ "cur": node_cur,
+ "rel": rel_pos,
"axis": [axis.x, axis.y, axis.z]
}
+ instance.transform.origin = abs_pos(serial_enemy)
serial_enemy += 1
func node_from_id (id):
return get_node(str(id))
+
+func abs_pos (id):
+ var enemy = enemies[id]
+ var from = _path.nodes[enemy.cur].transform.origin
+ var to = _path.nodes[enemy.cur+1].transform.origin
+ return lerp(from, to, enemy.rel)
func _physics_process(delta):
var delist = []
@@ -81,9 +89,9 @@ func _physics_process(delta):
if enemy.hp <= 0:
delist.append(id)
enemy.rel = 0
- for n in info.get("spawn_num", 0):
+ for n in range(info.get("spawn_num", 0)):
# todo rel +- epslion
- spawn(enemy.spawn_on_death, enemy.cur, enemy.rel - n/10)
+ spawn(info.spawn_on_death, enemy.cur, enemy.rel - n/10)
continue
var speed = info.speed
@@ -99,9 +107,7 @@ func _physics_process(delta):
_resources.lives -= load_shapes.get_damage(enemy.hp, enemy.name)
continue
- var from = _path.nodes[enemy.cur].transform.origin
- var to = _path.nodes[destination].transform.origin
- child.transform.origin = lerp(from, to, enemy.rel)
+ child.transform.origin = abs_pos(id)
var axis = Vector3(enemy.axis[0], enemy.axis[1], enemy.axis[2])
child.transform.basis = child.transform.basis.rotated(axis, delta)
diff --git a/scripts/gui.gd b/scripts/gui.gd
index 3ad47aa..2e63483 100644
--- a/scripts/gui.gd
+++ b/scripts/gui.gd
@@ -6,17 +6,30 @@ var wave : Node
var bottom_bar : Control
var top_bar : Control
-var _wave_ongoing : Panel
+var wave_ongoing : Panel
+var load_map : PanelContainer
+var save_as : AcceptDialog
+var delete_confirm : AcceptDialog
+var saveload : Node
+var saveload_map : Node
func _fetch ():
var root = get_tree().root.get_node("world")
player = root.get_node("player")
control = player.get_node("control")
wave = root.get_node("wave")
+ saveload = root.get_node("saveload")
+ saveload_map = saveload.get_node("saveload_map")
if bottom_bar == null: bottom_bar = get_node("bottom_bar")
if top_bar == null: top_bar = get_node("top_bar")
- if _wave_ongoing == null: _wave_ongoing = $wave_ongoing_indicator
+ if wave_ongoing == null: wave_ongoing = $wave_ongoing_indicator
+ if load_map == null: load_map = $gui_load_map
+ if save_as == null:
+ save_as = $save_as
+ save_as.register_text_enter(save_as.get_node("line_edit"))
+ if delete_confirm == null:
+ delete_confirm = $delete_confirm
func _ready():
_fetch()
@@ -27,5 +40,22 @@ func refresh ():
bottom_bar.refresh(control.ineditor)
top_bar.refresh(control.ineditor)
- if wave.ongoing: _wave_ongoing.visible = true
- else: _wave_ongoing.visible = false
+ if wave.ongoing: wave_ongoing.visible = true
+ else: wave_ongoing.visible = false
+
+func save_as_mapname():
+ var mapname = save_as.get_node("line_edit").text
+ if !mapname.ends_with(".json"): mapname += ".json"
+ control.gui_save_as_map_event(mapname)
+ save_as.visible = false
+ load_map.build()
+
+func _on_save_as_confirmed():
+ save_as_mapname()
+
+func _on_delete_confirmed():
+ control.gui_delete_map_event(load_map.selected_delete)
+ load_map.build()
+
+func _on_close_load_map():
+ load_map.visible = false
diff --git a/scripts/gui_bottom_bar.gd b/scripts/gui_bottom_bar.gd
index bd63a51..af987a4 100644
--- a/scripts/gui_bottom_bar.gd
+++ b/scripts/gui_bottom_bar.gd
@@ -5,10 +5,14 @@ var picker : Control
var gui : Control
+var load_map : Control
+var map_name : Label
+
func _fetch ():
if gui == null: gui = get_parent()
if editor_bar == null: editor_bar = $editor_bar
if picker == null: picker = $picker
+ if map_name == null: map_name = $editor_bar/hbox_map/mapname
func refresh (in_editor : bool):
_fetch()
@@ -19,6 +23,8 @@ func refresh (in_editor : bool):
editor_bar.visible = false
picker.refresh()
+
+ map_name.text = gui.saveload_map.mapname
func _on_turrets_button_up():
gui.control.do(Globals.PlayerActions.CHANGE_TYPE,
@@ -39,3 +45,14 @@ func _on_voxel_button_up():
func _on_palette_button_up():
gui.control.do(Globals.PlayerActions.CHANGE_TYPE,
{ "statetype": Globals.StateType.VOXEL_PALETTE })
+
+func _on_save_button_up():
+ gui.control.gui_save_map_event()
+
+func _on_load_button_up():
+ gui.load_map.build()
+ gui.load_map.visible = true
+
+func _on_save_as_button_up():
+ gui.save_as.popup()
+ gui.save_as.get_node("line_edit").grab_focus()
diff --git a/scripts/gui_button.gd b/scripts/gui_button.gd
index 41ebae1..a36b0f4 100644
--- a/scripts/gui_button.gd
+++ b/scripts/gui_button.gd
@@ -1,3 +1,3 @@
extends TextureButton
-var option : String
+var option : Dictionary
diff --git a/scripts/gui_load_map.gd b/scripts/gui_load_map.gd
new file mode 100644
index 0000000..288f937
--- /dev/null
+++ b/scripts/gui_load_map.gd
@@ -0,0 +1,51 @@
+extends PanelContainer
+
+var vbox_items
+var _gui_item : Resource = load("res://scenes/gui/gui_map_item.tscn")
+var saveload_map : Node
+
+var control : Node
+var gui : Control
+
+var selected_delete = ""
+
+func _fetch ():
+ if gui == null: gui = get_parent()
+ if saveload_map != null: return;
+
+ vbox_items = $"vbox/vbox_items"
+
+ var root = get_tree().root.get_node("world")
+ control = root.get_node("player").get_node("control")
+ saveload_map = root.get_node("saveload").get_node("saveload_map")
+
+func build ():
+ _fetch()
+
+ var txt = "load map from " + saveload_map.mappath
+ get_node("vbox").get_node("title").text = txt
+
+ var mapnames = saveload_map.get_mapnames()
+ for child in vbox_items.get_children(): child.queue_free()
+
+ for mapname in mapnames:
+ var item = _gui_item.instance()
+ item.get_node("name").text = mapname
+ vbox_items.add_child(item)
+
+ var button_load = item.get_node("hbox").get_node("load")
+ button_load.connect("pressed", self, "_load_pressed", [mapname])
+
+ var button_delete = item.get_node("hbox").get_node("delete")
+ button_delete.connect("pressed", self, "_delete_pressed", [mapname])
+
+func refresh ():
+ _fetch()
+
+func _delete_pressed (mapname : String):
+ gui.delete_confirm.popup()
+ gui.delete_confirm.dialog_text = "You are about to delete this map:\n"+mapname
+ selected_delete = mapname
+
+func _load_pressed (mapname : String):
+ control.gui_change_map_event(mapname)
diff --git a/scripts/gui_picker.gd b/scripts/gui_picker.gd
index 616b3e8..9a7e373 100644
--- a/scripts/gui_picker.gd
+++ b/scripts/gui_picker.gd
@@ -33,7 +33,7 @@ func build (options : Array = []):
_options = options
for opt in _options:
var button = _gui_button.instance()
- button.option = opt.name
+ button.option = opt
if opt.type == "turret buy":
var tinfo = load_turrets.info[opt.name]
@@ -60,11 +60,11 @@ func build (options : Array = []):
func refresh ():
_fetch()
-func _on_gui_turret_mouse_entered(option : String):
- hovering = option;
+func _on_gui_turret_mouse_entered(option : Dictionary):
+ hovering = option.name;
-func _on_gui_turret_mouse_exited(option : String):
+func _on_gui_turret_mouse_exited(option : Dictionary):
hovering = ""
-func _on_gui_turret_pressed(option : String):
- gui.control.do(Globals.PlayerActions.PICK, { "selected": option })
+func _on_gui_turret_pressed(option : Dictionary):
+ gui.control.do(Globals.PlayerActions.PICK, option)
diff --git a/scripts/load_map.gd b/scripts/load_map.gd
index 1e4405c..13d9255 100644
--- a/scripts/load_map.gd
+++ b/scripts/load_map.gd
@@ -1,9 +1,13 @@
extends Node
+var mapname = "map0.json"
+var mappath = "user://"
+
var _world : VoxelMesh = null
var _path_holder : Node = null
var _attach_point_holder : Node = null
+var saveload : Node = null
var _load_scenes : Node = null
func _ready():
@@ -17,8 +21,9 @@ func fetch ():
_path_holder = root.get_node("path")
if _attach_point_holder == null:
_attach_point_holder = root.get_node("attach")
+ if saveload == null: saveload = root.get_node("saveload")
if _load_scenes == null:
- _load_scenes = root.get_node("saveload").get_node("load_scenes")
+ _load_scenes = saveload.get_node("load_scenes")
func get_map_state ():
fetch()
@@ -90,14 +95,14 @@ func set_map_state (state):
func map_save():
var save_game = File.new()
- save_game.open("user://map0.json", File.WRITE)
+ save_game.open(mappath+mapname, File.WRITE)
save_game.store_string(to_json(get_map_state()))
save_game.close()
print("saved")
func map_load():
var save_game = File.new()
- save_game.open("user://map0.json", File.READ)
+ save_game.open(mappath+mapname, File.READ)
var raw = save_game.get_as_text()
save_game.close()
@@ -107,9 +112,17 @@ func map_load():
_path_holder.refresh_path(false)
+func map_delete (mapname : String):
+ var dir = Directory.new()
+ dir.remove(mappath+mapname)
+
+func get_mapnames ():
+ return saveload.parse_dir(mappath, ".json")
+
func _process(_delta):
if Input.is_action_just_released("save"):
map_save()
if Input.is_action_just_released("load"):
- map_load()
+ #map_load()
+ pass
diff --git a/scripts/load_shapes.gd b/scripts/load_shapes.gd
index 9ac9f3c..289afd9 100644
--- a/scripts/load_shapes.gd
+++ b/scripts/load_shapes.gd
@@ -30,7 +30,6 @@ func load_thumbnails():
thumbnails.clear()
var files = saveload.parse_dir("res://assets/textures/thumbnails/enemies", ".png")
for turr in files:
- print(turr)
thumbnails[turr] = load("res://assets/textures/thumbnails/enemies/" + turr)
func load_info():
diff --git a/scripts/placer.gd b/scripts/placer.gd
index 032900f..991f333 100644
--- a/scripts/placer.gd
+++ b/scripts/placer.gd
@@ -150,8 +150,8 @@ func inst_attach (pos, rot):
instance.transform.basis = Basis(rot);
return instance
-func inst_voxel (pos, rot):
- world.set_voxel(pos + normal, int(control.selected))
+func inst_voxel (pos, rot, block):
+ world.set_voxel(pos + normal, int(block))
world.update_mesh()
func nearest_child (node, pos):
@@ -254,7 +254,7 @@ func _pointer ():
Globals.StateType.PATH:
g = "path"
match control.selected:
- "start path": g = "voxel"
+ "start path": g = "voxels"
if Input.is_action_just_pressed("use"):
if colliding && g in colliding_group:
@@ -266,6 +266,7 @@ func _pointer ():
else:
control.do(Globals.PlayerActions.CANCEL)
if Input.is_action_just_pressed("cancel"):
- control.do(Globals.PlayerActions.DELETE, {
- "pos": colliding_node.transform.origin,
- "rot": colliding_node.transform.basis.get_rotation_quat() })
+ if colliding:
+ control.do(Globals.PlayerActions.DELETE, {
+ "pos": colliding_node.transform.origin,
+ "rot": colliding_node.transform.basis.get_rotation_quat() })