add area background sound

fixes #2
master
BuckarooBanzay 2020-06-12 08:29:52 +02:00
parent d6f69d5ee9
commit 07cfe9073c
5 changed files with 99 additions and 2 deletions

View File

@ -16,5 +16,5 @@ read_globals = {
-- deps
"epic", "epic_skybox",
"screwdriver", "areas"
"screwdriver", "areas", "soundblock"
}

View File

@ -26,5 +26,9 @@ if minetest.get_modpath("epic_weather") then
dofile(MP.."/integrations/epic_weather.lua")
end
if minetest.get_modpath("soundblock") then
dofile(MP.."/integrations/soundblock.lua")
end
dofile(MP.."/integrations/day_night.lua")
dofile(MP.."/integrations/no_clouds.lua")

View File

@ -0,0 +1,74 @@
area_effects.register_effect("sound", "background-sound from /sound_list")
-- playername -> sound-handle
local handles = {}
area_effects.register_hook({
enter = function(player, id)
local data = area_effects.get(id)
if data and data.sound then
for _, sounddef in pairs(soundblock.sounds) do
if sounddef.key == data.sound then
local playername = player:get_player_name()
minetest.log(
"action",
"[area_effects] setting sound " .. sounddef.key ..
" for player" .. playername
)
local filename = sounddef.filename
if sounddef.filenames then
filename = sounddef.filenames[math.random(1, #sounddef.filenames)]
end
local handle = minetest.sound_play(filename, {
to_player = playername,
gain = 1.0,
loop = true
})
handles[playername] = handle
break
end
end
end
end,
leave = function(player, id)
local data = area_effects.get(id)
if data and data.sound then
local playername = player:get_player_name()
minetest.log(
"action",
"[area_effects] clearing sound " ..
" for player" .. playername
)
local handle = handles[playername]
if handle then
minetest.sound_stop(handle)
handles[playername] = nil
end
end
end
})
minetest.register_chatcommand("sound_list", {
description = "Lists all available sounds",
func = function()
local list = ""
for _, sounddef in pairs(soundblock.sounds) do
list = list .. sounddef.key .. ","
end
return true, list
end
})
-- cleanup
minetest.register_on_leaveplayer(function(player)
local playername = player:get_player_name()
handles[playername] = nil
end)

View File

@ -1,4 +1,4 @@
name = area_effects
description = area based effects
depends = areas
optional_depends = epic_skybox, epic_weather
optional_depends = epic_skybox, epic_weather, soundblock

View File

@ -5,8 +5,14 @@ Area based effects
* **/area_effects** lists all area effects
# Integrations
Available integrations
## Skybox (epic_skybox)
Mod: https://github.com/damocles-minetest/epic_skybox
* **/skybox_list** List available skyboxes
* **/area_effect_set skybox Plain Black** Set
* **/area_effect_get skybox** Get
@ -14,12 +20,25 @@ Area based effects
## day/night
Mod: _builtin_
* **/area_effect_set day_night 0.4**
## Weather (epic_weather)
Mod: https://github.com/damocles-minetest/epic_weather
* **/area_effect_set weather Light rain**
## Clouds
Mod: _builtin_
* **/area_effect_set no_clouds true**
## Soundblock
Mod: https://github.com/mt-mods/soundblock
* **/area_effect_set sound damocles_soundblock_ambient_1**
* **/sound_list**