mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
implement timezone offset configuration
This commit is contained in:
parent
4c5de1fb42
commit
fbca7a64fa
1
init.lua
1
init.lua
@ -9,6 +9,7 @@ mtimer = {
|
|||||||
visible = { key = 'mtimer:visible', default = 'true' },
|
visible = { key = 'mtimer:visible', default = 'true' },
|
||||||
position = { key = 'mtimer:position', default = 'bl' },
|
position = { key = 'mtimer:position', default = 'bl' },
|
||||||
color = { key = 'mtimer:color', default = '#ffffffFF' },
|
color = { key = 'mtimer:color', default = '#ffffffFF' },
|
||||||
|
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,13 @@ Click the position you want to place the timer at.=Auf die Stelle klicken, an de
|
|||||||
mTimer Color=mTimer-Farbe
|
mTimer Color=mTimer-Farbe
|
||||||
Use `@1` format only!=Ausschließlich `@1`-Format benutzen!
|
Use `@1` format only!=Ausschließlich `@1`-Format benutzen!
|
||||||
|
|
||||||
|
# Timezone Offset
|
||||||
|
mTimer Timezone Offset=mTimer-Zeitzonenunterschied
|
||||||
|
30 minutes @= 0.5, 60 minutes @= 1=30 Minuten @= 0.5, 60 Minuten @= 1
|
||||||
|
“Arbitrary” values are possible.=Es sind „beliebige“ Werte möglich.
|
||||||
|
Server Time: @1=Serverzeit: @1
|
||||||
|
Local Time: @1=Lokale Zeit: @1
|
||||||
|
|
||||||
# Generic Formspec Strings
|
# Generic Formspec Strings
|
||||||
Default=Standard
|
Default=Standard
|
||||||
Exit=Verlassen
|
Exit=Verlassen
|
||||||
|
@ -12,6 +12,9 @@ local build_frame = function (width, height, title)
|
|||||||
container_end[]
|
container_end[]
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local width = width < 6 and 6 or width
|
||||||
|
local height = height < 2 and 2 or height
|
||||||
|
|
||||||
return formspec_frame:gsub('%+%a+', {
|
return formspec_frame:gsub('%+%a+', {
|
||||||
['+width'] = width,
|
['+width'] = width,
|
||||||
['+height'] = height,
|
['+height'] = height,
|
||||||
@ -94,3 +97,32 @@ mtimer.show_formspec.set_color = function (player_name)
|
|||||||
label[-0.05,1.45;]]..S('Use `@1` format only!', hexcolor)..[[]
|
label[-0.05,1.45;]]..S('Use `@1` format only!', hexcolor)..[[]
|
||||||
]])
|
]])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
mtimer.show_formspec.timezone_offset = function (player_name)
|
||||||
|
local player = minetest.get_player_by_name(player_name)
|
||||||
|
local offset = player:get_meta():get_string(m.meta.timezone_offset.key)
|
||||||
|
|
||||||
|
local server_timestamp = os.time()
|
||||||
|
local local_timestamp = server_timestamp + ((offset*60)*60)
|
||||||
|
local server_time = os.date('%Y-%m-%dT%T', server_timestamp)
|
||||||
|
local local_time = os.date('%Y-%m-%dT%T', local_timestamp)
|
||||||
|
|
||||||
|
local format_information = table.concat({
|
||||||
|
S('30 minutes @= 0.5, 60 minutes @= 1'),
|
||||||
|
S('“Arbitrary” values are possible.')
|
||||||
|
}, '\n')
|
||||||
|
|
||||||
|
local time_information = table.concat({
|
||||||
|
S('Server Time: @1', server_time),
|
||||||
|
S('Local Time: @1', local_time)
|
||||||
|
}, '\n')
|
||||||
|
|
||||||
|
minetest.show_formspec(player_name, 'mtimer:timezone_offset',
|
||||||
|
build_frame(7, 3, S('mTimer Timezone Offset'))..[[
|
||||||
|
field_close_on_enter[offset;false]
|
||||||
|
field[0.25,0.75;3,1;offset;;]]..offset..[[]
|
||||||
|
label[3,0.425;]]..format_information..[[]
|
||||||
|
label[0,1.45;]]..time_information..[[]
|
||||||
|
]])
|
||||||
|
end
|
||||||
|
@ -11,6 +11,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
if fields.set_visibility then f.set_visibility(name) end
|
if fields.set_visibility then f.set_visibility(name) end
|
||||||
if fields.set_position then f.set_position(name) end
|
if fields.set_position then f.set_position(name) end
|
||||||
if fields.set_color then f.set_color(name) end
|
if fields.set_color then f.set_color(name) end
|
||||||
|
if fields.timezone_offset then f.timezone_offset(name) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -53,6 +54,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Back to menu from all formspecs
|
-- Back to menu from all formspecs
|
||||||
if fields.main_menu then f.main_menu(name) end
|
if fields.main_menu then f.main_menu(name) end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user