From 1873ccff40f81c4d20fb752df1fe34adf33fd254 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Wed, 19 Jan 2022 15:39:52 +0100 Subject: cost check, icons --- scripts/control.gd | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'scripts/control.gd') 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": -- cgit v1.2.3-54-g00ecf