From d9104ada144376f43f2b88eb12c542bc56f3cc6e Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+Jnick-24@users.noreply.github.com> Date: Wed, 7 Feb 2024 17:39:48 -0600 Subject: [PATCH] hnngh --- .../StandardClasses/ChatCommand.cs | 21 +++++++++++++++++++ .../HeartModule/Utility/CommandHandler.cs | 12 +++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Definitions/StandardClasses/ChatCommand.cs diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Definitions/StandardClasses/ChatCommand.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Definitions/StandardClasses/ChatCommand.cs new file mode 100644 index 00000000..311a801e --- /dev/null +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Definitions/StandardClasses/ChatCommand.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Heart_Module.Data.Scripts.HeartModule.Definitions.StandardClasses +{ + [ProtoContract] + public class ChatCommand + { + public string modName; + public Action action; + + public ChatCommand(string modName, Action action) + { + this.modName = modName; + this.action = action; + } + } +} diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Utility/CommandHandler.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Utility/CommandHandler.cs index ad66e09a..c274e17b 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Utility/CommandHandler.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Utility/CommandHandler.cs @@ -1,5 +1,6 @@ using Heart_Module.Data.Scripts.HeartModule.ErrorHandler; using Heart_Module.Data.Scripts.HeartModule.Projectiles; +using RichHudFramework.Internal; using RichHudFramework.UI; using Sandbox.Game.GameSystems.Chat; using Sandbox.Game.Screens.Helpers.RadialMenuActions; @@ -76,11 +77,14 @@ private void Command_MessageEnteredSender(ulong sender, string messageText, ref sendToOthers = false; - string[] parts = messageText.Substring(4).ToLower().Split(' '); // Convert commands to be more parseable + string[] parts = messageText.Substring(4).Split(' '); // Convert commands to be more parseable // Really basic command handler - if (commands.ContainsKey(parts[0])) - commands[parts[0]].action.Invoke(parts); + if (commands.ContainsKey(parts[0].ToLower())) + commands[parts[0].ToLower()].action.Invoke(parts); + else + MyAPIGateway.Utilities.ShowMessage("[OCF]", $"Unrecognized command " + parts[0]); + } public void Close() @@ -106,7 +110,7 @@ public static void AddCommand(string command, string helpText, Action return; } - I.commands.Add(modName, new Command(modName, helpText, action)); + I.commands.Add(command, new Command(modName, helpText, action)); HeartData.I.Log.Log($"Registered new chat command \"/{command}\" from [{modName}]"); }