mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
89cd1f6212
Convert ingame time to millihours and calculate the timestamp from this. It results in a default timestampo that is parsed by default date and time functions. Replacement variables: {24h} = 24 hours time {12h} = 12 hours time {min} = minutes {its} = ingame timestamp For some reason I was not able to get the am/pm indicator (`%p`) so 12 hours format is only the time and no optional indicator.
87 lines
2.9 KiB
Lua
87 lines
2.9 KiB
Lua
local m = mtimer
|
|
local f = mtimer.show_formspec
|
|
|
|
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|
local meta = player:get_meta()
|
|
local name = player:get_player_name()
|
|
|
|
|
|
-- Select what formspec to show basing on main menu button
|
|
if formname == 'mtimer:main_menu' then
|
|
if fields.set_visibility then f.set_visibility(name) end
|
|
if fields.set_position then f.set_position(name) end
|
|
if fields.set_color then f.set_color(name) end
|
|
if fields.timezone_offset then f.timezone_offset(name) end
|
|
if fields.ingame_time_format then f.ingame_time_format(name) end
|
|
end
|
|
|
|
|
|
-- Set timer visibility
|
|
if formname == 'mtimer:set_visibility' then
|
|
local attr = m.meta.visible
|
|
if fields.visible then meta:set_string(attr.key, 'true') end
|
|
if fields.invisible then meta:set_string(attr.key, 'false') end
|
|
if fields.default then meta:set_string(attr.key, attr.default) end
|
|
end
|
|
|
|
|
|
-- Set timer position
|
|
if formname == 'mtimer:set_position' then
|
|
local attr = m.meta.position
|
|
for p,_ in pairs(fields) do
|
|
if p == 'default' then
|
|
meta:set_string(attr.key, attr.default)
|
|
elseif p:gsub('_.*', '') == 'pos' then
|
|
local new_pos = p:gsub('pos_', '')
|
|
if new_pos ~= 'xx' then meta:set_string(attr.key, new_pos) end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
-- Set timer text color
|
|
if formname == 'mtimer:set_color' then
|
|
local attr = m.meta.color
|
|
local color = ''
|
|
|
|
if fields.color then
|
|
local valid = fields.color:match('^#'..('[0-9a-fA-F]'):rep(8)..'$')
|
|
local color = valid and fields.color or attr.default
|
|
meta:set_string(attr.key, color)
|
|
end
|
|
|
|
if fields.default then meta:set_string(attr.key, attr.default) end
|
|
if not fields.quit then mtimer.show_formspec.set_color(name) end
|
|
end
|
|
|
|
|
|
-- Configure timezone offset
|
|
if formname == 'mtimer:timezone_offset' then
|
|
local attr = m.meta.timezone_offset
|
|
local value = tonumber(fields.offset) or attr.default
|
|
if math.abs(value) > os.time() then value = 0 end
|
|
meta:set_string(attr.key, value)
|
|
if fields.default then meta:set_string(attr.key, attr.default) end
|
|
if not fields.quit then mtimer.show_formspec.timezone_offset(name) end
|
|
end
|
|
|
|
|
|
-- Set ingame time format
|
|
if formname == 'mtimer:ingame_time_format' then
|
|
local attr = m.meta.ingame_time
|
|
local value = fields.format or attr.default
|
|
meta:set_string(attr.key, value)
|
|
if fields.default then meta:set_string(attr.key, attr.default) end
|
|
if not fields.quit then mtimer.show_formspec.ingame_time_format(name)end
|
|
end
|
|
|
|
|
|
|
|
-- Back to menu from all formspecs
|
|
if fields.main_menu then f.main_menu(name) end
|
|
|
|
|
|
-- DEBUG: Print all player meta data
|
|
print(dump(meta:to_table()))
|
|
end)
|