mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-29 05:51:05 +01:00
Implement doDaylightCycle, add on_change hook for tunables and make sure they are not called when loaded
This commit is contained in:
parent
38ed457211
commit
d8af2d4ced
2 changed files with 37 additions and 6 deletions
|
@ -27,22 +27,27 @@ local tunable_types = {
|
|||
|
||||
-- Tunable metatable functions
|
||||
local tunable_class = {}
|
||||
function tunable_class:set(value)
|
||||
function tunable_class:set(value, no_hook)
|
||||
local self_type = self.type
|
||||
if type(value) == "string" then
|
||||
local new_value = self_type.from_string(value)
|
||||
if new_value == nil then new_value = self.default end
|
||||
|
||||
minetest.log("action","new_value="..dump(new_value))
|
||||
self[1] = new_value
|
||||
else
|
||||
self[1] = value
|
||||
end
|
||||
|
||||
local setting = self.setting
|
||||
if setting then
|
||||
storage:set_string(setting,self_type.to_string(self[1]))
|
||||
minetest.log("action", "[vl_tuning] Set "..self.setting.." to "..dump(self[1]))
|
||||
|
||||
-- Call on_change hook
|
||||
if not no_hook then
|
||||
local hook = self.on_change
|
||||
if hook then hook(self) end
|
||||
end
|
||||
|
||||
-- Persist value
|
||||
storage:set_string(self.setting,self_type.to_string(self[1]))
|
||||
end
|
||||
function tunable_class:get_string()
|
||||
return self.type.to_string(self[1])
|
||||
|
@ -63,7 +68,8 @@ function mod.setting(setting, setting_type, def )
|
|||
-- Load the setting value from mod storage
|
||||
local setting_value = storage:get_string(setting)
|
||||
if setting_value and setting_value ~= "" then
|
||||
tunable:set(setting_value)
|
||||
tunable:set(setting_value, true)
|
||||
minetest.log("action", "[vl_tuning] Loading "..setting.." = "..dump(setting_value).." ("..dump(tunable[1])..")")
|
||||
end
|
||||
|
||||
-- Add to the list of all available settings
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
-- Constants
|
||||
local modname = minetest.get_current_modname()
|
||||
local modpath = minetest.get_modpath(modname)
|
||||
local S = minetest.get_translator(modname)
|
||||
|
||||
local mods_loaded = false
|
||||
local NIGHT_VISION_RATIO = 0.45
|
||||
local DEBUG = false
|
||||
|
||||
|
@ -10,6 +13,28 @@ local minimum_update_interval = { 250e3 }
|
|||
-- Module state
|
||||
local mods_loaded = false
|
||||
|
||||
-- Daylight cycle handling
|
||||
local fixed_time = vl_tuning.setting("fixed_daylight_time", "number", {
|
||||
description = S("Time of day to use when gamerule:doDaylightCycle == false"),
|
||||
default = 0.5
|
||||
})
|
||||
local gamerule_doDaylightCycle = vl_tuning.setting("gamerule:doDaylightCycle", "bool",{
|
||||
description = S("Whether the daylight cycle and moon phases progress"),
|
||||
default = true,
|
||||
on_change = function(self)
|
||||
if not self[1] then
|
||||
fixed_time:set(minetest.get_timeofday())
|
||||
end
|
||||
end
|
||||
})
|
||||
local function daylightCycle()
|
||||
if not gamerule_doDaylightCycle[1] and fixed_time[1] then
|
||||
minetest.set_timeofday(fixed_time[1])
|
||||
end
|
||||
minetest.after(1, daylightCycle)
|
||||
end
|
||||
minetest.after(1, daylightCycle)
|
||||
|
||||
function mcl_weather.set_sky_box_clear(player, sky, fog)
|
||||
-- Make sure the player's head isn't in water before changing the skybox
|
||||
local node_head = mcl_playerinfo[player:get_player_name()].node_head
|
||||
|
|
Loading…
Reference in a new issue