Browse Source

Add chat prefix config option to Commands feature

pull/8/head
Anton Tarasenko 3 years ago
parent
commit
0d285cb440
  1. 4
      sources/Commands/Command.uc
  2. 16
      sources/Commands/Commands.uc
  3. 15
      sources/Commands/Commands_Feature.uc

4
sources/Commands/Command.uc

@ -357,6 +357,10 @@ public final function bool Execute(CallData callData, EPlayer callerPlayer)
ReportError(callData, callerPlayer); ReportError(callData, callerPlayer);
return false; return false;
} }
callerPlayer.BorrowConsole()
.Write(P("Executing command `"))
.Write(commandData.name)
.Say(P("`"));
Executed(callData, callerPlayer); Executed(callData, callerPlayer);
if (commandData.requiresTarget) if (commandData.requiresTarget)
{ {

16
sources/Commands/Commands.uc

@ -23,6 +23,7 @@ class Commands extends FeatureConfig
var public config bool useChatInput; var public config bool useChatInput;
var public config bool useMutateInput; var public config bool useMutateInput;
var public config string chatCommandPrefix;
protected function AssociativeArray ToData() protected function AssociativeArray ToData()
{ {
@ -30,22 +31,32 @@ protected function AssociativeArray ToData()
data = __().collections.EmptyAssociativeArray(); data = __().collections.EmptyAssociativeArray();
data.SetBool(P("useChatInput"), useChatInput, true); data.SetBool(P("useChatInput"), useChatInput, true);
data.SetBool(P("useMutateInput"), useMutateInput, true); data.SetBool(P("useMutateInput"), useMutateInput, true);
data.SetItem( P("chatCommandPrefix"),
_.text.FromString(chatCommandPrefix), true);
return data; return data;
} }
protected function FromData(AssociativeArray source) protected function FromData(AssociativeArray source)
{ {
if (source != none) local Text newChatPrefix;
{ if (source == none) {
return;
}
useChatInput = source.GetBool(P("useChatInput")); useChatInput = source.GetBool(P("useChatInput"));
useMutateInput = source.GetBool(P("useMutateInput")); useMutateInput = source.GetBool(P("useMutateInput"));
newChatPrefix = source.GetText(P("chatCommandPrefix"));
chatCommandPrefix = "!";
if (newChatPrefix != none) {
chatCommandPrefix = newChatPrefix.ToString();
} }
_.memory.Free(newChatPrefix);
} }
protected function DefaultIt() protected function DefaultIt()
{ {
useChatInput = true; useChatInput = true;
useMutateInput = true; useMutateInput = true;
chatCommandPrefix = "!";
} }
defaultproperties defaultproperties
@ -53,4 +64,5 @@ defaultproperties
configName = "AcediaSystem" configName = "AcediaSystem"
useChatInput = true useChatInput = true
useMutateInput = true useMutateInput = true
chatCommandPrefix = "!"
} }

15
sources/Commands/Commands_Feature.uc

@ -29,11 +29,16 @@ var private array<Text> commandDelimiters;
var private AssociativeArray registeredCommands; 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 `chatCommandPrefix`.
// Default is `true`.
var private /*config*/ bool useChatInput; var private /*config*/ bool useChatInput;
// Setting this to `true` enables players to input commands with "mutate" // Setting this to `true` enables players to input commands with "mutate"
// console command. // console command.
// Default is `true`.
var private /*config*/ bool useMutateInput; var private /*config*/ bool useMutateInput;
// Chat messages, prepended by this prefix will be treated as commands.
// Default is "!". Empty values are also treated as "!".
var private /*config*/ Text chatCommandPrefix;
var LoggerAPI.Definition errCommandDuplicate; var LoggerAPI.Definition errCommandDuplicate;
@ -68,6 +73,8 @@ protected function OnDisabled()
registeredCommands = none; registeredCommands = none;
} }
commandDelimiters.length = 0; commandDelimiters.length = 0;
_.memory.Free(chatCommandPrefix);
chatCommandPrefix = none;
} }
protected function SwapConfig(FeatureConfig config) protected function SwapConfig(FeatureConfig config)
@ -77,6 +84,8 @@ protected function SwapConfig(FeatureConfig config)
if (newConfig == none) { if (newConfig == none) {
return; return;
} }
_.memory.Free(chatCommandPrefix);
chatCommandPrefix = _.text.FromString(newConfig.chatCommandPrefix);
if (useChatInput != newConfig.useChatInput) if (useChatInput != newConfig.useChatInput)
{ {
useChatInput = newConfig.useChatInput; useChatInput = newConfig.useChatInput;
@ -245,9 +254,9 @@ private function bool HandleCommands(
bool teamMessage) bool teamMessage)
{ {
local Parser parser; local Parser parser;
// We are only interested in messages that start with "!" // We are only interested in messages that start with `chatCommandPrefix`
parser = _.text.Parse(message); parser = _.text.Parse(message);
if (!parser.Match(P("!")).Ok()) if (!parser.Match(chatCommandPrefix).Ok())
{ {
parser.FreeSelf(); parser.FreeSelf();
return true; return true;

Loading…
Cancel
Save