mirror of
https://gitlab.com/4w/mtimer.git
synced 2024-11-28 10:13:50 +01:00
unification and configuration additions
This commit is contained in:
parent
91c3ec5332
commit
1817f4b046
16
init.lua
16
init.lua
@ -11,12 +11,26 @@ mtimer = {
|
||||
color = { key = 'mtimer:color', default = '#ffffffFF' },
|
||||
timezone_offset = { key = 'mtimer:timezone_offset', default = '0' },
|
||||
ingame_time = {key='mtimer:ingame_time_format',default='{24h}:{min}'},
|
||||
real_time = { key='mtimer:real_time_format', default='{24h}:{min}' },
|
||||
session_start_time = {
|
||||
key = 'mtimer:session_start_time_format',
|
||||
default = '{isodate}T{isotime}'
|
||||
},
|
||||
session_duration = {
|
||||
key = 'mtimer:session_duration_format',
|
||||
default = '{hours}:{minutes}'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-- Load formspec functionality
|
||||
dofile(syspath..'formspec'..DIR_DELIM..'formspec_helpers.lua')
|
||||
dofile(syspath..'formspec'..DIR_DELIM..'real_time_universal.lua')
|
||||
dofile(syspath..'formspec'..DIR_DELIM..'formspec_creation.lua')
|
||||
|
||||
-- Load system
|
||||
dofile(syspath..'chat_command.lua')
|
||||
dofile(syspath..'formspec_creation.lua')
|
||||
dofile(syspath..'timer_update.lua')
|
||||
dofile(syspath..'on_receive_fields.lua')
|
||||
dofile(syspath..'on_joinplayer.lua')
|
||||
|
@ -1,43 +1,49 @@
|
||||
# textdomain: mtimer
|
||||
|
||||
# Configuration Selection Menu and chat command help
|
||||
# mTimer configuration section names
|
||||
mTimer Configuration=mTimer-Konfiguration
|
||||
Set Visibility=Sichtbarkeit einstellen
|
||||
Set Position=Position setzen
|
||||
Set Color=Farbe einstellen
|
||||
Visibility=Sichtbarkeit
|
||||
Position=Position
|
||||
Color=Farbe
|
||||
Timezone Offset=Zeitzonenunterschied
|
||||
Ingame Time Format=Spielzeit-Format
|
||||
Real-World Time Format=Realzeit-Format
|
||||
Session Start Time Format=Session-Startzeit-Format
|
||||
Session Duration Format=Session-Dauer-Format
|
||||
Set Timer Text=Timertext einstellen
|
||||
Open Main Menu=Hauptmenü öffnen
|
||||
|
||||
# Visibility
|
||||
mTimer Visibility=mTimer-Sichtbarkeit
|
||||
Visible=Sichtbar
|
||||
Invisible=Unsichtbar
|
||||
|
||||
# Positioning
|
||||
mTimer Position=mTimer-Position
|
||||
Click the position you want to place the timer at.=Auf die Stelle klicken, an der der Timer angezeigt werden soll.
|
||||
|
||||
# Set Color
|
||||
mTimer Color=mTimer-Farbe
|
||||
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
|
||||
|
||||
# Time format strings
|
||||
# Real time format strings (universal formspec)
|
||||
Variable=Variable
|
||||
Current value=Aktueller Wert
|
||||
Hours (24h)=Stunden (24h-Format)
|
||||
Hours (12h)=Stunden (12h-Format)
|
||||
Hours (24h)=24-Stunden-Stunde
|
||||
Hours (12h)=12-Stunden-Stunde
|
||||
Minutes=Minuten
|
||||
Ingame Timestamp=Spielzeit-Zeitstempel
|
||||
Seconds=Sekunden
|
||||
Day Name=Tagesname
|
||||
Month Name=Monatsname
|
||||
Year=Jahr
|
||||
Month=Monat
|
||||
Day=Tag
|
||||
ISO 8601 Date=Datum nach ISO 8601
|
||||
ISO 8601 Time=Zeit nach ISO 8601
|
||||
Timestamp=Zeitstempel
|
||||
Current Result=Aktuelles Ergebnis
|
||||
|
||||
# Generic Formspec Strings
|
||||
|
@ -10,7 +10,7 @@ end
|
||||
|
||||
minetest.register_chatcommand('mtimer', {
|
||||
description = S('Configure timer display'),
|
||||
params = '<vi/po/co/tz/in/re/te/help>',
|
||||
params = '<vi/po/co/tz/in/re/st/sd/te/help>',
|
||||
func = function(name, parameters)
|
||||
local action = parameters:match('%a+')
|
||||
|
||||
@ -22,7 +22,9 @@ minetest.register_chatcommand('mtimer', {
|
||||
if action == 'co' then fs.set_color(name) end
|
||||
if action == 'tz' then fs.timezone_offset(name) end
|
||||
if action == 'in' then fs.ingame_time_format(name) end
|
||||
if action == 're' then fs.real_time_format(name) end
|
||||
if action == 're' then fs.real_world_time_format(name) end
|
||||
if action == 'st' then fs.session_start_time_format(name) end
|
||||
if action == 'sd' then fs.session_duration_format(name) end
|
||||
if action == 'te' then fs.timer_text(name) end
|
||||
|
||||
if action == 'help' then
|
||||
@ -33,6 +35,8 @@ minetest.register_chatcommand('mtimer', {
|
||||
command('tz')..S('Timezone Offset'),
|
||||
command('in')..S('Ingame Time Format'),
|
||||
command('re')..S('Real-World Time Format'),
|
||||
command('st')..S('Session Start Time Format'),
|
||||
command('sd')..S('Session Duration Format'),
|
||||
command('te')..S('Set Timer Text'),
|
||||
command(' ')..S('Open Main Menu')
|
||||
}
|
||||
|
@ -1,53 +1,30 @@
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
|
||||
|
||||
local build_frame = function (width, height, title)
|
||||
local formspec_frame = [[
|
||||
size[+width,+height] label[0,-0.125;+title]
|
||||
container[0,+position]
|
||||
button_exit[+exitpos,0;+bwidth,1;exit;]]..S('Exit')..[[]
|
||||
button[+mainpos,0;+bwidth,1;main_menu;]]..S('Main Menu')..[[]
|
||||
button[+defaultpos,0;+bwidth,1;default;]]..S('Default')..[[]
|
||||
container_end[]
|
||||
]]
|
||||
|
||||
local width = width < 6 and 6 or width
|
||||
local height = height < 2 and 2 or height
|
||||
|
||||
return formspec_frame:gsub('%+%a+', {
|
||||
['+width'] = width,
|
||||
['+height'] = height,
|
||||
['+title'] = title,
|
||||
['+position'] = height-0.6,
|
||||
['+bwidth'] = width/3,
|
||||
['+exitpos'] = 0,
|
||||
['+mainpos'] = width/3,
|
||||
['+defaultpos'] = (width/3)*2
|
||||
})
|
||||
end
|
||||
local build_frame = m.build_frame
|
||||
|
||||
|
||||
mtimer.show_formspec.main_menu = function (player_name)
|
||||
minetest.show_formspec(player_name, 'mtimer:main_menu', [[
|
||||
size[4,8.25]
|
||||
size[4,10.25]
|
||||
label[0,-0.125;]]..S('mTimer Configuration')..[[]
|
||||
|
||||
button[0,0.5;4,1;set_visibility;]]..S('Set Visibility')..[[]
|
||||
button[0,1.5;4,1;set_position;]]..S('Set Position')..[[]
|
||||
button[0,2.5;4,1;set_color;]]..S('Set Color')..[[]
|
||||
button[0,0.5;4,1;set_visibility;]]..S('Visibility')..[[]
|
||||
button[0,1.5;4,1;set_position;]]..S('Position')..[[]
|
||||
button[0,2.5;4,1;set_color;]]..S('Color')..[[]
|
||||
button[0,3.5;4,1;timezone_offset;]]..S('Timezone Offset')..[[]
|
||||
button[0,4.5;4,1;ingame_time_format;]]..S('Ingame Time Format')..[[]
|
||||
button[0,5.5;4,1;real_world_time_format;]]..S('Real-World Time Format')..[[]
|
||||
button[0,6.5;4,1;timer_text;]]..S('Set Timer Text')..[[]
|
||||
button_exit[0,7.5;4,1;exit;]]..S('Exit')..[[]
|
||||
button[0,6.5;4,1;session_start_time_format;]]..S('Session Start Time Format')..[[]
|
||||
button[0,7.5;4,1;session_duration_format;]]..S('Session Duration Format')..[[]
|
||||
button[0,8.5;4,1;timer_text;]]..S('Set Timer Text')..[[]
|
||||
button_exit[0,9.5;4,1;exit;]]..S('Exit')..[[]
|
||||
]])
|
||||
end
|
||||
|
||||
|
||||
mtimer.show_formspec.set_visibility = function (player_name)
|
||||
minetest.show_formspec(player_name, 'mtimer:set_visibility',
|
||||
build_frame(6, 2.25, S('mTimer Visibility'))..[[
|
||||
build_frame(6, 2.25, S('Visibility'))..[[
|
||||
button[0,0.5;3,1;visible;]]..S('Visible')..[[]
|
||||
button[3,0.5;3,1;invisible;]]..S('Invisible')..[[]
|
||||
]])
|
||||
@ -56,7 +33,7 @@ end
|
||||
|
||||
mtimer.show_formspec.set_position = function (player_name)
|
||||
minetest.show_formspec(player_name, 'mtimer:set_position',
|
||||
build_frame(8, 6.125, S('mTimer Position'))..[[
|
||||
build_frame(8, 6.2, S('Position'))..[[
|
||||
|
||||
image_button[0,0.5;8,4.5 ;mtimer_positions_orientation.png;pos_xx;;;false]
|
||||
|
||||
@ -90,7 +67,7 @@ mtimer.show_formspec.set_color = function (player_name)
|
||||
})
|
||||
|
||||
minetest.show_formspec(player_name, 'mtimer:set_color',
|
||||
build_frame(6, 2.7, S('mTimer Color'))..[[
|
||||
build_frame(6, 2.7, S('Color'))..[[
|
||||
field_close_on_enter[color;false]
|
||||
field[0.25,0.75;3,1;color;;]]..color..[[]
|
||||
box[3,0.55;0.65,0.65;]]..color..[[]
|
||||
@ -101,8 +78,6 @@ end
|
||||
|
||||
mtimer.show_formspec.timezone_offset = function (player_name)
|
||||
local time_data = mtimer.get_times(player_name).real_time
|
||||
local server_time = os.date('%Y-%m-%dT%T', time_data.server_timestamp)
|
||||
local local_time = os.date('%Y-%m-%dT%T', time_data.local_timestamp)
|
||||
|
||||
local format_information = table.concat({
|
||||
S('30 minutes @= 0.5, 60 minutes @= 1'),
|
||||
@ -110,14 +85,14 @@ mtimer.show_formspec.timezone_offset = function (player_name)
|
||||
}, '\n')
|
||||
|
||||
local time_information = table.concat({
|
||||
S('Server Time: @1', server_time),
|
||||
S('Local Time: @1', local_time)
|
||||
S('Server Time: @1', time_data.times.server_time),
|
||||
S('Local Time: @1', time_data.times.local_time)
|
||||
}, '\n')
|
||||
|
||||
minetest.show_formspec(player_name, 'mtimer:timezone_offset',
|
||||
build_frame(7, 3, S('mTimer Timezone Offset'))..[[
|
||||
build_frame(7, 3.125, S('Timezone Offset'))..[[
|
||||
field_close_on_enter[offset;false]
|
||||
field[0.25,0.75;3,1;offset;;]]..time_data.offset..[[]
|
||||
field[0.25,0.75;3,1;offset;;]]..time_data.times.offset..[[]
|
||||
label[3,0.425;]]..format_information..[[]
|
||||
label[0,1.45;]]..time_information..[[]
|
||||
]])
|
||||
@ -128,7 +103,7 @@ mtimer.show_formspec.ingame_time_format = function (player_name)
|
||||
local time_data = mtimer.get_times(player_name).ingame_time
|
||||
|
||||
minetest.show_formspec(player_name, 'mtimer:ingame_time_format',
|
||||
build_frame(7, 4.85, S('Ingame Time Format'))..[[
|
||||
build_frame(7, 4.9, S('Ingame Time Format'))..[[
|
||||
field_close_on_enter[format;false]
|
||||
field[0.25,0.75;7,1;format;;]]..time_data.format..[[]
|
||||
container[0,1.425]
|
||||
@ -161,3 +136,62 @@ mtimer.show_formspec.ingame_time_format = function (player_name)
|
||||
container_end[]
|
||||
]])
|
||||
end
|
||||
|
||||
|
||||
mtimer.show_formspec.real_world_time_format = function (player_name)
|
||||
mtimer.show_formspec.real_time_universal(player_name, {
|
||||
time_type = 'real_time',
|
||||
formspec_name = 'mtimer:real_world_time_format',
|
||||
title = S('Real-World Time Format')
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
mtimer.show_formspec.session_start_time_format = function (player_name)
|
||||
mtimer.show_formspec.real_time_universal(player_name, {
|
||||
time_type = 'session_start_time',
|
||||
formspec_name = 'mtimer:session_start_time_format',
|
||||
title = S('Session Start Time Format')
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
mtimer.show_formspec.session_duration_format = function (player_name)
|
||||
local time_data = mtimer.get_times(player_name).session_duration
|
||||
|
||||
minetest.show_formspec(player_name, 'mtimer:session_duration_format',
|
||||
build_frame(7, 5, S('Session Duration Format'))..[[
|
||||
field_close_on_enter[format;false]
|
||||
field[0.25,0.75;7,1;format;;]]..time_data.format..[[]
|
||||
|
||||
container[0,1.425]
|
||||
|
||||
label[2.5,0;]]..S('Variable')..[[]
|
||||
label[4,0;]]..S('Current value')..[[]
|
||||
|
||||
box[0,0.45;6.75,0.02;#ffffff]
|
||||
|
||||
label[0,0.5;]]..S('Days')..[[]
|
||||
label[2.5,0.5;{days}]
|
||||
label[4,0.5;]]..time_data.days..[[]
|
||||
|
||||
label[0,0.9;]]..S('Hours')..[[]
|
||||
label[2.5,0.9;{hours}]
|
||||
label[4,0.9;]]..time_data.hours..[[]
|
||||
|
||||
label[0,1.3;]]..S('Minutes')..[[]
|
||||
label[2.5,1.3;{minutes}]
|
||||
label[4,1.3;]]..time_data.minutes..[[]
|
||||
|
||||
label[0,1.7;]]..S('Seconds')..[[]
|
||||
label[2.5,1.7;{seconds}]
|
||||
label[4,1.7;]]..time_data.seconds..[[]
|
||||
|
||||
box[0,2.2;6.75,0.02;#ffffff]
|
||||
|
||||
label[0,2.25;]]..S('Current Result')..[[]
|
||||
label[2.5,2.25;]]..time_data.formatted..[[]
|
||||
|
||||
container_end[]
|
||||
]])
|
||||
end
|
28
system/formspec/formspec_helpers.lua
Normal file
28
system/formspec/formspec_helpers.lua
Normal file
@ -0,0 +1,28 @@
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
|
||||
|
||||
mtimer.build_frame = function (width, height, title)
|
||||
local formspec_frame = [[
|
||||
size[+width,+height] label[0,-0.125;+title]
|
||||
container[0,+position]
|
||||
button_exit[+exitpos,0;+bwidth,1;exit;]]..S('Exit')..[[]
|
||||
button[+mainpos,0;+bwidth,1;main_menu;]]..S('Main Menu')..[[]
|
||||
button[+defaultpos,0;+bwidth,1;default;]]..S('Default')..[[]
|
||||
container_end[]
|
||||
]]
|
||||
|
||||
local width = width < 6 and 6 or width
|
||||
local height = height < 2 and 2 or height
|
||||
|
||||
return formspec_frame:gsub('%+%a+', {
|
||||
['+width'] = width,
|
||||
['+height'] = height,
|
||||
['+title'] = minetest.formspec_escape('[mTimer] '..title),
|
||||
['+position'] = height-0.7,
|
||||
['+bwidth'] = width/3,
|
||||
['+exitpos'] = 0,
|
||||
['+mainpos'] = width/3,
|
||||
['+defaultpos'] = (width/3)*2
|
||||
})
|
||||
end
|
82
system/formspec/real_time_universal.lua
Normal file
82
system/formspec/real_time_universal.lua
Normal file
@ -0,0 +1,82 @@
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
local build_frame = m.build_frame
|
||||
|
||||
|
||||
mtimer.show_formspec.real_time_universal = function (player_name, config)
|
||||
local time_data = mtimer.get_times(player_name)[config.time_type]
|
||||
|
||||
minetest.show_formspec(player_name, config.formspec_name,
|
||||
build_frame(7, 8.5, config.title)..[[
|
||||
field_close_on_enter[format;false]
|
||||
field[0.25,0.75;7,1;format;;]]..time_data.format..[[]
|
||||
container[0,1.425]
|
||||
|
||||
label[2.8,0;]]..S('Variable')..[[]
|
||||
label[4.6,0;]]..S('Current value')..[[]
|
||||
|
||||
box[0,0.45;6.75,0.02;#ffffff]
|
||||
|
||||
label[0,0.5;]]..S('Hours (24h)')..[[]
|
||||
label[2.8,0.5;{24h}]
|
||||
label[4.6,0.5;]]..time_data.variables.hours_24..[[]
|
||||
|
||||
label[0,0.9;]]..S('Hours (12h)')..[[]
|
||||
label[2.8,0.9;{12h}]
|
||||
label[4.6,0.9;]]..time_data.variables.hours_12..[[]
|
||||
|
||||
label[0,1.3;]]..S('Minutes')..[[]
|
||||
label[2.8,1.3;{min}]
|
||||
label[4.6,1.3;]]..time_data.variables.minutes..[[]
|
||||
|
||||
label[0,1.7;]]..S('Seconds')..[[]
|
||||
label[2.8,1.7;{sec}]
|
||||
label[4.6,1.7;]]..time_data.variables.seconds..[[]
|
||||
|
||||
box[0,2.18;6.75,0.02;#ffffff]
|
||||
|
||||
label[0,2.2;]]..S('Day Name')..[[]
|
||||
label[2.8,2.2;{dname}]
|
||||
label[4.6,2.2;]]..time_data.variables.dayname..[[]
|
||||
|
||||
label[0,2.6;]]..S('Month Name')..[[]
|
||||
label[2.8,2.6;{mname}]
|
||||
label[4.6,2.6;]]..time_data.variables.monthname..[[]
|
||||
|
||||
box[0,3.05;6.75,0.02;#ffffff]
|
||||
|
||||
label[0,3.1;]]..S('Year')..[[]
|
||||
label[2.8,3.1;{year}]
|
||||
label[4.6,3.1;]]..time_data.variables.year..[[]
|
||||
|
||||
label[0,3.5;]]..S('Month')..[[]
|
||||
label[2.8,3.5;{month}]
|
||||
label[4.6,3.5;]]..time_data.variables.month..[[]
|
||||
|
||||
label[0,3.9;]]..S('Day')..[[]
|
||||
label[2.8,3.9;{day}]
|
||||
label[4.6,3.9;]]..time_data.variables.day..[[]
|
||||
|
||||
box[0,4.4;6.75,0.02;#ffffff]
|
||||
|
||||
label[0,4.45;]]..S('ISO 8601 Date')..[[]
|
||||
label[2.8,4.45;{isodate}]
|
||||
label[4.6,4.45;]]..time_data.variables.iso8601_date..[[]
|
||||
|
||||
label[0,4.85;]]..S('ISO 8601 Time')..[[]
|
||||
label[2.8,4.85;{isotime}]
|
||||
label[4.6,4.85;]]..time_data.variables.iso8601_time..[[]
|
||||
|
||||
label[0,5.25;]]..S('Timestamp')..[[]
|
||||
label[2.8,5.25;{timestamp}]
|
||||
label[4.6,5.25;]]..time_data.variables.timestamp..[[]
|
||||
|
||||
box[0,5.75;6.75,0.02;#ffffff]
|
||||
|
||||
label[0,5.8;]]..S('Current Result')..[[]
|
||||
label[2.8,5.8;]]..time_data.formatted..[[]
|
||||
|
||||
container_end[]
|
||||
]])
|
||||
end
|
||||
|
@ -1,16 +1,89 @@
|
||||
local m = mtimer
|
||||
local S = m.translator
|
||||
|
||||
|
||||
local get_real_time = 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()
|
||||
|
||||
return {
|
||||
offset = _offset,
|
||||
server_timestamp = _server_timestamp,
|
||||
local_timestamp = _server_timestamp + ((_offset*60)*60)
|
||||
local get_date_names = function (dates)
|
||||
-- %w -> weekday [0-6 = Sunday-Saturday]
|
||||
local weekdays = {
|
||||
S('Sunday'), S('Monday'), S('Tuesday'), S('Wednesday'), S('Thursday'),
|
||||
S('Friday'), S('Saturday')
|
||||
}
|
||||
-- %m -> month [01-12 = January-December]
|
||||
local months = {
|
||||
S('January'), S('February'), S('March'), S('April'), S('May'),
|
||||
S('June'), S('July'), S('August'), S('September'), S('Oktober'),
|
||||
S('November'), S('December')
|
||||
}
|
||||
return {
|
||||
day = weekdays[tonumber(dates.day)],
|
||||
month = months[tonumber(dates.month)]
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
local get_real_time_universal = function (player_name, time_type)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local player_meta = player:get_meta()
|
||||
local m_meta = m.meta
|
||||
local timezone_offset = player_meta:get_string(m_meta.timezone_offset.key)
|
||||
local server_timestamp = ''
|
||||
local local_timestamp = ''
|
||||
local format = ''
|
||||
|
||||
if time_type == 'real' then
|
||||
server_timestamp = os.time()
|
||||
local_timestamp = server_timestamp + ((timezone_offset*60)*60)
|
||||
format = player_meta:get_string(m_meta.real_time.key)
|
||||
elseif time_type == 'session' then
|
||||
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)
|
||||
end
|
||||
|
||||
local date_names = get_date_names({
|
||||
day = os.date('!%w', local_timestamp),
|
||||
month = os.date('!%m', local_timestamp)
|
||||
})
|
||||
|
||||
local values = {
|
||||
times = {
|
||||
server_time = os.date('%Y-%m-%dT%T', server_timestamp),
|
||||
local_time = os.date('!%Y-%m-%dT%T', local_timestamp),
|
||||
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),
|
||||
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),
|
||||
timestamp = local_timestamp
|
||||
},
|
||||
format = format
|
||||
}
|
||||
|
||||
values['formatted'] = format:gsub('{[a-z0-9]+}', {
|
||||
['{24h}'] = values.variables.hours_24,
|
||||
['{12h}'] = values.variables.hours_12,
|
||||
['{min}'] = values.variables.minutes,
|
||||
['{sec}'] = values.variables.seconds,
|
||||
['{dname}'] = values.variables.dayname,
|
||||
['{mname}'] = values.variables.monthname,
|
||||
['{year}'] = values.variables.year,
|
||||
['{month}'] = values.variables.month,
|
||||
['{day}'] = values.variables.day,
|
||||
['{isodate}'] = values.variables.iso8601_date,
|
||||
['{isotime}'] = values.variables.iso8601_time,
|
||||
['{timestamp}'] = values.variables.timestamp
|
||||
})
|
||||
|
||||
return values
|
||||
end
|
||||
|
||||
|
||||
@ -18,7 +91,7 @@ local get_ingame_time = function (player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local format = player:get_meta():get_string(m.meta.ingame_time.key)
|
||||
local time_of_day = tostring((minetest.get_timeofday() * 24000) * 3.6)
|
||||
local ingame_timestamp = tonumber(string.format("%.0f", time_of_day))
|
||||
local ingame_timestamp = tonumber(string.format('%.0f', time_of_day))
|
||||
|
||||
local values = {
|
||||
hours_24 = os.date('!%H', ingame_timestamp),
|
||||
@ -39,9 +112,39 @@ local get_ingame_time = function (player_name)
|
||||
end
|
||||
|
||||
|
||||
local get_session_duration = function (player_name)
|
||||
local player = minetest.get_player_by_name(player_name)
|
||||
local player_meta = player:get_meta()
|
||||
local format = player_meta:get_string(m.meta.session_duration.key)
|
||||
local start_timestamp = player_meta:get_string('mtimer:session_start')
|
||||
local current_timestamp = os.time()
|
||||
local difference = current_timestamp - start_timestamp
|
||||
|
||||
local values = {
|
||||
format = format,
|
||||
difference = difference,
|
||||
days = string.format('%02d', math.floor(difference/86400)),
|
||||
hours = string.format('%02d', math.floor((difference % 86400)/3600)),
|
||||
minutes = string.format('%02d', math.floor((difference % 3600)/60)),
|
||||
seconds = string.format('%02d', math.floor((difference % 60)))
|
||||
}
|
||||
|
||||
values['formatted'] = format:gsub('{[a-z0-9]+}', {
|
||||
['{days}'] = values.days,
|
||||
['{hours}'] = values.hours,
|
||||
['{minutes}'] = values.minutes,
|
||||
['{seconds}'] = values.seconds
|
||||
})
|
||||
|
||||
return values
|
||||
end
|
||||
|
||||
|
||||
mtimer.get_times = function (player_name)
|
||||
return {
|
||||
real_time = get_real_time(player_name),
|
||||
session_start_time = get_real_time_universal(player_name, 'session'),
|
||||
session_duration = get_session_duration(player_name),
|
||||
real_time = get_real_time_universal(player_name, 'real'),
|
||||
ingame_time = get_ingame_time(player_name)
|
||||
}
|
||||
end
|
||||
|
@ -13,6 +13,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
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
|
||||
if fields.real_world_time_format then f.real_world_time_format(name) end
|
||||
if fields.session_start_time_format then
|
||||
f.session_start_time_format(name)
|
||||
end
|
||||
if fields.session_duration_format then
|
||||
f.session_duration_format(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -76,6 +83,41 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
|
||||
-- Set real-time format
|
||||
if formname == 'mtimer:real_world_time_format' then
|
||||
local attr = m.meta.real_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.real_world_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
|
||||
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.session_start_time_format(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Set session duration format
|
||||
if formname == 'mtimer:session_duration_format' then
|
||||
local attr = m.meta.session_duration
|
||||
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.session_duration_format(name)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Back to menu from all formspecs
|
||||
if fields.main_menu then f.main_menu(name) end
|
||||
|
Loading…
Reference in New Issue
Block a user