From bedaaf9f57d0c24e2a81c0bf3c482a07382d78c1 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Mon, 17 Jan 2022 16:22:55 +0100 Subject: Remove ignored files --- scripts/control.gd | 73 +++++++++++++++++++++++++++++---- scripts/globals.gd | 2 + scripts/load_shapes.gd | 44 +++++++++++++------- scripts/load_turrets.gd | 7 ++-- scripts/placer.gd | 106 +++++++++++++++++++++++++----------------------- 5 files changed, 156 insertions(+), 76 deletions(-) (limited to 'scripts') diff --git a/scripts/control.gd b/scripts/control.gd index b88874f..8ef1ff0 100644 --- a/scripts/control.gd +++ b/scripts/control.gd @@ -7,6 +7,9 @@ var selected = "" var editing_turret = "" var gui : Node +var player : Node +var placer : Node +var resources : Node var pointer : Node var turret_holder : Node var load_turrets : Node @@ -16,8 +19,11 @@ var world : VoxelMesh func fetch (): if load_turrets != null: return var root = get_tree().root.get_node("world") - gui = root.get_node("gui") + player = root.get_node("player") + resources = player.get_node("resources") + placer = player.get_node("placer") 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") @@ -48,8 +54,7 @@ func build_option (st, sttype): 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 + if details.has("color"): color = details.color opts += [ { "type": "color", "name": i, "color": color} ] Globals.PlayerState.EDIT: @@ -58,12 +63,27 @@ func build_option (st, sttype): 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": "priority" } ] + opts += [ { "type": "text", "name": "targeting" } ] opts += [ { "type": "text", "name": "modules" } ] opts += [ { "type": "text", "name": "sell" } ] opts += [ { "type": "text", "name": "back" } ] + Globals.StateType.TARGETING: + opts += [ { "type": "text", "name": "back" } ] + + Globals.StateType.MODULES: + opts += [ { "type": "text", "name": "back" } ] + gui.bottom_bar.picker.build(opts) + +func sell (turr_name): + var turr = turret_holder.get_node(turr_name) + var info = turr.info + + resources.add(info.cost) + + placer.delete(Globals.StateType.TURRET, + turr.transform.origin, turr.transform.basis.get_rotation_quat()) func _refresh (): gui.refresh(ineditor) @@ -106,11 +126,27 @@ func do (action, par = {}): Globals.PlayerActions.PLACE: match statetype: Globals.StateType.TURRET: - editing_turret = par.placed + var obj = placer.inst_turret( + par.pos, par.rot, selected) + editing_turret = obj.name state = Globals.PlayerState.EDIT build_option(state, statetype) + Globals.StateType.ATTACH: + placer.inst_attach(par.pos, par.rot) + Globals.StateType.PATH: + match selected: + "start path": placer.inst_path_start(par.pos, par.rot) + "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) + + Globals.PlayerActions.PICK: + selected = par.selected - Globals.PlayerActions.DELETE: pass + Globals.PlayerActions.DELETE: + placer.delete(statetype, par.pos, par.rot) + Globals.PlayerActions.CANCEL: to_pick() Globals.PlayerActions.CHANGE_TYPE: @@ -127,8 +163,31 @@ func do (action, par = {}): Globals.StateType.TURRET: selected = par.selected match par.selected: - "back": + "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: + "back": + statetype = Globals.StateType.TURRET + build_option(state, statetype) + + Globals.StateType.MODULES: + selected = par.selected + match par.selected: + "back": + statetype = Globals.StateType.TURRET + build_option(state, statetype) + _: to_pick() Globals.PlayerActions.CANCEL: to_pick() diff --git a/scripts/globals.gd b/scripts/globals.gd index 8c66f03..c6862a0 100644 --- a/scripts/globals.gd +++ b/scripts/globals.gd @@ -12,6 +12,8 @@ enum StateType { PATH, VOXEL, VOXEL_PALETTE + TARGETING + MODULES } enum PlayerActions { diff --git a/scripts/load_shapes.gd b/scripts/load_shapes.gd index 308f111..32e9104 100644 --- a/scripts/load_shapes.gd +++ b/scripts/load_shapes.gd @@ -1,29 +1,43 @@ extends Node var saveload : Node + +var info : Dictionary var models : Dictionary +var thumbnails : Dictionary -var loaded = false +var loaded : bool = false signal done_loading -func get_saveload(): - if saveload == null: saveload = get_tree().root.get_node("world").get_node("saveload") - func _ready(): get_saveload() load_models() + load_info() emit_signal("done_loading") loaded = true +func get_saveload(): + if saveload == null: saveload = get_tree().root.get_node("world").get_node("saveload") + func load_models(): - models = {} - var dir = Directory.new() - dir.open("res://assets/models/shapes") - dir.list_dir_begin(true) - var shape = dir.get_next() - while shape != "": - if (shape.ends_with(".glb")): - var model = load("res://assets/models/shapes/" + shape) - var sname = shape.substr(0, shape.length()-4) - models[sname] = model - shape = dir.get_next() + models.clear() + var files = saveload.parse_dir("res://assets/models/shapes", ".glb") + for turr in files: + models[turr] = load("res://assets/models/shapes/" + turr) + +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(): + info.clear() + var files = saveload.parse_dir("res://assets/json", ".json") + for f in files: + if f != "enemies.json": continue + var parsed = saveload.load_parse_json("res://assets/json/" + f) + if parsed != null: + for tin in parsed: + info[tin.name] = tin diff --git a/scripts/load_turrets.gd b/scripts/load_turrets.gd index 93e7841..3cfd802 100644 --- a/scripts/load_turrets.gd +++ b/scripts/load_turrets.gd @@ -39,9 +39,10 @@ func get_base_turrets(): func load_info(): info.clear() - var files = saveload.parse_dir("res://assets", ".json") - for turr in files: - var parsed = saveload.load_parse_json("res://assets/" + turr) + var files = saveload.parse_dir("res://assets/json", ".json") + for f in files: + if f != "turrets.json": continue + var parsed = saveload.load_parse_json("res://assets/json/" + f) if parsed != null: for tin in parsed: info[tin.name] = tin diff --git a/scripts/placer.gd b/scripts/placer.gd index 6547d02..032900f 100644 --- a/scripts/placer.gd +++ b/scripts/placer.gd @@ -86,14 +86,14 @@ func check_overlap_pointer(): return overlap -func _inst_turret (pos, rot): +func inst_turret (pos, rot, sel): var instance = load_scenes.turret.instance() turret_holder.add_child(instance) instance.transform.origin = pos; instance.transform.basis = Basis(rot); instance.refresh_normal() - var info = load_turrets.info[control.selected] + var info = load_turrets.info[sel] var model = load_turrets.models[info.model_name] var instance_model = model.instance() instance_model.name = "model" @@ -105,7 +105,7 @@ func _inst_turret (pos, rot): child.add_to_group("attach") var apos = child.global_transform.origin var arot = child.global_transform.basis.get_rotation_quat() - instance.pivot.add_child(_inst_attach(apos, arot)) + instance.pivot.add_child(inst_attach(apos, arot)) child.queue_free() instance.refresh_info(info) @@ -119,51 +119,65 @@ func _inst_turret (pos, rot): sb.get_node("CollisionShapeSphere").queue_free(); return instance -func _inst_path_start (pos, rot): +func inst_path_start (pos, rot): var instance = load_scenes.path_start.instance() path_holder.add_child(instance) instance.transform.origin = pos + normal * 0.25; instance.transform.basis = Basis(rot); return instance -func _inst_path (pos, rot): +func inst_path (pos, rot): var instance = load_scenes.path.instance() path_holder.add_child(instance) instance.transform.origin = pos + normal * 0.25; instance.transform.basis = Basis(rot); instance.set_name("path") + # remove collision depencency colliding_node.transform.basis = Basis(rot); return instance -func _inst_path_end (pos, rot): +func inst_path_end (pos, rot): var instance = load_scenes.path_end.instance() path_holder.add_child(instance) instance.transform.origin = pos + normal * 0.25 instance.transform.basis = Basis(rot); return instance -func _inst_attach (pos, rot): +func inst_attach (pos, rot): var instance = load_scenes.attach_point.instance() attach_point_holder.add_child(instance) instance.transform.origin = pos; instance.transform.basis = Basis(rot); return instance -func place (group, inst : FuncRef): - if colliding && group in colliding_group: - var overlap = check_overlap_pointer() - if overlap == "clear": - var obj = inst.call_func( - ptr.transform.origin, - ptr.transform.basis.get_rotation_quat()) - return obj - return null +func inst_voxel (pos, rot): + world.set_voxel(pos + normal, int(control.selected)) + world.update_mesh() -func delete (group): - if colliding && group in colliding_group: - colliding_node.queue_free() - return true - return false +func nearest_child (node, pos): + var mindist = 99999999999; + var minnode = null + for child in node.get_children(): + var dist = child.transform.origin.distance_squared_to(pos) + if mindist > dist: + mindist = dist + minnode = child + return { "node": minnode, "dist": mindist } + +func delete (statetype, pos, rot): + match statetype: + Globals.StateType.TURRET: + var result = nearest_child(turret_holder, pos) + if result.dist < 0.01: result.node.queue_free() + Globals.StateType.ATTACH: + var result = nearest_child(attach_point_holder, pos) + if result.dist < 0.01: result.node.queue_free() + Globals.StateType.PATH: + var result = nearest_child(path_holder, pos) + if result.dist < 0.01: result.node.queue_free() + Globals.StateType.VOXEL: + world.erase_voxel(pos) + world.update_mesh() func _pointer (): if control.state == Globals.PlayerState.PLACE: ptr.visible = true @@ -220,48 +234,38 @@ func _pointer (): { "selected": colliding_node.name }) if control.state == Globals.PlayerState.PLACE: - var inst = null var g = null match control.statetype: - Globals.StateType.TURRET: - g = "attach" - inst = funcref(self, "_inst_turret") - Globals.StateType.ATTACH: - g = "voxels" - inst = funcref(self, "_inst_attach") + Globals.StateType.TURRET: g = "attach" + Globals.StateType.ATTACH: g = "voxels" Globals.StateType.VOXEL: if voxelpos != null: var pos = Voxel.world_to_grid(voxelpos) if Input.is_action_just_pressed("use"): var overlap = check_overlap_pointer() if overlap == "clear": - world.set_voxel(pos + normal, int(control.selected)) - world.update_mesh() - control.do(Globals.PlayerActions.PLACE) + control.do(Globals.PlayerActions.PLACE, { + "pos": pos, + "rot": ptr.transform.basis.get_rotation_quat() }) if Input.is_action_just_pressed("cancel"): - world.erase_voxel(pos) - world.update_mesh() - control.do(Globals.PlayerActions.DELETE) + control.do(Globals.PlayerActions.DELETE, { + "pos": pos, + "rot": ptr.transform.basis.get_rotation_quat() }) Globals.StateType.PATH: g = "path" match control.selected: - "start path": - g = "voxel" - inst = funcref(self, "_inst_path_start") - "path": inst = funcref(self, "_inst_path") - "end path": inst = funcref(self, "_inst_path_end") + "start path": g = "voxel" - if inst != null: - if Input.is_action_just_pressed("use"): - var placed = place(g, inst); - if placed != null: - control.do(Globals.PlayerActions.PLACE, - { "placed": placed.name }) - else: - control.do(Globals.PlayerActions.CANCEL) - if Input.is_action_just_pressed("cancel"): - var has_deleted = delete(g) - if has_deleted: - control.do(Globals.PlayerActions.DELETE) + if Input.is_action_just_pressed("use"): + if colliding && g in colliding_group: + var overlap = check_overlap_pointer() + if overlap == "clear": + control.do(Globals.PlayerActions.PLACE, { + "pos": ptr.transform.origin, + "rot": ptr.transform.basis.get_rotation_quat() }) 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() }) -- cgit v1.2.3-54-g00ecf