Browse Source

Add mutate input to `Commands` feature

pull/8/head
Anton Tarasenko 3 years ago
parent
commit
e2744cc6dd
  1. 12
      sources/Commands/Commands.uc
  2. 60
      sources/Commands/Commands_Feature.uc

12
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
}

60
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'

Loading…
Cancel
Save