From e2744cc6dd40654ff2f3aa560283010c937dd228 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sat, 15 Jan 2022 02:46:01 +0700 Subject: [PATCH] Add mutate input to `Commands` feature --- sources/Commands/Commands.uc | 12 ++++-- sources/Commands/Commands_Feature.uc | 60 ++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/sources/Commands/Commands.uc b/sources/Commands/Commands.uc index 45b2654..ba85ca0 100644 --- a/sources/Commands/Commands.uc +++ b/sources/Commands/Commands.uc @@ -22,29 +22,35 @@ class Commands extends FeatureConfig config(AcediaSystem); var public config bool useChatInput; +var public config bool useMutateInput; protected function AssociativeArray ToData() { local AssociativeArray data; data = __().collections.EmptyAssociativeArray(); data.SetBool(P("useChatInput"), useChatInput, true); + data.SetBool(P("useMutateInput"), useMutateInput, true); return data; } protected function FromData(AssociativeArray source) { - if (source != none) { - useChatInput = source.GetBool(P("useChatInput")); + if (source != none) + { + useChatInput = source.GetBool(P("useChatInput")); + useMutateInput = source.GetBool(P("useMutateInput")); } } protected function DefaultIt() { useChatInput = true; + useMutateInput = true; } defaultproperties { configName = "AcediaSystem" - useChatInput = true + useChatInput = true + useMutateInput = true } \ No newline at end of file diff --git a/sources/Commands/Commands_Feature.uc b/sources/Commands/Commands_Feature.uc index 665e044..d1e7d6a 100644 --- a/sources/Commands/Commands_Feature.uc +++ b/sources/Commands/Commands_Feature.uc @@ -31,6 +31,9 @@ var private AssociativeArray registeredCommands; // Setting this to `true` enables players to input commands right in the chat // by prepending them with "!" character. var private /*config*/ bool useChatInput; +// Setting this to `true` enables players to input commands with "mutate" +// console command. +var private /*config*/ bool useMutateInput; var LoggerAPI.Definition errCommandDuplicate; @@ -38,7 +41,6 @@ protected function OnEnabled() { registeredCommands = _.collections.EmptyAssociativeArray(); RegisterCommand(class'ACommandHelp'); - _.chat.OnMessage(self).connect = HandleCommands; // Macro selector commandDelimiters[0] = P("@"); // Key selector @@ -51,14 +53,21 @@ protected function OnEnabled() protected function OnDisabled() { - _.chat.OnMessage(self).Disconnect(); + if (useChatInput) { + _.chat.OnMessage(self).Disconnect(); + } + if (useMutateInput) { + _.unreal.mutator.OnMutate(self).Disconnect(); + } + useChatInput = false; + useMutateInput = false; if (registeredCommands != none) { registeredCommands.Empty(true); registeredCommands.FreeSelf(); registeredCommands = none; } - commandDelimiters.length = 0; + commandDelimiters.length = 0; } protected function SwapConfig(FeatureConfig config) @@ -68,17 +77,26 @@ protected function SwapConfig(FeatureConfig config) if (newConfig == none) { return; } - useChatInput = newConfig.useChatInput; -} - -/** - * Checks whether this feature uses in-game chat input for commands. - * - * @return `true` iff this feature uses in-game chat input for commands. - */ -public final function bool UsingChatInput() -{ - return useChatInput; + if (useChatInput != newConfig.useChatInput) + { + useChatInput = newConfig.useChatInput; + if (newConfig.useChatInput) { + _.chat.OnMessage(self).connect = HandleCommands; + } + else { + _.chat.OnMessage(self).Disconnect(); + } + } + if (useMutateInput != newConfig.useMutateInput) + { + useMutateInput = newConfig.useMutateInput; + if (newConfig.useMutateInput) { + _.unreal.mutator.OnMutate(self).connect = HandleMutate; + } + else { + _.unreal.mutator.OnMutate(self).Disconnect(); + } + } } /** @@ -227,9 +245,6 @@ private function bool HandleCommands( bool teamMessage) { local Parser parser; - if (!UsingChatInput()) { - return true; - } // We are only interested in messages that start with "!" parser = _.text.Parse(message); if (!parser.Match(P("!")).Ok()) @@ -243,6 +258,17 @@ private function bool HandleCommands( return false; } +private function HandleMutate(string command, PlayerController sendingPlayer) +{ + local Parser parser; + local EPlayer sender; + parser = _.text.ParseString(command); + sender = _.players.FromController(sendingPlayer); + HandleInput(parser, sender); + sender.FreeSelf(); + parser.FreeSelf(); +} + defaultproperties { configClass = class'Commands'