From c4e594cc3158bd5ca0979a78bed1017fc7f30d5e Mon Sep 17 00:00:00 2001 From: ne_mene Date: Sat, 28 Mar 2026 22:50:16 +0100 Subject: sound module --- src/sound.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/sound.lua (limited to 'src') 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 -- cgit v1.3-2-g0d8e