mirror of
https://github.com/t-affeldt/climate_api.git
synced 2025-06-30 07:20:48 +02:00
Sound improvements
This commit is contained in:
@ -2,10 +2,18 @@ climate_api.register_influence("heat", function(pos)
|
||||
return climate_api.environment.get_heat(pos)
|
||||
end)
|
||||
|
||||
climate_api.register_influence("base_heat", function(pos)
|
||||
return minetest.get_heat(pos)
|
||||
end)
|
||||
|
||||
climate_api.register_influence("humidity", function(pos)
|
||||
return climate_api.environment.get_humidity(pos)
|
||||
end)
|
||||
|
||||
climate_api.register_influence("base_humidity", function(pos)
|
||||
return minetest.get_humidity(pos)
|
||||
end)
|
||||
|
||||
climate_api.register_influence("biome", function(pos)
|
||||
local data = minetest.get_biome_data(pos)
|
||||
local biome = minetest.get_biome_name(data.biome)
|
||||
|
57
lib/soundloop.lua
Normal file
57
lib/soundloop.lua
Normal file
@ -0,0 +1,57 @@
|
||||
local soundloop = {}
|
||||
local sounds = {}
|
||||
|
||||
local function parse_sound(sound)
|
||||
if type(sound) == "string" then
|
||||
return { name = sound, gain = 1, pitch = 1 }
|
||||
end
|
||||
if sound.gain == nil then sound.gain = 1 end
|
||||
if sound.pitch == nil then sound.pitch = 1 end
|
||||
return sound
|
||||
end
|
||||
|
||||
soundloop.play = function(player, sound, fade)
|
||||
sound = parse_sound(sound)
|
||||
if fade == nil then fade = 1 end
|
||||
local step
|
||||
local handle
|
||||
local start_gain
|
||||
if sounds[player] == nil then sounds[player] = {} end
|
||||
if sounds[player][sound.name] == nil then
|
||||
step = sound.gain / fade
|
||||
start_gain = 0
|
||||
elseif sounds[player][sound.name] ~= sound.gain then
|
||||
minetest.sound_stop(sounds[player][sound.name].handle)
|
||||
start_gain = sounds[player][sound.name].gain
|
||||
local change = sound.gain - start_gain
|
||||
step = change / fade
|
||||
else
|
||||
return
|
||||
end
|
||||
handle = minetest.sound_play(sound.name, {
|
||||
to_player = player,
|
||||
loop = true,
|
||||
gain = 0
|
||||
})
|
||||
sounds[player][sound.name] = {
|
||||
gain = sound.gain,
|
||||
handle = handle
|
||||
}
|
||||
minetest.sound_fade(handle, step, sound.gain)
|
||||
return handle
|
||||
end
|
||||
|
||||
soundloop.stop = function(player, sound, fade)
|
||||
sound = parse_sound(sound)
|
||||
if sounds[player] == nil or sounds[player][sound.name] == nil then
|
||||
return
|
||||
end
|
||||
if fade == nil then fade = 1 end
|
||||
local handle = sounds[player][sound.name].handle
|
||||
local step = -sounds[player][sound.name].gain / fade
|
||||
minetest.sound_fade(handle, step, 0)
|
||||
sounds[player][sound.name].gain = 0
|
||||
minetest.after(fade, minetest.sound_stop, handle)
|
||||
end
|
||||
|
||||
return soundloop
|
Reference in New Issue
Block a user