aboutsummaryrefslogtreecommitdiff
path: root/src/sound.lua
diff options
context:
space:
mode:
authorne_mene <[email protected]>2026-03-28 22:50:16 +0100
committerne_mene <[email protected]>2026-03-28 22:50:16 +0100
commitc4e594cc3158bd5ca0979a78bed1017fc7f30d5e (patch)
tree1a413463de832379e0e494646b4f5b84d8f006bb /src/sound.lua
parent44af8d899bfbf495b919636dab2ea0184590caf3 (diff)
sound module
Diffstat (limited to 'src/sound.lua')
-rw-r--r--src/sound.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/sound.lua b/src/sound.lua
new file mode 100644
index 0000000..4d31861
--- /dev/null
+++ b/src/sound.lua
@@ -0,0 +1,39 @@
+
+local sound_bank = {}
+
+function load_sounds_from(path)
+ path = path or "res/sound"
+ local files = lf.getDirectoryItems(path)
+
+ for _, file in ipairs(files) do
+ local filepath = path.."/"..file
+
+ if lf.getInfo(filepath).type == "directory" then
+ load_sounds_from(filepath)
+ else
+ if is_filetype(filepath, {"wav", "ogg", "mp3"}) then
+ sound_bank[filepath] = {
+ size = 1,
+ [1] = la.newSource(filepath, "static"),
+ }
+ end
+ end
+ end
+end
+
+function play_sound(path)
+ sound = sound_bank[path]
+ local source = nil
+
+ for i = 1, sound.size do
+ if not sound[i]:isPlaying() then
+ source = sound[i]
+ end
+ end
+ if not source then
+ sound.size = sound.size + 1
+ sound[sound.size] = sound[1]:clone()
+ source = sound[sound.size]
+ end
+ la.play(source)
+end