Browse Source

Add new alias source for commands' aliases

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
7cae407049
  1. 0
      config/AcediaAliases_Commands.ini
  2. 63
      sources/Aliases/AliasesAPI.uc
  3. 16
      sources/Aliases/Aliases_Feature.uc
  4. 26
      sources/Aliases/BuiltInSources/CommandAliasSource.uc
  5. 28
      sources/Aliases/BuiltInSources/CommandAliases.uc

0
config/AcediaAliases_Commands.ini

63
sources/Aliases/AliasesAPI.uc

@ -28,6 +28,7 @@ var private BaseAliasSource weaponAliasSource;
var private BaseAliasSource colorAliasSource;
var private BaseAliasSource featureAliasSource;
var private BaseAliasSource entityAliasSource;
var private BaseAliasSource commandAliasSource;
public function _reloadSources()
{
@ -37,10 +38,12 @@ public function _reloadSources()
_.memory.Free(colorAliasSource);
_.memory.Free(featureAliasSource);
_.memory.Free(entityAliasSource);
_.memory.Free(commandAliasSource);
weaponAliasSource = none;
colorAliasSource = none;
featureAliasSource = none;
entityAliasSource = none;
commandAliasSource = none;
feature = Aliases_Feature(
class'Aliases_Feature'.static.GetEnabledInstance());
if (feature == none) {
@ -50,6 +53,7 @@ public function _reloadSources()
colorAliasSource = feature.GetColorSource();
featureAliasSource = feature.GetFeatureSource();
entityAliasSource = feature.GetEntitySource();
commandAliasSource = feature.GetCommandSource();
_.memory.Free(feature);
}
@ -101,7 +105,6 @@ public final function BaseAliasSource GetWeaponSource()
* Returns `BaseAliasSource` that is designated in configuration files as
* a source for color aliases.
*
*
* @return Reference to the `BaseAliasSource` that contains color aliases.
* Can return `none` if no source for colors was configured or
* the configured source is incorrectly defined.
@ -118,7 +121,6 @@ public final function BaseAliasSource GetColorSource()
* Returns `BaseAliasSource` that is designated in configuration files as
* a source for feature aliases.
*
*
* @return Reference to the `BaseAliasSource` that contains feature aliases.
* Can return `none` if no source for features was configured or
* the configured source is incorrectly defined.
@ -135,7 +137,6 @@ public final function BaseAliasSource GetFeatureSource()
* Returns `BaseAliasSource` that is designated in configuration files as
* a source for entity aliases.
*
*
* @return Reference to the `BaseAliasSource` that contains entity aliases.
* Can return `none` if no source for entities was configured or
* the configured source is incorrectly defined.
@ -148,6 +149,25 @@ public final function BaseAliasSource GetEntitySource()
return entityAliasSource;
}
/**
* Returns `BaseAliasSource` that is designated in configuration files as
* a source for command aliases.
*
* Command aliases values can have the format of "<command>" or
* "<command> <sub-command>".
*
* @return Reference to the `BaseAliasSource` that contains command aliases.
* Can return `none` if no source for command was configured or
* the configured source is incorrectly defined.
*/
public final function BaseAliasSource GetCommandSource()
{
if (commandAliasSource != none) {
commandAliasSource.NewRef();
}
return commandAliasSource;
}
private final function Text ResolveWithSource(
BaseText alias,
BaseAliasSource source,
@ -311,6 +331,43 @@ public final function Text ResolveEntity(
return ResolveWithSource(alias, entityAliasSource, copyOnFailure);
}
/**
* Tries to look up a value stored for given alias in an `BaseAliasSource`
* configured to store command aliases.
*
* Command aliases values can have the format of "<command>" or
* "<command> <sub-command>".
*
* In Acedia aliases are typically prefixed with '$' to indicate that user
* means to enter alias. This method is able to handle both aliases with and
* without that prefix. This does not lead to conflicts, because '$' cannot
* be a valid part of any alias.
*
* Lookup of alias can fail if either alias does not exist in command alias
* source or command alias source itself does not exist
* (due to either faulty configuration or incorrect definition).
* To determine if command alias source exists you can check
* `_.alias.GetCommandSource()` value.
*
* @param alias Alias, for which method will attempt to
* look up a value. Case-insensitive.
* @param copyOnFailure Whether method should return copy of original
* `alias` value in case caller source did not have any records
* corresponding to `alias`. If `alias` was specified with '$' prefix -
* it will be discarded.
* @return If look up was successful - value, associated with the given
* alias `alias`. If lookup was unsuccessful, it depends on `copyOnFailure`
* flag: `copyOnFailure == false` means method will return `none`
* and `copyOnFailure == true` means method will return `alias.Copy()`.
* If `alias == none` method always returns `none`.
*/
public final function Text ResolveCommand(
BaseText alias,
optional bool copyOnFailure)
{
return ResolveWithSource(alias, commandAliasSource, copyOnFailure);
}
/**
* Tries to look up a value stored for given alias in a custom alias source
* with a given name `sourceName`.

16
sources/Aliases/Aliases_Feature.uc

@ -38,6 +38,7 @@ var private AliasSource weaponAliasSource;
var private AliasSource colorAliasSource;
var private AliasSource featureAliasSource;
var private AliasSource entityAliasSource;
var private AliasSource commandAliasSource;
// Everything else
var private HashTable customSources;
@ -65,6 +66,8 @@ private function DropSources()
featureAliasSource = none;
_.memory.Free(entityAliasSource);
entityAliasSource = none;
_.memory.Free(commandAliasSource);
commandAliasSource = none;
_.memory.Free(customSources);
customSources = none;
}
@ -210,6 +213,19 @@ public function AliasSource GetEntitySource()
return entityAliasSource;
}
/**
* Returns `AliasSource` for command aliases.
*
* @return `AliasSource`, configured to store command aliases.
*/
public function AliasSource GetCommandSource()
{
if (commandAliasSource != none) {
commandAliasSource.Newref();
}
return commandAliasSource;
}
/**
* Returns custom `AliasSource` with a given name.
*

26
sources/Aliases/BuiltInSources/CommandAliasSource.uc

@ -0,0 +1,26 @@
/**
* Source intended for command aliases.
* Copyright 2022 Anton Tarasenko
*------------------------------------------------------------------------------
* This file is part of Acedia.
*
* Acedia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License, or
* (at your option) any later version.
*
* Acedia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Acedia. If not, see <https://www.gnu.org/licenses/>.
*/
class ColorAliasSource extends AliasSource
config(AcediaAliases_Commands);
defaultproperties
{
aliasesClass = class'CommandAliases'
}

28
sources/Aliases/BuiltInSources/CommandAliases.uc

@ -0,0 +1,28 @@
/**
* Per-object-configuration intended for command aliases.
* Copyright 2022 Anton Tarasenko
*------------------------------------------------------------------------------
* This file is part of Acedia.
*
* Acedia is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License, or
* (at your option) any later version.
*
* Acedia is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Acedia. If not, see <https://www.gnu.org/licenses/>.
*/
class CommandAliases extends AliasesStorage
perObjectConfig
config(AcediaAliases_Commands);
defaultproperties
{
configName = "AcediaAliases_Commands"
sourceClass = class'CommandAliasSource'
}
Loading…
Cancel
Save