mtimer/system/chat_command.lua

77 lines
3.0 KiB
Lua
Raw Normal View History

2019-02-16 16:45:32 +01:00
local m = mtimer
local S = m.translator
local d = m.dialog
2019-02-16 17:33:16 +01:00
local cs = minetest.chat_send_player
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
-- 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
-- -------------------------------------------------------------------
-- 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)
-- st start time d.session_start_time_format(name)
-- sd session duration d.session_duration_format(name)
-- tf timer format d.timer_format(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'),
2019-02-22 14:08:44 +01:00
params = '<vi/po/co/tz/in/re/st/sd/tt/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
if not action then d.main_menu(name) end
2019-02-16 17:33:16 +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
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
2019-02-16 17:33:16 +01:00
if action == 'help' then
local message = {
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'),
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'),
2019-02-22 14:08:44 +01:00
command('tf')..S('Timer Format'),
2019-02-16 17:33:16 +01:00
command(' ')..S('Open Main Menu')
}
cs(name, table.concat(message, '\n'))
end
2019-02-16 16:45:32 +01:00
end
})