2019-02-16 16:45:32 +01:00
|
|
|
local m = mtimer
|
|
|
|
local S = m.translator
|
2019-03-06 18:22:50 +01:00
|
|
|
local d = m.dialog
|
2019-02-16 17:33:16 +01:00
|
|
|
local cs = minetest.chat_send_player
|
2021-02-12 20:23:40 +01:00
|
|
|
local ds = minetest.deserialize
|
2019-02-16 17:33:16 +01:00
|
|
|
|
|
|
|
|
2019-02-22 20:33:42 +01:00
|
|
|
-- Colorize a command sequence
|
|
|
|
--
|
|
|
|
-- This function returns a colorized chat command sequence with the given
|
|
|
|
-- parameter and the needed spacing
|
|
|
|
--
|
|
|
|
-- @param command The chat command paramter
|
|
|
|
-- @return table The colorized string
|
2019-02-16 17:33:16 +01:00
|
|
|
local command = function (command)
|
|
|
|
return minetest.colorize('cyan', '/mtimer '..command..' ')
|
|
|
|
end
|
2019-02-16 16:45:32 +01:00
|
|
|
|
2019-02-22 20:33:42 +01:00
|
|
|
|
2021-02-12 20:23:40 +01:00
|
|
|
local custom_timer_handling = function (name, action)
|
|
|
|
local player = minetest.get_player_by_name(name)
|
|
|
|
local player_meta = player:get_meta()
|
|
|
|
local current_timestamp = os.time(os.date('!*t'))
|
|
|
|
local ctv_key = m.meta.custom_timer_settings.key
|
|
|
|
local ctv = ds(player_meta:get_string(ctv_key))
|
|
|
|
|
|
|
|
if action == 'start' then
|
|
|
|
if ctv.running ~= true then
|
|
|
|
ctv.running = true
|
|
|
|
ctv.start_timestamp = current_timestamp
|
|
|
|
cs(name, S('The custom timer was started'))
|
|
|
|
else
|
|
|
|
cs(name, S('The custom timer is already running'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if action == 'stop' then
|
|
|
|
if ctv.running ~= false then
|
|
|
|
ctv.running = false
|
|
|
|
ctv.start_timestamp = 0
|
|
|
|
cs(name, S('The custom timer was stopped'))
|
|
|
|
else
|
|
|
|
cs(name, S('The custom timer is not running'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if action == 'restart' then
|
|
|
|
if ctv.running == true then
|
|
|
|
ctv.start_timestamp = current_timestamp
|
|
|
|
cs(name, S('The custom timer was restarted'))
|
|
|
|
else
|
|
|
|
cs(name, S('The custom timer is not running'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
player_meta:set_string(ctv_key, minetest.serialize(ctv))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2019-02-22 20:33:42 +01:00
|
|
|
-- Chat command
|
|
|
|
--
|
|
|
|
-- The `/mtimer` chat command opens the main menu and allows to directly open
|
|
|
|
-- the formspecs for the specific configuration. It can be run by all users.
|
|
|
|
--
|
|
|
|
-- The following parameters are supported.
|
|
|
|
--
|
|
|
|
-- Parameter Mnemonic Action
|
|
|
|
-- -------------------------------------------------------------------
|
2019-03-06 18:22:50 +01:00
|
|
|
-- vi visibility d.set_visibility(name)
|
|
|
|
-- po position d.set_position(name)
|
|
|
|
-- co color d.sec_color(name)
|
|
|
|
-- tz timezone d.timezone_offset(name)
|
|
|
|
-- in ingame d.ingame_time_format(name)
|
|
|
|
-- re real d.real_world_time_format(name)
|
2019-04-12 21:56:06 +02:00
|
|
|
-- ht host time d.host_time_format(name)
|
2019-03-06 18:22:50 +01:00
|
|
|
-- st start time d.session_start_time_format(name)
|
|
|
|
-- sd session duration d.session_duration_format(name)
|
2020-08-07 05:15:47 +02:00
|
|
|
-- hs HUD size d.hud_element_size(name)
|
2020-08-11 21:02:26 +02:00
|
|
|
-- os OffSet d.hud_element_offset(name)
|
2019-03-06 18:22:50 +01:00
|
|
|
-- tf timer format d.timer_format(name)
|
2021-02-10 21:21:24 +01:00
|
|
|
-- ct custom timer d.custom_timer(name)
|
2019-02-22 20:33:42 +01:00
|
|
|
-- -------------------------------------------------------------------
|
|
|
|
-- help Prints the help output showing the parameters
|
|
|
|
--
|
|
|
|
-- Providing unknown parameters has no effect.
|
2019-02-16 16:45:32 +01:00
|
|
|
minetest.register_chatcommand('mtimer', {
|
|
|
|
description = S('Configure timer display'),
|
2021-02-12 20:23:40 +01:00
|
|
|
params = '<vi/po/co/tz/in/re/ht/st/sd/hs/os/tf/ct/help>',
|
2019-02-16 16:45:32 +01:00
|
|
|
func = function(name, parameters)
|
|
|
|
local action = parameters:match('%a+')
|
2019-02-16 17:33:16 +01:00
|
|
|
|
|
|
|
if not minetest.get_player_by_name(name) then return end
|
2019-03-06 18:22:50 +01:00
|
|
|
if not action then d.main_menu(name) end
|
2019-02-16 17:33:16 +01:00
|
|
|
|
2019-03-06 18:22:50 +01:00
|
|
|
if action == 'vi' then d.set_visibility(name) end
|
|
|
|
if action == 'po' then d.set_position(name) end
|
|
|
|
if action == 'co' then d.set_color(name) end
|
|
|
|
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
|
2019-04-12 21:56:06 +02:00
|
|
|
if action == 'ht' then d.host_time_format(name) end
|
2019-03-06 18:22:50 +01:00
|
|
|
if action == 'st' then d.session_start_time_format(name) end
|
|
|
|
if action == 'sd' then d.session_duration_format(name) end
|
2020-08-07 05:15:47 +02:00
|
|
|
if action == 'hs' then d.hud_element_size(name) end
|
2020-08-11 21:02:26 +02:00
|
|
|
if action == 'os' then d.hud_element_offset(name) end
|
2019-03-06 18:22:50 +01:00
|
|
|
if action == 'tf' then d.timer_format(name) end
|
2021-02-10 21:21:24 +01:00
|
|
|
if action == 'ct' then d.custom_timer(name) end
|
2019-02-16 17:33:16 +01:00
|
|
|
|
2021-02-12 20:23:40 +01:00
|
|
|
if action == 'ctstart' then custom_timer_handling(name,'start') end
|
|
|
|
if action == 'ctstop' then custom_timer_handling(name,'stop') end
|
|
|
|
if action == 'ctrestart' then custom_timer_handling(name,'restart') end
|
|
|
|
|
2019-02-16 17:33:16 +01:00
|
|
|
if action == 'help' then
|
|
|
|
local message = {
|
2021-02-12 20:23:40 +01:00
|
|
|
command(' ')..S('Open Main Menu'),
|
2019-02-22 20:33:42 +01:00
|
|
|
command('vi')..S('Visibility'),
|
|
|
|
command('po')..S('Position'),
|
|
|
|
command('co')..S('Color'),
|
2019-02-16 17:33:16 +01:00
|
|
|
command('tz')..S('Timezone Offset'),
|
2019-02-21 16:16:10 +01:00
|
|
|
command('in')..S('Ingame Time Format'),
|
|
|
|
command('re')..S('Real-World Time Format'),
|
2019-04-12 21:56:06 +02:00
|
|
|
command('ht')..S('Host Time Format'),
|
2019-02-21 21:07:35 +01:00
|
|
|
command('st')..S('Session Start Time Format'),
|
|
|
|
command('sd')..S('Session Duration Format'),
|
2020-08-07 05:15:47 +02:00
|
|
|
command('hs')..S('HUD Element Size'),
|
2020-08-11 21:02:26 +02:00
|
|
|
command('os')..S('HUD Element Offset'),
|
2019-02-22 14:08:44 +01:00
|
|
|
command('tf')..S('Timer Format'),
|
2021-02-12 20:23:40 +01:00
|
|
|
'',
|
|
|
|
command('ct ')..S('Configure the custom timer'),
|
|
|
|
command('ctstart ')..S('Start the custom timer'),
|
|
|
|
command('ctstop ')..S('Stop stop custom timer'),
|
|
|
|
command('ctrestart')..S('Restart the custom timer')
|
2019-02-16 17:33:16 +01:00
|
|
|
}
|
|
|
|
cs(name, table.concat(message, '\n'))
|
|
|
|
end
|
2019-02-16 16:45:32 +01:00
|
|
|
end
|
|
|
|
})
|