mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-07-04 15:25:27 +02:00
Implement doDaylightCycle, add on_change hook for tunables and make sure they are not called when loaded
This commit is contained in:
parent
f0d9c5c83c
commit
d4286ff535
@ -27,22 +27,27 @@ local tunable_types = {
|
|||||||
|
|
||||||
-- Tunable metatable functions
|
-- Tunable metatable functions
|
||||||
local tunable_class = {}
|
local tunable_class = {}
|
||||||
function tunable_class:set(value)
|
function tunable_class:set(value, no_hook)
|
||||||
local self_type = self.type
|
local self_type = self.type
|
||||||
if type(value) == "string" then
|
if type(value) == "string" then
|
||||||
local new_value = self_type.from_string(value)
|
local new_value = self_type.from_string(value)
|
||||||
if new_value == nil then new_value = self.default end
|
if new_value == nil then new_value = self.default end
|
||||||
|
|
||||||
minetest.log("action","new_value="..dump(new_value))
|
|
||||||
self[1] = new_value
|
self[1] = new_value
|
||||||
else
|
else
|
||||||
self[1] = value
|
self[1] = value
|
||||||
end
|
end
|
||||||
|
|
||||||
local setting = self.setting
|
minetest.log("action", "[vl_tuning] Set "..self.setting.." to "..dump(self[1]))
|
||||||
if setting then
|
|
||||||
storage:set_string(setting,self_type.to_string(self[1]))
|
-- Call on_change hook
|
||||||
|
if not no_hook then
|
||||||
|
local hook = self.on_change
|
||||||
|
if hook then hook(self) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Persist value
|
||||||
|
storage:set_string(self.setting,self_type.to_string(self[1]))
|
||||||
end
|
end
|
||||||
function tunable_class:get_string()
|
function tunable_class:get_string()
|
||||||
return self.type.to_string(self[1])
|
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
|
-- Load the setting value from mod storage
|
||||||
local setting_value = storage:get_string(setting)
|
local setting_value = storage:get_string(setting)
|
||||||
if setting_value and setting_value ~= "" then
|
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
|
end
|
||||||
|
|
||||||
-- Add to the list of all available settings
|
-- Add to the list of all available settings
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
local modname = minetest.get_current_modname()
|
||||||
|
local S = minetest.get_translator(modname)
|
||||||
|
|
||||||
local mods_loaded = false
|
local mods_loaded = false
|
||||||
local NIGHT_VISION_RATIO = 0.45
|
local NIGHT_VISION_RATIO = 0.45
|
||||||
|
|
||||||
@ -7,6 +10,28 @@ local water_color = "#3F76E4"
|
|||||||
|
|
||||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||||
|
|
||||||
|
-- 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)
|
function mcl_weather.set_sky_box_clear(player, sky, fog)
|
||||||
local pos = player:get_pos()
|
local pos = player:get_pos()
|
||||||
if minetest.get_item_group(minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name, "water") ~= 0 then return end
|
if minetest.get_item_group(minetest.get_node(vector.new(pos.x,pos.y+1.5,pos.z)).name, "water") ~= 0 then return end
|
||||||
|
Loading…
Reference in New Issue
Block a user