From 52a062299509ae3c483e2201afebf088c1540c89 Mon Sep 17 00:00:00 2001 From: Matthew Heguy Date: Tue, 12 Feb 2019 20:20:35 -0500 Subject: [PATCH] Use locale for new rank system --- features/admin_commands.lua | 15 ++++++++++----- features/rank_system.lua | 7 +++---- features/redmew_commands.lua | 2 +- locale/en/redmew.cfg | 17 +++++++++++++++++ utils/core.lua | 6 +++--- utils/game.lua | 2 +- 6 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 locale/en/redmew.cfg diff --git a/features/admin_commands.lua b/features/admin_commands.lua index 50ccebf5..a41ff6ac 100644 --- a/features/admin_commands.lua +++ b/features/admin_commands.lua @@ -84,21 +84,26 @@ local function regular(args) if add_remove == 'add' then if Rank.less_than(name, Ranks.guest) then - Game.player_print('Cannot promote someone on probation to regular. Instead remove their probation and then promote them.', Color.red) + -- Cannot promote someone on probation to regular. You must remove them from probation and then promote them. + Game.player_print({'admin_commands.regular_add_fail_probation'}, Color.red) end local success, rank = Rank.increase_player_rank_to(name, Ranks.regular) if success then - game.print(format('%s promoted %s to %s.', Utils.get_actor(), name, rank), Color.yellow) + -- __1__ promoted __2__ to __3__. + game.print({'admin_commands.regular_add_success', Utils.get_actor(), name, rank}, Color.yellow) else - Game.player_print(format('%s is already rank %s.', name, rank), Color.red) + -- __1__ is already rank __2__. + Game.player_print({'admin_commands.regular_add_fail', name, rank}, Color.red) end elseif add_remove == 'remove' then if Rank.equal(name, Ranks.regular) then local new_rank = Rank.decrease_player_rank(name) - game.print(format('%s demoted %s to %s.', Utils.get_actor(), name, new_rank), Color.yellow) + -- __1__ demoted __2__ to __3__. + game.print({'admin_commands.regular_remove_success', Utils.get_actor(), name, new_rank}, Color.yellow) else local rank_name = Rank.get_player_rank_name(name) - Game.player_print(format('%s is rank %s, their regular status cannot be removed.', name, rank_name), Color.red) + -- __1__ is rank __2__ their regular status cannot be removed. + Game.player_print({'admin_commands.regular_remove_fail', name, rank_name}, Color.red) end end end diff --git a/features/rank_system.lua b/features/rank_system.lua index a3f9c1c8..e2da0d5b 100644 --- a/features/rank_system.lua +++ b/features/rank_system.lua @@ -31,9 +31,8 @@ local sorted_ranks = {} local rank_to_index = {} for k, v in pairs(Ranks) do - rank_name_lookup[v] = k + rank_name_lookup[v] = {'ranks.' .. k} end - for k, v in pairs(Ranks) do sorted_ranks[#sorted_ranks + 1] = v end @@ -258,7 +257,7 @@ function Public.increase_player_rank(player_name) local new_rank_name = rank_name_lookup[new_rank] if new_rank_name then - player_ranks[player_name] = (new_rank) + player_ranks[player_name] = new_rank return new_rank_name else return nil @@ -291,7 +290,7 @@ function Public.decrease_player_rank(player_name) local new_rank_name = rank_name_lookup[new_rank] if new_rank_name then - player_ranks[player_name] = (new_rank) + player_ranks[player_name] = new_rank return new_rank_name else return nil diff --git a/features/redmew_commands.lua b/features/redmew_commands.lua index 63b18d0f..fc1419c1 100644 --- a/features/redmew_commands.lua +++ b/features/redmew_commands.lua @@ -242,7 +242,7 @@ local function print_player_info(args, player) 'Name: ' .. name, target.connected and 'Online: yes' or 'Online: no', 'Index: ' .. target.index, - 'Rank: ' .. Rank.get_player_rank_name(name), + --'Rank: ' .. Rank.get_player_rank_name(name), Donator.is_donator(target.name) and 'Donator: yes' or 'Donator: no', 'Time played: ' .. Utils.format_time(target.online_time), 'AFK time: ' .. Utils.format_time(target.afk_time or 0), diff --git a/locale/en/redmew.cfg b/locale/en/redmew.cfg new file mode 100644 index 00000000..cbb42a58 --- /dev/null +++ b/locale/en/redmew.cfg @@ -0,0 +1,17 @@ +[ranks] +probation=Probation +guest=Guest +auto_trusted=Auto Trusted +regular=Regular +admin=Admin +donator=Donator +donator_abbreviation=D + +[admin_commands] +regular_add_success=__1__ promoted __2__ to __3__. +regular_add_fail=__1__ is already rank __2__. +regular_add_fail_probation=Cannot promote someone on probation to regular. You must remove them from probation and then promote them. +regular_remove_success=__1__ demoted __2__ to __3__. +regular_remove_fail=__1__ is rank __2__ their regular status cannot be removed. + +[redmew_commands] diff --git a/utils/core.lua b/utils/core.lua index 7fc2928e..c43937fb 100644 --- a/utils/core.lua +++ b/utils/core.lua @@ -32,7 +32,7 @@ function Module.distance(pos1, pos2) end --- Takes msg and prints it to all players except provided player --- @param msg The message to print +-- @param msg table if locale is used -- @param player the player not to send the message to -- @param color the color to use for the message, defaults to white function Module.print_except(msg, player, color) @@ -48,8 +48,8 @@ function Module.print_except(msg, player, color) end --- Prints a message to all online admins ---@param msg The message to print ---@param source string must be the name of a player, nil for server. +-- @param msg table if locale is used +-- @param source string must be the name of a player, nil for server. function Module.print_admins(msg, source) local source_name local chat_color diff --git a/utils/game.lua b/utils/game.lua index 99f16dfe..7a151c17 100644 --- a/utils/game.lua +++ b/utils/game.lua @@ -64,7 +64,7 @@ function Game.get_player_from_any(obj) end --- Prints to player or console. --- @param str +-- @param str table if locale is used -- @param color
defaults to white function Game.player_print(str, color) color = color or Color.white