Remember ambience on/off state
parent
dfe45024d2
commit
f05befa436
|
@ -6,6 +6,7 @@ local ambiences = {}
|
|||
|
||||
local current_singleplayer_ambience = nil -- ambience sound handler. nil if no current ambience
|
||||
local current_singleplayer_ambience_id = nil -- ambience type ID (e.g. "ocean", "temple"). nil if uninitialized
|
||||
local ambience_active = true
|
||||
|
||||
lzr_ambience.register_ambience = function(id, soundname, gain)
|
||||
ambiences[id] = { soundname = soundname, gain = gain }
|
||||
|
@ -30,7 +31,7 @@ function lzr_ambience.set_ambience(id, no_play)
|
|||
return true
|
||||
end
|
||||
lzr_ambience.stop_ambience()
|
||||
if id ~= "none" and not no_play then
|
||||
if id ~= "none" and not no_play and ambience_active then
|
||||
current_singleplayer_ambience = minetest.sound_play({name=ambience.soundname}, {gain = ambience.gain, to_player="singleplayer", loop=true})
|
||||
end
|
||||
current_singleplayer_ambience_id = id
|
||||
|
@ -46,8 +47,10 @@ local setting = minetest.settings:get_bool("lzr_ambience_start_with_ambience", t
|
|||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
if setting then
|
||||
ambience_active = true
|
||||
lzr_ambience.set_ambience("ocean")
|
||||
else
|
||||
ambience_active = false
|
||||
lzr_ambience.set_ambience("ocean", true)
|
||||
end
|
||||
end)
|
||||
|
@ -56,9 +59,11 @@ minetest.register_chatcommand("ambience", {
|
|||
description = S("Toggle ambience sounds"),
|
||||
func = function()
|
||||
if current_singleplayer_ambience then
|
||||
ambience_active = false
|
||||
lzr_ambience.stop_ambience()
|
||||
return true, S("Ambience sounds disabled.")
|
||||
else
|
||||
ambience_active = true
|
||||
lzr_ambience.set_ambience(current_singleplayer_ambience_id)
|
||||
return true, S("Ambience sounds enabled.")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue