aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/objs/speck_entity.lua34
-rw-r--r--src/specks.lua (renamed from src/objs/specks.lua)53
2 files changed, 54 insertions, 33 deletions
diff --git a/src/objs/speck_entity.lua b/src/objs/speck_entity.lua
new file mode 100644
index 0000000..cf81130
--- /dev/null
+++ b/src/objs/speck_entity.lua
@@ -0,0 +1,34 @@
+
+register_comp("Speck_System", function(ent)
+ ent.speck_sys = Speck_Sys.new()
+end)
+
+function speck_update_sys(ent, dt)
+ ent.speck_sys.x = ent.x
+ ent.speck_sys.y = ent.y
+
+ ent.speck_sys:update(dt)
+end
+
+function speck_draw_sys(ent)
+ ent.speck_sys:draw()
+end
+
+function new_speck_entity(x, y, filepath)
+ local ent = new_entity()
+ add_comp(ent, "Position", x, y)
+ add_comp(ent, "Speck_System")
+ ent.speck_sys = load_speck_sys(filepath)
+ ent.speck_sys.oneshot = true
+
+ add_comp(ent, "Speck_Entity")
+end
+
+register_comp("Speck_Entity", TAGCOMP)
+
+function speck_entity_system(ent, dt)
+ local sys = ent.speck_sys
+ if not sys.emitting and sys:is_empty() then
+ queue_entity_kill(ent)
+ end
+end
diff --git a/src/objs/specks.lua b/src/specks.lua
index baa9a14..a703d04 100644
--- a/src/objs/specks.lua
+++ b/src/specks.lua
@@ -218,20 +218,6 @@ function Speck_Sys:draw()
end
end
-register_comp("Speck_System", function(ent)
- ent.speck_sys = Speck_Sys.new()
-end)
-
-function speck_update_sys(ent, dt)
- ent.speck_sys.x = ent.x
- ent.speck_sys.y = ent.y
-
- ent.speck_sys:update(dt)
-end
-
-function speck_draw_sys(ent)
- ent.speck_sys:draw()
-end
function export_speck_sys(sys, filename)
local EXPORTED_ARGS = {
@@ -267,30 +253,31 @@ function export_speck_sys(sys, filename)
export_to_source(exp, filename)
end
+local speck_bank = {}
+function load_specks_from(path)
+ path = path or "res/speck"
+ local files = lf.getDirectoryItems(path)
+
+ for _, file in ipairs(files) do
+ local filepath = path.."/"..file
+
+ if lf.getInfo(filepath).type == "directory" then
+ load_specks_from(filepath)
+ else
+ if is_filetype(filepath, {"speck.lua"}) then
+ local data = lf.load(filepath)()
+ speck_bank[filepath] = data
+ end
+ end
+ end
+end
+
function load_speck_sys(filename)
local sys = Speck_Sys.new()
- local loaded = lf.load(filename)()
+ local loaded = speck_bank[filename]
for key, data in pairs(loaded) do
sys[key] = data
end
return sys
end
-function new_speck_entity(x, y, filepath)
- local ent = new_entity()
- add_comp(ent, "Position", x, y)
- add_comp(ent, "Speck_System")
- ent.speck_sys = load_speck_sys(filepath)
- ent.speck_sys.oneshot = true
-
- add_comp(ent, "Speck_Entity")
-end
-
-register_comp("Speck_Entity", TAGCOMP)
-
-function speck_entity_system(ent, dt)
- local sys = ent.speck_sys
- if not sys.emitting and sys:is_empty() then
- queue_entity_kill(ent)
- end
-end