aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bullet.gd1
-rw-r--r--scripts/control.gd43
-rw-r--r--scripts/gui_picker.gd22
-rw-r--r--scripts/load_turrets.gd1
4 files changed, 52 insertions, 15 deletions
diff --git a/scripts/bullet.gd b/scripts/bullet.gd
index 2a5df41..dd9793e 100644
--- a/scripts/bullet.gd
+++ b/scripts/bullet.gd
@@ -63,4 +63,5 @@ func collided(body):
queue_free()
else:
hitlist.append(parent)
+ print(hitlist)
diff --git a/scripts/control.gd b/scripts/control.gd
index 0b94adb..7c8b95d 100644
--- a/scripts/control.gd
+++ b/scripts/control.gd
@@ -86,6 +86,34 @@ func build_option (st, sttype):
gui.bottom_bar.picker.build(opts)
+func buy (pos, rot, turr_name):
+ var info = load_turrets.info[turr_name]
+ if resources.greater_than(info.cost):
+ resources.sub(info.cost)
+ var obj = placer.inst_turret(pos, rot, turr_name)
+ editing_turret = obj.name
+ state = Globals.PlayerState.EDIT
+ build_option(state, statetype)
+ else:
+ pass
+ ## TODO feedback
+
+func upgrade (turr_inst_name, upg_name):
+ var info = load_turrets.info[upg_name]
+ if resources.greater_than(info.cost):
+ resources.sub(info.cost)
+ var prv = turret_holder.get_node(turr_inst_name)
+ 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, upg_name)
+ editing_turret = obj.name
+ state = Globals.PlayerState.EDIT
+ build_option(state, statetype)
+ else:
+ pass
+ ## TODO feedback
+
func sell (turr_name):
var turr = turret_holder.get_node(turr_name)
var info = turr.info
@@ -136,11 +164,7 @@ func do (action, par = {}):
Globals.PlayerActions.PLACE:
match statetype:
Globals.StateType.TURRET:
- var obj = placer.inst_turret(
- par.pos, par.rot, selected)
- editing_turret = obj.name
- state = Globals.PlayerState.EDIT
- build_option(state, statetype)
+ buy(par.pos, par.rot, selected)
Globals.StateType.ATTACH:
placer.inst_attach(par.pos, par.rot)
Globals.StateType.PATH:
@@ -174,14 +198,7 @@ func do (action, par = {}):
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)
+ upgrade(editing_turret, par.name)
_ :
match par.name:
"targeting":
diff --git a/scripts/gui_picker.gd b/scripts/gui_picker.gd
index 9a7e373..b888572 100644
--- a/scripts/gui_picker.gd
+++ b/scripts/gui_picker.gd
@@ -5,7 +5,10 @@ var _gui_button : Resource = load("res://scenes/gui/gui_button.tscn")
var _options = []
+var thumbs_generic = {}
+
var gui : Control
+var saveload : Node
var load_turrets : Node
var resources : Node
@@ -17,8 +20,18 @@ func _fetch ():
var root = get_tree().root.get_node("world")
resources = root.get_node("player").get_node("resources")
- load_turrets = root.get_node("saveload").get_node("load_turrets")
+ saveload = root.get_node("saveload")
+ load_turrets = saveload.get_node("load_turrets")
+ load_thumbnails()
if !load_turrets.loaded: yield(load_turrets, "done_loading")
+
+
+func load_thumbnails():
+ var thumbspath = "res://assets/textures/thumbnails/generic"
+ thumbs_generic.clear()
+ var files = saveload.parse_dir(thumbspath, ".svg")
+ for turr in files:
+ thumbs_generic[turr] = load(thumbspath + "/" + turr)
func build (options : Array = []):
_fetch()
@@ -34,6 +47,7 @@ func build (options : Array = []):
for opt in _options:
var button = _gui_button.instance()
button.option = opt
+ var tback = button.get_node("texture_back");
if opt.type == "turret buy":
var tinfo = load_turrets.info[opt.name]
@@ -45,8 +59,14 @@ func build (options : Array = []):
button.get_node("name").text = tinfo.name
button.get_node("cash").text = resources.dict_to_str(tinfo.cost)
button.get_node("texture").texture = load_turrets.thumbnails[tinfo.thumbnail_name]
+ tback.texture = thumbs_generic["upgrade.svg"]
if opt.type == "text":
button.get_node("name").text = opt.name
+ if opt.name == "back": tback.texture = thumbs_generic["back.svg"]
+ if opt.name == "modules": tback.texture = thumbs_generic["modules.svg"]
+ if opt.name == "targeting": tback.texture = thumbs_generic["targeting.svg"]
+ if opt.name == "sell": tback.texture = thumbs_generic["sell.svg"]
+ tback.modulate = Color.white
if opt.type == "color":
button.get_node("name").text = ""
button.get_node("color").color = opt.color
diff --git a/scripts/load_turrets.gd b/scripts/load_turrets.gd
index 3cfd802..e79a68c 100644
--- a/scripts/load_turrets.gd
+++ b/scripts/load_turrets.gd
@@ -57,5 +57,4 @@ func load_thumbnails():
thumbnails.clear()
var files = saveload.parse_dir("res://assets/textures/thumbnails/turrets", ".png")
for turr in files:
- print(turr)
thumbnails[turr] = load("res://assets/textures/thumbnails/turrets/" + turr)