mod-sounds/init.lua

66 lines
1.2 KiB
Lua
Raw Normal View History

2021-06-14 12:36:49 -07:00
sounds = {}
2021-06-14 19:19:48 -07:00
sounds.modname = core.get_current_modname()
sounds.modpath = core.get_modpath(sounds.modname)
sounds.log = function(lvl, msg)
if not msg then
msg = lvl
lvl = nil
end
msg = "[" .. sounds.modname .. "] " .. msg
if not lvl then
core.log(msg)
else
core.log(lvl, msg)
end
end
local scripts = {
2021-08-21 06:03:22 -07:00
"settings",
"override",
2021-08-08 23:47:11 -07:00
"api",
2021-08-21 09:58:59 -07:00
"groups/main",
"groups/animal",
"groups/creature",
"groups/firearm",
2021-08-21 09:58:59 -07:00
"groups/node",
"groups/projectile",
"groups/vehicle",
"groups/weather",
"node",
}
for _, s in ipairs(scripts) do
dofile(sounds.modpath .. "/" .. s .. ".lua")
end
if sounds.enable_tests then
dofile(sounds.modpath .. "/tests.lua")
end
-- cache available sound files
sounds.cache = {}
core.register_on_mods_loaded(function()
sounds.log("action", "caching sound files ...")
for _, modname in ipairs(core.get_modnames()) do
local s_dir = core.get_modpath(modname) .. "/sounds"
for _, ogg in ipairs(core.get_dir_list(s_dir, false)) do
if ogg:find("%.ogg$") then
local basename = ogg:gsub("%.ogg$", "")
-- files for playing randomly by core must have suffix trimmed
if basename:find("%.[0-9]$") then
basename = basename:gsub("%.[0-9]$", "")
end
sounds.cache[basename] = true
end
end
end
end)