aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorjacopograndi <jacopo.grandi@outlook.it>2022-01-15 16:29:02 +0100
committerjacopograndi <jacopo.grandi@outlook.it>2022-01-15 16:29:02 +0100
commitc9c5b5d7c2a238310ce7bde336f76d2d1b6f9f29 (patch)
treec6e935fea995752a0b307e56892e8422fb734c0e /scripts
parent98f356e68b759bf84300290315d4ada09c41f79b (diff)
moved shapes to loading area & fixed asset paths
Diffstat (limited to 'scripts')
-rw-r--r--scripts/enemies.gd29
-rw-r--r--scripts/load_shapes.gd27
-rw-r--r--scripts/load_turrets.gd10
3 files changed, 38 insertions, 28 deletions
diff --git a/scripts/enemies.gd b/scripts/enemies.gd
index 2144bdf..37c1f6b 100644
--- a/scripts/enemies.gd
+++ b/scripts/enemies.gd
@@ -10,11 +10,11 @@ var _enemy_mat : Material
var _fx_holder
var _fx_enemy_damage
-var _shapes = {}
-
var serial_enemy = 0
var enemies = {}
+var load_shapes : Node
+
var colors = [
Color.red,
Color.purple,
@@ -35,31 +35,20 @@ func _ready():
_path = root.get_node("path")
_resources = root.get_node("player").get_node("resources")
_dissolve_mat = load("res://shaders/dissolve_mat.tres")
- _enemy_mat = load("res://models/shapes/Enemy.material")
+ _enemy_mat = load("res://assets/models/shapes/Enemy.material")
_enemy_blue = load("res://scenes/enemy.tscn")
_fx_enemy_damage = load("res://scenes/fx/enemy_damage.tscn")
- load_shapes()
-
-func load_shapes():
- _shapes = {}
- var dir = Directory.new()
- dir.open("res://models/shapes")
- dir.list_dir_begin(true)
- var shape = dir.get_next()
- while shape != "":
- if (shape.ends_with(".glb")):
- var model = load("res://models/shapes/" + shape)
- var sname = shape.substr(0, shape.length()-4)
- _shapes[sname] = model
- shape = dir.get_next()
+ var saveload = root.get_node("saveload")
+ load_shapes = saveload.get_node("load_shapes")
+ if !load_shapes.loaded: yield(load_shapes, "done_loading")
func spawn():
var instance = _enemy_blue.instance()
add_child(instance)
instance.transform.origin = _path.nodes[0].transform.origin;
instance.name = str(serial_enemy)
- var instance_model = _shapes[_shapes.keys()[randi() % _shapes.size()]].instance()
+ var instance_model = load_shapes.models[load_shapes.models.keys()[randi() % load_shapes.models.size()]].instance()
instance.add_child(instance_model)
instance_model.get_child(0).set_surface_material(0, _enemy_mat.duplicate())
@@ -88,7 +77,7 @@ func _physics_process(delta):
child.get_node(enemy.ops).queue_free()
enemy.ops = enemy.ops.substr(1, enemy.ops.length()-1)
enemy.hp = 10
- var instance_model = _shapes[enemy.ops].instance()
+ var instance_model = load_shapes.models[enemy.ops].instance()
child.add_child(instance_model)
var speed = 1
@@ -138,7 +127,7 @@ func fx_damage(name):
instance.transform = node.transform;
instance.refresh_basis()
- var instance_model = _shapes[enemy["ops"]].instance()
+ var instance_model = load_shapes.models[enemy["ops"]].instance()
instance.add_child(instance_model)
instance.refresh_shader(_dissolve_mat.duplicate(), colors[enemy.hp-1])
diff --git a/scripts/load_shapes.gd b/scripts/load_shapes.gd
new file mode 100644
index 0000000..f3de4ae
--- /dev/null
+++ b/scripts/load_shapes.gd
@@ -0,0 +1,27 @@
+extends Node
+
+var loaded = false
+var saveload : Node
+var models : Dictionary
+
+func get_saveload():
+ if saveload == null: saveload = get_tree().root.get_child(0).get_node("saveload")
+
+func _ready():
+ get_saveload()
+ load_models()
+ emit_signal("done_loading")
+ loaded = true
+
+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()
diff --git a/scripts/load_turrets.gd b/scripts/load_turrets.gd
index ba2e198..2b96652 100644
--- a/scripts/load_turrets.gd
+++ b/scripts/load_turrets.gd
@@ -41,12 +41,6 @@ func load_info():
func load_models():
models.clear()
- var files = saveload.parse_dir("res://models/turrets", ".glb")
+ var files = saveload.parse_dir("res://assets/models/turrets", ".glb")
for turr in files:
- models[turr] = load("res://models/turrets/" + turr)
-
-func load_thumbs():
- thumbs.clear()
- var files = saveload.parse_dir("res://textures/thumbnails", ".png")
- for turr in files:
- thumbs[turr] = load("res://textures/thumbnails/" + turr)
+ models[turr] = load("res://assets/models/turrets/" + turr)