Fix overly verbose mod.

This doesn't remove any messages, but marks most of them as "info"
or "verbose". Turning the minetest log to verbose will allow anyone
debugging them to get all the messages again.
This commit is contained in:
Auke Kok 2016-05-26 15:45:38 -07:00
parent e356df7616
commit cef840ae04
1 changed files with 37 additions and 37 deletions

View File

@ -60,7 +60,7 @@ local old_settime_func = core.chatcommands["time"].func
core.chatcommands["time"].func = function(...) core.chatcommands["time"].func = function(...)
local res, msg = old_settime_func(...) local res, msg = old_settime_func(...)
if res and time_reg.status == time_reg.STATUS_ACTIVE then if res and time_reg.status == time_reg.STATUS_ACTIVE then
time_reg.log("Settime override : updating regulation") time_reg.log("Settime override : updating regulation", "verbose")
time_reg.loop(false, true) time_reg.loop(false, true)
end end
return res, msg return res, msg
@ -70,7 +70,7 @@ local old_set_func = core.chatcommands["set"].func
core.chatcommands["set"].func = function(...) core.chatcommands["set"].func = function(...)
local res, msg = old_set_func(...) local res, msg = old_set_func(...)
if res and time_reg.status ~= time_reg.STATUS_DEAD and tonumber(minetest.setting_get("time_speed")) ~= time_reg.time_speed then if res and time_reg.status ~= time_reg.STATUS_DEAD and tonumber(minetest.setting_get("time_speed")) ~= time_reg.time_speed then
time_reg.log("Set override : updating constants and regulation") time_reg.log("Set override : updating constants and regulation", "verbose")
time_reg.update_constants({time_speed = true}) time_reg.update_constants({time_speed = true})
end end
return res, msg return res, msg
@ -81,16 +81,16 @@ end
-- Information functions -- Information functions
-- Function meant to be an alias to minetest.log("action", "[TimeRegulation] " + parameters) -- Function meant to be an alias to minetest.log("action", "[TimeRegulation] " + parameters)
function time_reg.log(x) minetest.log("action", "[TimeRegulation] " .. (x or "")) end function time_reg.log(x, ...) minetest.log(... or "action", "[TimeRegulation] " .. (x or "")) end
-- Standard calculation function -- Standard calculation function
-- Function used when performing calculation of standard method (meaning that we already have the ratio) -- Function used when performing calculation of standard method (meaning that we already have the ratio)
function time_reg.std_calculation() function time_reg.std_calculation()
time_reg.log("Calculation using time_speed = " .. time_reg.time_speed) time_reg.log("Calculation using time_speed = " .. time_reg.time_speed, "verbose")
local day_htime, night_htime = time_reg.duration * (time_reg.ratio.day/100), time_reg.duration * (time_reg.ratio.night/100) local day_htime, night_htime = time_reg.duration * (time_reg.ratio.day/100), time_reg.duration * (time_reg.ratio.night/100)
time_reg.day_time_speed = 1440 / day_htime / 2 -- Human times are divided per two since we only span half a cycle for each period of a day time_reg.day_time_speed = 1440 / day_htime / 2 -- Human times are divided per two since we only span half a cycle for each period of a day
time_reg.night_time_speed = 1440 / night_htime / 2 time_reg.night_time_speed = 1440 / night_htime / 2
time_reg.log("Output is : " .. time_reg.day_time_speed .. " (day); " .. time_reg.night_time_speed .. " (night)") time_reg.log("Output is : " .. time_reg.day_time_speed .. " (day); " .. time_reg.night_time_speed .. " (night)", "verbose")
end end
-- Seasonal calculation function -- Seasonal calculation function
@ -105,7 +105,7 @@ function time_reg.seasonal_calculation()
time_reg.ratio.night = (((math.cos((time_reg.day_of_year / ylength) * 2 * math.pi) * time_reg.offset) / 2.0) + 0.5) * 100 time_reg.ratio.night = (((math.cos((time_reg.day_of_year / ylength) * 2 * math.pi) * time_reg.offset) / 2.0) + 0.5) * 100
time_reg.ratio.day = 100 - time_reg.ratio.night time_reg.ratio.day = 100 - time_reg.ratio.night
time_reg.log("Seasonal calculation done") time_reg.log("Seasonal calculation done", "verbose")
end end
-- Constants update function -- Constants update function
@ -154,7 +154,7 @@ end
-- Launch the Loop with the order to repeat itself indefinitely -- Launch the Loop with the order to repeat itself indefinitely
function time_reg.start_loop() function time_reg.start_loop()
if time_reg.loop_active then if time_reg.loop_active then
time_reg.log("Will not start the loop : one is already running") time_reg.log("Will not start the loop : one is already running", "error")
return false return false
end end
time_reg.loop_active = true time_reg.loop_active = true
@ -162,7 +162,7 @@ function time_reg.start_loop()
time_reg.set_status(time_reg.STATUS_ACTIVE, "ACTIVE") time_reg.set_status(time_reg.STATUS_ACTIVE, "ACTIVE")
end end
time_reg.loop(true) time_reg.loop(true)
time_reg.log("Loop started") time_reg.log("Loop started", "verbose")
return true return true
end end
@ -170,25 +170,25 @@ end
-- Break the Loop by setting time_reg.loop_active to false, unless it isn't running -- Break the Loop by setting time_reg.loop_active to false, unless it isn't running
function time_reg.stop_loop() function time_reg.stop_loop()
if not time_reg.loop_active then if not time_reg.loop_active then
time_reg.log("Will not break the loop : no loop running") time_reg.log("Will not break the loop : no loop running", "error")
return false return false
end end
time_reg.loop_active = false time_reg.loop_active = false
time_reg.log("Loop asked to stop") time_reg.log("Loop asked to stop", "verbose")
return true return true
end end
-- Set status -- Set status
-- Set the mechanism's current status (an integer, and a title) -- Set the mechanism's current status (an integer, and a title)
function time_reg.set_status(x, title) function time_reg.set_status(x, title)
time_reg.log("Entered status " .. x .. " (" .. title .. ")") time_reg.log("Entered status " .. x .. " (" .. title .. ")", "info")
time_reg.status = x time_reg.status = x
end end
-- And the loop -- And the loop
function time_reg.loop(loop, forceupdate) function time_reg.loop(loop, forceupdate)
if not loop then if not loop then
time_reg.log("Loop running as standalone") time_reg.log("Loop running as standalone", "verbose")
end end
-- Do all calculations -- Do all calculations
@ -196,7 +196,7 @@ function time_reg.loop(loop, forceupdate)
time_reg.compute() time_reg.compute()
if not time_reg.loop_active then if not time_reg.loop_active then
time_reg.set_status(time_reg.STATUS_IDLE, "IDLE") time_reg.set_status(time_reg.STATUS_IDLE, "IDLE")
time_reg.log("Loop broken") time_reg.log("Loop broken", "error")
return return
end end
@ -215,18 +215,18 @@ function time_reg.loop(loop, forceupdate)
if moment == "day" then if moment == "day" then
if time_reg.ratio.day == 0 then if time_reg.ratio.day == 0 then
minetest.set_timeofday(time_reg.threshold.night / 24000) minetest.set_timeofday(time_reg.threshold.night / 24000)
time_reg.log("Entering day period : period skipped") time_reg.log("Entering day period : period skipped", "info")
else else
minetest.setting_set("time_speed", time_reg.day_time_speed) minetest.setting_set("time_speed", time_reg.day_time_speed)
time_reg.log("Entering day period : time_speed " .. time_reg.day_time_speed) time_reg.log("Entering day period : time_speed " .. time_reg.day_time_speed, "info")
end end
else else
if time_reg.ratio.night == 0 then if time_reg.ratio.night == 0 then
minetest.set_timeofday(time_reg.threshold.day / 24000) minetest.set_timeofday(time_reg.threshold.day / 24000)
time_reg.log("Entering night period : period skipped") time_reg.log("Entering night period : period skipped", "info")
else else
minetest.setting_set("time_speed", time_reg.night_time_speed) minetest.setting_set("time_speed", time_reg.night_time_speed)
time_reg.log("Entering night period : time_speed " .. time_reg.night_time_speed) time_reg.log("Entering night period : time_speed " .. time_reg.night_time_speed, "info")
end end
end end
end end
@ -235,7 +235,7 @@ function time_reg.loop(loop, forceupdate)
if loop then if loop then
minetest.after(time_reg.loop_interval, time_reg.loop, time_reg.loop_active) minetest.after(time_reg.loop_interval, time_reg.loop, time_reg.loop_active)
else else
time_reg.log("Loop stopped") time_reg.log("Loop stopped", "verbose")
end end
end end
@ -342,47 +342,47 @@ function time_reg.init()
if time_reg.seasons_mode then if time_reg.seasons_mode then
time_reg.log("Seasonal ratio calculation: on") time_reg.log("Seasonal ratio calculation: on")
if time_reg.real_life_seasons then if time_reg.real_life_seasons then
time_reg.log("Seasonal ratio calculated from real life date") time_reg.log("Seasonal ratio calculated from real life date", "info")
else else
time_reg.log("Seasonal ratio calculated from game date") time_reg.log("Seasonal ratio calculated from game date", "info")
end end
else else
time_reg.log("Seasonal ratio calculation: off") time_reg.log("Seasonal ratio calculation: off", "info")
end end
if not time_reg.enabled then if not time_reg.enabled then
time_reg.log("Time Regulation is disabled by default. Use /time_reg start to start it") time_reg.log("Time Regulation is disabled by default. Use /time_reg start to start it", "action")
else else
time_reg.start_loop() time_reg.start_loop()
end end
time_reg.log("Duration: " .. time_reg.duration .. " minutes") time_reg.log("Duration: " .. time_reg.duration .. " minutes", "verbose")
time_reg.log("Loop interval: " .. time_reg.loop_interval .. "s") time_reg.log("Loop interval: " .. time_reg.loop_interval .. "s", "verbose")
time_reg.log("Ratio:") time_reg.log("Ratio:", "verbose")
time_reg.log("\tDay: " .. time_reg.ratio.day .. "%") time_reg.log("\tDay: " .. time_reg.ratio.day .. "%", "verbose")
time_reg.log("\tNight: " .. time_reg.ratio.night .. "%") time_reg.log("\tNight: " .. time_reg.ratio.night .. "%", "verbose")
time_reg.log("Applied time speeds:") time_reg.log("Applied time speeds:", "verbose")
time_reg.log("\tDay: " .. time_reg.day_time_speed) time_reg.log("\tDay: " .. time_reg.day_time_speed, "verbose")
time_reg.log("\tNight: " .. time_reg.night_time_speed) time_reg.log("\tNight: " .. time_reg.night_time_speed, "verbose")
time_reg.log("Human Durations of Half-Cycles:") time_reg.log("Human Durations of Half-Cycles:", "verbose")
time_reg.log("\tDay: " .. 1440 / time_reg.day_time_speed / 2 .. " minutes") time_reg.log("\tDay: " .. 1440 / time_reg.day_time_speed / 2 .. " minutes", "verbose")
time_reg.log("\tNight: " .. 1440 / time_reg.night_time_speed / 2 .. " minutes") time_reg.log("\tNight: " .. 1440 / time_reg.night_time_speed / 2 .. " minutes", "verbose")
end end
-- Shutdown -- Shutdown
-- Sometimes MT will shutdown and write current time_speed in minetest.conf; we need to change the value back to normal before it happens -- Sometimes MT will shutdown and write current time_speed in minetest.conf; we need to change the value back to normal before it happens
function time_reg.on_shutdown() function time_reg.on_shutdown()
minetest.setting_set("time_speed", time_reg.time_speed) minetest.setting_set("time_speed", time_reg.time_speed)
time_reg.log("Time speed set back to " .. time_reg.time_speed) time_reg.log("Time speed set back to " .. time_reg.time_speed, "verbose")
end end
minetest.register_on_shutdown(time_reg.on_shutdown) minetest.register_on_shutdown(time_reg.on_shutdown)
-- --[[ NOW WE SHALL START ]]-- -- -- --[[ NOW WE SHALL START ]]-- --
time_reg.log("Thank you for using TimeRegulation v" .. time_reg.version .. " by " .. table.concat(time_reg.authors, ", ")) time_reg.log("Thank you for using TimeRegulation v" .. time_reg.version .. " by " .. table.concat(time_reg.authors, ", "), "info")
time_reg.log("Status: " .. time_reg.status) time_reg.log("Status: " .. time_reg.status, "info")
time_reg.log("Absolute Time Speed: " .. time_reg.time_speed) time_reg.log("Absolute Time Speed: " .. time_reg.time_speed, "verbose")
minetest.after(0.1, time_reg.init) minetest.after(0.1, time_reg.init)