1
0
mirror of https://codeberg.org/tenplus1/ambience.git synced 2024-12-24 09:40:30 +01:00

tweak and tidy code

This commit is contained in:
TenPlus1 2020-06-25 19:25:44 +01:00
parent 11eff9462b
commit d79504239a

View File

@ -182,9 +182,8 @@ minetest.register_globalstep(function(dtime)
-- get list of players and set some variables -- get list of players and set some variables
local players = minetest.get_connected_players() local players = minetest.get_connected_players()
local player_name, number, chance, ambience, handler local player_name, number, chance, ambience, handler, ok
local tod = minetest.get_timeofday() local tod = minetest.get_timeofday()
local ok = true
-- loop through players -- loop through players
for n = 1, #players do for n = 1, #players do
@ -239,7 +238,7 @@ minetest.register_globalstep(function(dtime)
}, ambience.ephemeral) }, ambience.ephemeral)
--print ("playing... " .. ambience.name .. " (" .. chance .. " < " --print ("playing... " .. ambience.name .. " (" .. chance .. " < "
-- .. sound_sets[set_name].frequency .. ") @ ", MORE_GAIN) -- .. sound_sets[set_name].frequency .. ") @ ", MORE_GAIN, handler)
-- only continue if sound playing returns handler -- only continue if sound playing returns handler
if handler then if handler then
@ -247,31 +246,31 @@ minetest.register_globalstep(function(dtime)
--print("-- current handler", handler) --print("-- current handler", handler)
-- set what player is currently listening to -- set what player is currently listening to
playing[player_name] = playing[player_name] or {} playing[player_name] = {
playing[player_name].handler = handler set = set_name, gain = MORE_GAIN,
playing[player_name].set = set_name handler = handler, old_handler = handler
playing[player_name].gain = MORE_GAIN }
playing[player_name].old_handler = handler
-- set timer to stop sound -- set timer to stop sound
minetest.after(ambience.length, function() minetest.after(ambience.length, function()
--print("-- after", set_name, handler)
-- make sure we are stopping same sound we started -- make sure we are stopping same sound we started
if playing[player_name] if playing[player_name]
and playing[player_name].handler and playing[player_name].handler
and playing[player_name].set == set_name and playing[player_name].old_handler == handler then
and handler == playing[player_name].old_handler then
--print("-- timed stop", set_name, handler) --print("-- timed stop", set_name, handler)
--minetest.sound_stop(playing[player_name].handler) --minetest.sound_stop(playing[player_name].handler)
minetest.sound_stop(playing[player_name].old_handler) minetest.sound_stop(handler)
-- reset player variables and backup handler -- reset player variables and backup handler
playing[player_name].set = nil playing[player_name] = {
playing[player_name].handler = nil set = nil, gain = nil,
playing[player_name].gain = nil handler = nil, old_handler = nil
playing[player_name].old_handler = handler }
end end
end) end)
end end