Browse Source

Add mutate input to `Commands` feature

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

8
sources/Commands/Commands.uc

@ -22,29 +22,35 @@ class Commands extends FeatureConfig
config(AcediaSystem); config(AcediaSystem);
var public config bool useChatInput; var public config bool useChatInput;
var public config bool useMutateInput;
protected function AssociativeArray ToData() protected function AssociativeArray ToData()
{ {
local AssociativeArray data; local AssociativeArray data;
data = __().collections.EmptyAssociativeArray(); data = __().collections.EmptyAssociativeArray();
data.SetBool(P("useChatInput"), useChatInput, true); data.SetBool(P("useChatInput"), useChatInput, true);
data.SetBool(P("useMutateInput"), useMutateInput, true);
return data; return data;
} }
protected function FromData(AssociativeArray source) protected function FromData(AssociativeArray source)
{ {
if (source != none) { if (source != none)
{
useChatInput = source.GetBool(P("useChatInput")); useChatInput = source.GetBool(P("useChatInput"));
useMutateInput = source.GetBool(P("useMutateInput"));
} }
} }
protected function DefaultIt() protected function DefaultIt()
{ {
useChatInput = true; useChatInput = true;
useMutateInput = true;
} }
defaultproperties defaultproperties
{ {
configName = "AcediaSystem" configName = "AcediaSystem"
useChatInput = true useChatInput = true
useMutateInput = true
} }

54
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 // Setting this to `true` enables players to input commands right in the chat
// by prepending them with "!" character. // by prepending them with "!" character.
var private /*config*/ bool useChatInput; 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; var LoggerAPI.Definition errCommandDuplicate;
@ -38,7 +41,6 @@ protected function OnEnabled()
{ {
registeredCommands = _.collections.EmptyAssociativeArray(); registeredCommands = _.collections.EmptyAssociativeArray();
RegisterCommand(class'ACommandHelp'); RegisterCommand(class'ACommandHelp');
_.chat.OnMessage(self).connect = HandleCommands;
// Macro selector // Macro selector
commandDelimiters[0] = P("@"); commandDelimiters[0] = P("@");
// Key selector // Key selector
@ -51,7 +53,14 @@ protected function OnEnabled()
protected function OnDisabled() protected function OnDisabled()
{ {
if (useChatInput) {
_.chat.OnMessage(self).Disconnect(); _.chat.OnMessage(self).Disconnect();
}
if (useMutateInput) {
_.unreal.mutator.OnMutate(self).Disconnect();
}
useChatInput = false;
useMutateInput = false;
if (registeredCommands != none) if (registeredCommands != none)
{ {
registeredCommands.Empty(true); registeredCommands.Empty(true);
@ -68,17 +77,26 @@ protected function SwapConfig(FeatureConfig config)
if (newConfig == none) { if (newConfig == none) {
return; return;
} }
if (useChatInput != newConfig.useChatInput)
{
useChatInput = newConfig.useChatInput; useChatInput = newConfig.useChatInput;
} if (newConfig.useChatInput) {
_.chat.OnMessage(self).connect = HandleCommands;
/** }
* Checks whether this feature uses in-game chat input for commands. else {
* _.chat.OnMessage(self).Disconnect();
* @return `true` iff this feature uses in-game chat input for commands. }
*/ }
public final function bool UsingChatInput() if (useMutateInput != newConfig.useMutateInput)
{ {
return useChatInput; 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) bool teamMessage)
{ {
local Parser parser; local Parser parser;
if (!UsingChatInput()) {
return true;
}
// We are only interested in messages that start with "!" // We are only interested in messages that start with "!"
parser = _.text.Parse(message); parser = _.text.Parse(message);
if (!parser.Match(P("!")).Ok()) if (!parser.Match(P("!")).Ok())
@ -243,6 +258,17 @@ private function bool HandleCommands(
return false; 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 defaultproperties
{ {
configClass = class'Commands' configClass = class'Commands'

Loading…
Cancel
Save