Save weather in mod storage

This commit is contained in:
Wuzzy 2019-09-21 18:16:49 +02:00
parent 7df8a3a307
commit 0b61070a16
1 changed files with 10 additions and 1 deletions

View File

@ -5,6 +5,8 @@
local S = minetest.get_translator("weather")
local mod_storage = minetest.get_mod_storage()
weather = {}
weather.weather = "clear"
weather.types = {"storm", "clear"}
@ -63,6 +65,7 @@ local function setweather_type(type, do_repeat)
end
if valid then
weather.weather = type
mod_storage:set_string("weather:weather", weather.weather)
minetest.log("action", "[weather] Weather set to: "..weather.weather)
update_sounds(do_repeat)
return true
@ -88,6 +91,7 @@ minetest.register_globalstep(
weather.weather = "storm"
end
if oldweather ~= weather.weather then
mod_storage:set_string("weather:weather", weather.weather)
minetest.log("action", "[weather] Weather changed to: "..weather.weather)
update_sounds()
end
@ -190,6 +194,11 @@ minetest.register_on_leaveplayer(function(player)
sound_handles[player:get_player_name()] = nil
end)
setweather_type("clear", true)
local loaded_weather = mod_storage:get_string("weather:weather")
if loaded_weather == "" then
setweather_type("clear", true)
else
setweather_type(loaded_weather, true)
end
default.log("mod:weather", "loaded")