Fix ambience setting, add settingtypes.txt

master
Wuzzy 2022-03-16 00:17:25 +01:00
parent b0f520ba89
commit dfe45024d2
2 changed files with 14 additions and 7 deletions

View File

@ -4,8 +4,8 @@ local S = minetest.get_translator("lzr_ambience")
local ambiences = {}
local current_singleplayer_ambience = nil
local current_singleplayer_ambience_id = nil
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
lzr_ambience.register_ambience = function(id, soundname, gain)
ambiences[id] = { soundname = soundname, gain = gain }
@ -18,7 +18,7 @@ function lzr_ambience.stop_ambience()
end
end
function lzr_ambience.set_ambience(id)
function lzr_ambience.set_ambience(id, no_play)
local ambience = ambiences[id]
if not ambience then
minetest.log("error", "[lzr_ambience] set_ambience called with invalid ambience ID ("..tostring(id)..")")
@ -26,11 +26,11 @@ function lzr_ambience.set_ambience(id)
end
minetest.log("info", "[lzr_ambience] Ambience set to: "..tostring(id))
-- No-op if we already have this ambience active
if current_singleplayer_ambience_id == id then
if current_singleplayer_ambience_id == id and current_singleplayer_ambience then
return true
end
lzr_ambience.stop_ambience()
if id ~= "none" then
if id ~= "none" and not no_play then
current_singleplayer_ambience = minetest.sound_play({name=ambience.soundname}, {gain = ambience.gain, to_player="singleplayer", loop=true})
end
current_singleplayer_ambience_id = id
@ -42,12 +42,13 @@ lzr_ambience.register_ambience("temple", "lzr_ambience_temple", 1.0)
-- Special ambience that is completely silent
lzr_ambience.register_ambience("none")
local setting = minetest.settings:get_bool("lzr_ambience_start_with_ambience")
if setting == nil then setting = true end
local setting = minetest.settings:get_bool("lzr_ambience_start_with_ambience", true)
minetest.register_on_joinplayer(function(player)
if setting then
lzr_ambience.set_ambience("ocean")
else
lzr_ambience.set_ambience("ocean", true)
end
end)

6
settingtypes.txt Normal file
View File

@ -0,0 +1,6 @@
# If true, laser beams are opaque instead of translucent.
lzr_opaque_lasers (Opaque lasers) bool false
# If true, background ambience sounds will be played.
# Note: You can always toggle ambience sounds in-game with the '/ambience' command.
lzr_ambience_start_with_ambience (Ambience sounds) bool true