diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/init.lua | 3 | ||||
| -rw-r--r-- | src/objs/speck_entity.lua | 34 | ||||
| -rw-r--r-- | src/sound.lua | 1 | ||||
| -rw-r--r-- | src/specks.lua (renamed from src/objs/specks.lua) | 54 |
4 files changed, 57 insertions, 35 deletions
diff --git a/src/init.lua b/src/init.lua index 4fd66dd..50d542f 100644 --- a/src/init.lua +++ b/src/init.lua @@ -10,6 +10,7 @@ require "src.im" require "src.room_editor" require "src.export" require "src.sound" +require "src.specks" SCR_WIDTH = 320 SCR_HEIGHT = 180 @@ -49,10 +50,10 @@ end function main_init() lg.setDefaultFilter("nearest", "nearest") viewport = lg.newCanvas(SCR_WIDTH, SCR_HEIGHT) - lw.setVSync(0) load_textures_from() load_sounds_from() + load_specks_from() load_dir("src/objs") load_dir("src/scenes") 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/sound.lua b/src/sound.lua index 5b530fc..30f7e5b 100644 --- a/src/sound.lua +++ b/src/sound.lua @@ -25,6 +25,7 @@ end function play_sound(path, x, y) sound = sound_bank[path] + assert(sound, "sound "..path.." unknown") local source = nil for i = 1, sound.size do diff --git a/src/objs/specks.lua b/src/specks.lua index 16fe021..a703d04 100644 --- a/src/objs/specks.lua +++ b/src/specks.lua @@ -91,7 +91,6 @@ function Speck_Sys:check_bounce(i) to_tile_coords(self.data.pos[i].x, self.data.pos[i].y)) end - function Speck_Sys:spawn_particles() local data = self.data local amt = lmath.random(self.spawn_amount_min, self.spawn_amount_max) @@ -219,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 = { @@ -268,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 |
