diff --git a/init.lua b/init.lua index bc79a74..0fd5cd3 100644 --- a/init.lua +++ b/init.lua @@ -29,6 +29,10 @@ mtimer = { key = 'mtimer:real_time_format', default = '{24h}:{min} ({isodate})' }, + host_time = { + key = 'mtimer:host_time_format', + default = '{24h}:{min} ({isodate})' + }, session_start_time = { key = 'mtimer:session_start_time_format', default = '{isodate}T{isotime}' diff --git a/locale/mtimer.de.tr b/locale/mtimer.de.tr index 82706c5..e6ee5ac 100644 --- a/locale/mtimer.de.tr +++ b/locale/mtimer.de.tr @@ -6,6 +6,7 @@ Ingame Time Format=Spielzeit-Format Open Main Menu=Hauptmenü öffnen Position=Ausrichtung Real-World Time Format=Realzeit-Format +Host Time Format=Hostzeit-Format Reset Everything=Alles zurücksetzen Session Duration Format=Sitzungsdauer-Format Session Start Time Format=Sitzungsstartzeit-Format diff --git a/screenshots/main_menu.png b/screenshots/main_menu.png index 28aee22..a61a42f 100644 Binary files a/screenshots/main_menu.png and b/screenshots/main_menu.png differ diff --git a/system/chat_command.lua b/system/chat_command.lua index 3152c48..5fcd541 100644 --- a/system/chat_command.lua +++ b/system/chat_command.lua @@ -31,6 +31,7 @@ end -- tz timezone d.timezone_offset(name) -- in ingame d.ingame_time_format(name) -- re real d.real_world_time_format(name) +-- ht host time d.host_time_format(name) -- st start time d.session_start_time_format(name) -- sd session duration d.session_duration_format(name) -- tf timer format d.timer_format(name) @@ -53,6 +54,7 @@ minetest.register_chatcommand('mtimer', { if action == 'tz' then d.timezone_offset(name) end if action == 'in' then d.ingame_time_format(name) end if action == 're' then d.real_world_time_format(name) end + if action == 'ht' then d.host_time_format(name) end if action == 'st' then d.session_start_time_format(name) end if action == 'sd' then d.session_duration_format(name) end if action == 'tf' then d.timer_format(name) end @@ -65,6 +67,7 @@ minetest.register_chatcommand('mtimer', { command('tz')..S('Timezone Offset'), command('in')..S('Ingame Time Format'), command('re')..S('Real-World Time Format'), + command('ht')..S('Host Time Format'), command('st')..S('Session Start Time Format'), command('sd')..S('Session Duration Format'), command('tf')..S('Timer Format'), diff --git a/system/formspec/formspec_creation.lua b/system/formspec/formspec_creation.lua index cd9b1a3..c5bc40f 100644 --- a/system/formspec/formspec_creation.lua +++ b/system/formspec/formspec_creation.lua @@ -26,7 +26,7 @@ mtimer.dialog.main_menu = function (player_name) mtimer.show_formspec('mtimer:main_menu', { title = S('mTimer'), width = 9.5, - height = 6.125, + height = 7.125, prefix = '', add_buttons = false, show_to = player_name, @@ -43,13 +43,14 @@ mtimer.dialog.main_menu = function (player_name) 'button[0,1.5;3,1;real_world_time_format;'..S('Real-World Time Format')..']', 'button[0,2.5;3,1;session_start_time_format;'..S('Session Start Time Format')..']', 'button[0,3.5;3,1;session_duration_format;'..S('Session Duration Format')..']', + 'button[0,4.5;3,1;host_time_format;'..S('Host Time Format')..']', 'container_end[]', 'container[6.5,0]', 'label[0,0;'..S('Timer Configuration')..']', 'button[0,0.5;3,1;timer_format;'..S('Timer Format')..']', 'button[0,1.5;3,1;timezone_offset;'..S('Timezone Offset')..']', 'container_end[]', - 'container[0,4.55]', + 'container[0,5.55]', 'box[0,0;+linewidth,0.04;#ffffff]', 'button[4.5,0.225;2.5,1;reset_everything;'..S('Reset Everything')..']', 'button_exit[7,0.225;2.5,1;exit;'..S('Exit')..']', @@ -183,6 +184,15 @@ mtimer.dialog.real_world_time_format = function (player_name) end +mtimer.dialog.host_time_format = function (player_name) + mtimer.dialog.real_time_universal(player_name, { + time_type = 'host_time', + formspec_name = 'mtimer:host_time_format', + title = S('Host Time Format') + }) +end + + mtimer.dialog.session_start_time_format = function (player_name) mtimer.dialog.real_time_universal(player_name, { time_type = 'session_start_time', @@ -226,7 +236,7 @@ mtimer.dialog.timer_format = function (player_name) mtimer.show_formspec('mtimer:timer_format', { title = S('Timer Format'), show_to = player_name, - height = 4.41, + height = 4.75, formspec = { 'textarea[0.3,0;6,2.5;format;;'..fe(timer_data.format)..']', 'container[0,2.18]', @@ -237,6 +247,7 @@ mtimer.dialog.timer_format = function (player_name) 'label[0,0.9;'..S('In-Game Time')..'] label[2.5,0.9;{it}] label[4,0.9;'..fe(timer_data.ingame_time)..']', 'label[0,1.3;'..S('Session Start Time')..'] label[2.5,1.3;{st}] label[4,1.3;'..fe(timer_data.session_start_time)..']', 'label[0,1.7;'..S('Session Duration')..'] label[2.5,1.7;{sd}] label[4,1.7;'..fe(timer_data.session_duration)..']', + 'label[0,2.1;'..S('Host Time')..'] label[2.5,2.1;{ht}] label[4,2.1;'..fe(timer_data.host_time)..']', 'container_end[]', 'container[6,0]', 'button[0,-0.05;2,1;apply;'..S('Apply')..']', diff --git a/system/get_timer_data.lua b/system/get_timer_data.lua index ba46e3f..24efe68 100644 --- a/system/get_timer_data.lua +++ b/system/get_timer_data.lua @@ -25,7 +25,8 @@ mtimer.get_timer_data = function (player_name) real_world_date = time_data.real_time.formatted, ingame_time = time_data.ingame_time.formatted, session_start_time = time_data.session_start_time.formatted, - session_duration = time_data.session_duration.formatted + session_duration = time_data.session_duration.formatted, + host_time = time_data.host_time.formatted } values['formatted'] = values.format:gsub('{[0-9a-z]+}', { @@ -33,6 +34,7 @@ mtimer.get_timer_data = function (player_name) ['{it}'] = values.ingame_time, ['{st}'] = values.session_start_time, ['{sd}'] = values.session_duration, + ['{ht}'] = values.host_time }) return values diff --git a/system/get_times.lua b/system/get_times.lua index 97c4652..a89ea0c 100644 --- a/system/get_times.lua +++ b/system/get_times.lua @@ -77,6 +77,7 @@ local get_real_time_universal = function (player_name, time_type) local server_timestamp = '' local local_timestamp = '' local format = '' + local force_utc = '!' if time_type == 'real' then server_timestamp = os.time() @@ -86,6 +87,11 @@ local get_real_time_universal = function (player_name, time_type) server_timestamp = player_meta:get('mtimer:session_start') local_timestamp = server_timestamp + ((timezone_offset*60)*60) format = player_meta:get_string(m_meta.session_start_time.key) + elseif time_type == 'host' then + server_timestamp = os.time() + local_timestamp = server_timestamp + format = player_meta:get_string(m_meta.host_time.key) + force_utc = '' end local date_names = get_date_names({ @@ -100,17 +106,17 @@ local get_real_time_universal = function (player_name, time_type) offset = timezone_offset, }, variables = { - hours_24 = os.date('!%H', local_timestamp), - hours_12 = os.date('!%I', local_timestamp), - minutes = os.date('!%M', local_timestamp), - seconds = os.date('!%S', local_timestamp), + hours_24 = os.date(force_utc..'%H', local_timestamp), + hours_12 = os.date(force_utc..'%I', local_timestamp), + minutes = os.date(force_utc..'%M', local_timestamp), + seconds = os.date(force_utc..'%S', local_timestamp), dayname = date_names.day, monthname = date_names.month, - year = os.date('!%Y', local_timestamp), - month = os.date('!%m', local_timestamp), - day = os.date('!%d', local_timestamp), - iso8601_date = os.date('!%Y-%m-%d', local_timestamp), - iso8601_time = os.date('!%H:%M:%S', local_timestamp), + year = os.date(force_utc..'%Y', local_timestamp), + month = os.date(force_utc..'%m', local_timestamp), + day = os.date(force_utc..'%d', local_timestamp), + iso8601_date = os.date(force_utc..'%Y-%m-%d', local_timestamp), + iso8601_time = os.date(force_utc..'%H:%M:%S', local_timestamp), timestamp = local_timestamp }, format = format @@ -253,9 +259,10 @@ end -- @return table The table containing the times as described mtimer.get_times = function (player_name) return { - session_start_time = get_real_time_universal(player_name, 'session'), - session_duration = get_session_duration(player_name), + ingame_time = get_ingame_time(player_name), real_time = get_real_time_universal(player_name, 'real'), - ingame_time = get_ingame_time(player_name) + host_time = get_real_time_universal(player_name, 'host'), + session_start_time = get_real_time_universal(player_name, 'session'), + session_duration = get_session_duration(player_name) } end diff --git a/system/on_receive_fields.lua b/system/on_receive_fields.lua index 723b64f..eb91830 100644 --- a/system/on_receive_fields.lua +++ b/system/on_receive_fields.lua @@ -19,6 +19,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.timezone_offset then d.timezone_offset(name) end if fields.ingame_time_format then d.ingame_time_format(name) end if fields.real_world_time_format then d.real_world_time_format(name) end + if fields.host_time_format then d.host_time_format(name) end if fields.session_start_time_format then d.session_start_time_format(name) end @@ -99,6 +100,16 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end + -- Set host time format + if formname == 'mtimer:host_time_format' then + local attr = m.meta.host_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 d.host_time_format(name) end + end + + -- Set session start time format if formname == 'mtimer:session_start_time_format' then local attr = m.meta.session_start_time