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)
|
2021-06-14 12:39:29 -07:00
|
|
|
|
2021-08-06 13:57:26 -07:00
|
|
|
sounds.log = function(lvl, msg)
|
|
|
|
if not msg then
|
|
|
|
msg = lvl
|
|
|
|
lvl = nil
|
|
|
|
end
|
2021-06-14 12:39:29 -07:00
|
|
|
|
2021-08-06 13:57:26 -07:00
|
|
|
msg = "[" .. sounds.modname .. "] " .. msg
|
|
|
|
|
|
|
|
if not lvl then
|
|
|
|
core.log(msg)
|
|
|
|
else
|
|
|
|
core.log(lvl, msg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local scripts = {
|
2021-08-09 03:09:55 -07:00
|
|
|
"override",
|
2021-08-08 23:47:11 -07:00
|
|
|
"api",
|
|
|
|
"groups",
|
2021-08-11 01:33:17 -07:00
|
|
|
"groups_animal",
|
|
|
|
"groups_creature",
|
|
|
|
"groups_node",
|
2021-08-06 13:57:26 -07:00
|
|
|
"node",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, s in ipairs(scripts) do
|
|
|
|
dofile(sounds.modpath .. "/" .. s .. ".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
|
2021-08-06 23:04:35 -07:00
|
|
|
if ogg:find("%.ogg$") then
|
|
|
|
local basename = ogg:gsub("%.ogg$", "")
|
2021-08-06 13:57:26 -07:00
|
|
|
-- files for playing randomly by core must have suffix trimmed
|
2021-08-06 23:04:35 -07:00
|
|
|
if basename:find("%.[0-9]$") then
|
|
|
|
basename = basename:gsub("%.[0-9]$", "")
|
2021-08-06 13:57:26 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
sounds.cache[basename] = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|