Add influence registry, make sounds fade, add skybox feature detection

This commit is contained in:
Till Affeldt
2020-04-18 08:01:36 +02:00
parent f41d5f259c
commit 18045b1943
10 changed files with 83 additions and 52 deletions

View File

@ -3,6 +3,7 @@ if not climate_mod.settings.skybox then return end
local EFFECT_NAME = "climate_api:skybox"
local function set_skybox(player, sky)
if not player.get_stars then return end
if sky.sky_data ~= nil then
player:set_sky(sky.sky_data)
end
@ -21,6 +22,7 @@ local function set_skybox(player, sky)
end
local function remove_skybox(player)
if not player.get_stars then return end
player:set_sky({ type = "regular", clouds = true})
end

View File

@ -1,23 +1,44 @@
if not climate_mod.settings.sound then return end
local EFFECT_NAME = "climate_api:sound"
local FADE_DURATION = climate_api.LONG_CYCLE
local handles = {}
local removables = {}
local function end_sound(pname, weather, sound)
if removables[pname] == nil
or removables[pname][weather] == nil then return end
local handle = removables[pname][weather]
minetest.sound_stop(handle)
removables[pname][weather] = nil
end
local function start_sound(pname, weather, sound)
local handle
if handles[pname] == nil then handles[pname] = {} end
if handles[pname][weather] ~= nil then return end
local handle = minetest.sound_play(sound, {
to_player = pname,
loop = true
})
if removables[pname] == nil or removables[pname][weather] == nil then
handle = minetest.sound_play(sound.name, {
to_player = pname,
loop = true,
gain = 0
})
else
handle = removables[pname][weather]
removables[pname][weather] = nil
end
minetest.sound_fade(handle, sound.gain / FADE_DURATION, sound.gain)
handles[pname][weather] = handle
end
local function stop_sound(pname, weather, sound)
if handles[pname] == nil or handles[pname][weather] == nil then return end
local handle = handles[pname][weather]
minetest.sound_stop(handle)
minetest.sound_fade(handle, -sound.gain / FADE_DURATION, 0)
if removables[pname] == nil then removables[pname] = {} end
removables[pname][weather] = handle
handles[pname][weather] = nil
minetest.after(FADE_DURATION, end_sound, pname, weather, sound)
end
local function start_effect(player_data)
@ -58,4 +79,4 @@ end
climate_api.register_effect(EFFECT_NAME, start_effect, "start")
climate_api.register_effect(EFFECT_NAME, handle_effect, "tick")
climate_api.register_effect(EFFECT_NAME, stop_effect, "stop")
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.LONG_CYCLE)
climate_api.set_effect_cycle(EFFECT_NAME, climate_api.MEDIUM_CYCLE)