diff --git a/config.lua b/config.lua index 2b9d8e9c..11e0f24d 100644 --- a/config.lua +++ b/config.lua @@ -44,6 +44,11 @@ global.config = { time_for_trust = 3 * 60 * 60 * 60, -- 3 hours everyone_is_regular = false }, + -- allows syncing player colors from and to the server. Disable this if you want to enforce custom colors + -- when enabled, /color will also be synced to the player settings + player_colors = { + enabled = true, + }, -- saves players' lives if they have a small-plane in their inventory, also adds the small-plane to the market and must therefor be loaded first train_saviour = { enabled = true diff --git a/control.lua b/control.lua index fbe70568..ff9222d5 100644 --- a/control.lua +++ b/control.lua @@ -27,7 +27,10 @@ require 'features.server_commands' require 'features.player_create' require 'features.rank_system' require 'features.redmew_settings_sync' -require 'features.player_colors' + +if config.player_colors.enabled then + require 'features.player_colors' +end -- Feature modules -- Each can be disabled safely diff --git a/features/player_colors.lua b/features/player_colors.lua index cb2aa749..951ce433 100644 --- a/features/player_colors.lua +++ b/features/player_colors.lua @@ -2,6 +2,7 @@ local Event = require 'utils.event' local Server = require 'features.server' local Token = require 'utils.token' local Settings = require 'utils.redmew_settings' +local Color = require 'resources.color_presets' local player_color_name = 'player-color' local player_chat_color_name = 'player-chat-color' @@ -69,7 +70,31 @@ local function player_joined_game(event) Server.try_get_data('colors', player.name, color_callback) end +local function on_command(event) + local player_index = event.player_index + if not player_index or event.command ~= 'color' then + return + end + + local player = game.get_player(player_index) + if not player or not player.valid then + return + end + + local color = event.parameters + local error = Settings.validate(player_color_name, color) + if error then + player.print(error, Color.fail) + return + end + + player.print({'player_colors.gui_setting_reference_message'}, Color.success) + Settings.set(player_index, player_color_name, color) + Settings.set(player_index, player_chat_color_name, color) +end + Event.add(defines.events.on_player_joined_game, player_joined_game) Event.add(Settings.events.on_setting_set, setting_set) +Event.add(defines.events.on_console_command, on_command) return Public diff --git a/locale/en/redmew_features.cfg b/locale/en/redmew_features.cfg index 6e5bd1a9..b88ffec5 100644 --- a/locale/en/redmew_features.cfg +++ b/locale/en/redmew_features.cfg @@ -82,6 +82,7 @@ color_random=Your color has been changed to: __1__ fail_wrong_argument=Only set, reset, and random are accepted arguments player_color_setting_label=Character color player_chat_color_setting_label=Chat color +gui_setting_reference_message=Color saved and synchronized to Redmew. You can also use the Redmew Settings (gear icon) to set the character and chat colors. [performance] fail_wrong_argument=Scale must be a valid number ranging from 0.05 to 1 diff --git a/resources/setting_types.lua b/resources/setting_types.lua index f76ff7e0..9a912e6f 100644 --- a/resources/setting_types.lua +++ b/resources/setting_types.lua @@ -112,8 +112,7 @@ return { if input_type == 'string' then local color = Color[input] - if color and tonumber(input) == nil then - -- we have some numeric keys in there + if color then return true, color end diff --git a/utils/command.lua b/utils/command.lua index ad056b9b..2d185690 100644 --- a/utils/command.lua +++ b/utils/command.lua @@ -30,7 +30,6 @@ local deprecated_command_alternatives = { local notify_on_commands = { ['version'] = 'RedMew has a version as well, accessible via /redmew-version', - ['color'] = 'You can also use the Redmew Settings (gear icon) to set the character and chat colors, this will be synchronized to all Redmew servers', ['ban'] = 'In case your forgot: please remember to include a message on how to appeal a ban' }