Browse Source

Add entity aliases

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
06701efff5
  1. 85
      config/AcediaAliases_Entities.ini
  2. 2
      sources/Aliases/AliasService.uc
  3. 68
      sources/Aliases/AliasesAPI.uc
  4. 26
      sources/Aliases/BuiltInSources/EntityAliasSource.uc
  5. 28
      sources/Aliases/BuiltInSources/EntityAliases.uc
  6. 1
      sources/Manifest.uc

85
config/AcediaAliases_Entities.ini

@ -0,0 +1,85 @@
[AcediaCore.EntityAliasSource]
; Standard zeds
[KFChar:ZombieClot_STANDARD EntityAliases]
Alias="clot"
Alias="zombie"
Alias="pawn"
Alias="trash"
Alias="ct"
[KFChar:ZombieCrawler_STANDARD EntityAliases]
Alias="crawler"
Alias="cravler"
Alias="spider"
Alias="spiderman"
Alias="arachnid"
Alias="cr"
[KFChar:ZombieStalker_STANDARD EntityAliases]
Alias="stalker"
Alias="invis"
Alias="invisible"
Alias="st"
[KFChar:ZombieGorefast_STANDARD EntityAliases]
Alias="gorefast"
Alias="red"
Alias="blade"
Alias="gore"
Alias="gr"
[KFChar:ZombieBloat_STANDARD EntityAliases]
Alias="bloat"
Alias="bt"
Alias="vomit"
Alias="fat"
[KFChar:ZombieSiren_STANDARD EntityAliases]
Alias="siren"
Alias="sn"
Alias="witch"
Alias="screaming"
Alias="scream"
Alias="loud"
[KFChar:ZombieHusk_STANDARD EntityAliases]
Alias="husk"
Alias="hsk"
Alias="flamer"
Alias="flame"
Alias="fire"
Alias="ranged"
Alias="shooter"
Alias="shoot"
[KFChar:ZombieScrake_STANDARD EntityAliases]
Alias="scrake"
Alias="scrak"
Alias="sc"
Alias="chainsaw"
Alias="chain"
Alias="saw"
Alias="bald"
Alias="mask"
Alias="doctor"
[KFChar:ZombieFleshpound_STANDARD EntityAliases]
Alias="fleshpound"
Alias="fleshpond"
Alias="flesh"
Alias="flashpound"
Alias="flashpoud"
Alias="flash"
Alias="pound"
Alias="poud"
Alias="fp"
Alias="big"
Alias="lamp"
[KFChar:ZombieBoss_STANDARD EntityAliases]
Alias="patriarch"
Alias="patty"
Alias="pat"
Alias="boss"
Alias="finalboss"
Alias="daddy"
Alias="leader"
Alias="bos"
Alias="KevinClamely"
Alias="Kevin"
Alias="Clamely"
Alias="KevinClam"
Alias="Clame"
Alias="Kev"
Alias="Kevster"

2
sources/Aliases/AliasService.uc

@ -40,6 +40,7 @@ var public config const float saveInterval;
var public config const class<AliasSource> weaponAliasesSource; var public config const class<AliasSource> weaponAliasesSource;
var public config const class<AliasSource> colorAliasesSource; var public config const class<AliasSource> colorAliasesSource;
var public config const class<AliasSource> featureAliasesSource; var public config const class<AliasSource> featureAliasesSource;
var public config const class<AliasSource> entityAliasesSource;
protected function OnLaunch() protected function OnLaunch()
{ {
@ -134,4 +135,5 @@ defaultproperties
weaponAliasesSource = class'WeaponAliasSource' weaponAliasesSource = class'WeaponAliasSource'
colorAliasesSource = class'ColorAliasSource' colorAliasesSource = class'ColorAliasSource'
featureAliasesSource = class'FeatureAliasSource' featureAliasesSource = class'FeatureAliasSource'
entityAliasesSource = class'EntityAliasSource'
} }

68
sources/Aliases/AliasesAPI.uc

@ -23,6 +23,7 @@ class AliasesAPI extends AcediaObject
var private LoggerAPI.Definition noWeaponAliasSource, invalidWeaponAliasSource; var private LoggerAPI.Definition noWeaponAliasSource, invalidWeaponAliasSource;
var private LoggerAPI.Definition noColorAliasSource, invalidColorAliasSource; var private LoggerAPI.Definition noColorAliasSource, invalidColorAliasSource;
var private LoggerAPI.Definition noFeatureAliasSource, invalidFeatureAliasSource; var private LoggerAPI.Definition noFeatureAliasSource, invalidFeatureAliasSource;
var private LoggerAPI.Definition noEntityAliasSource, invalidEntityAliasSource;
/** /**
* Provides an easier access to the instance of the `AliasSource` of * Provides an easier access to the instance of the `AliasSource` of
@ -133,6 +134,37 @@ public final function AliasSource GetFeatureSource()
return featureSource; return featureSource;
} }
/**
* Returns `AliasSource` that is designated in configuration files as
* a source for entity aliases.
*
* NOTE: while by default entity aliases source will contain only entity
* aliases, you should not assume that. Acedia allows admins to store all the
* aliases in the same config.
*
* @return Reference to the `AliasSource` that contains entity aliases.
* Can return `none` if no source for entities was configured or
* the configured source is incorrectly defined.
*/
public final function AliasSource GetEntitySource()
{
local AliasSource entitySource;
local class<AliasSource> sourceClass;
sourceClass = class'AliasService'.default.entityAliasesSource;
if (sourceClass == none)
{
_.logger.Auto(noEntityAliasSource);
return none;
}
entitySource = AliasSource(sourceClass.static.GetInstance(true));
if (entitySource == none)
{
_.logger.Auto(invalidEntityAliasSource).ArgClass(sourceClass);
return none;
}
return entitySource;
}
/** /**
* Tries to look up a value stored for given alias in an `AliasSource` * Tries to look up a value stored for given alias in an `AliasSource`
* configured to store weapon aliases. Returns `none` on failure. * configured to store weapon aliases. Returns `none` on failure.
@ -232,12 +264,48 @@ public final function Text ResolveFeature(
return none; return none;
} }
/**
* Tries to look up a value stored for given alias in an `AliasSource`
* configured to store entity aliases. Reports error on failure.
*
* Lookup of alias can fail if either alias does not exist in entity alias
* source or entity alias source itself does not exist
* (due to either faulty configuration or incorrect definition).
* To determine if entity alias source exists you can check
* `_.alias.GetEntitySource()` 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`.
* @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 ResolveEntity(
BaseText alias,
optional bool copyOnFailure)
{
local AliasSource source;
source = GetEntitySource();
if (source != none) {
return source.Resolve(alias, copyOnFailure);
}
return none;
}
defaultproperties defaultproperties
{ {
// TODO: all this shit below can be done as two messages
noWeaponAliasSource = (l=LOG_Error,m="No weapon aliases source configured for Acedia's alias API. Error is most likely cause by erroneous config.") noWeaponAliasSource = (l=LOG_Error,m="No weapon aliases source configured for Acedia's alias API. Error is most likely cause by erroneous config.")
invalidWeaponAliasSource = (l=LOG_Error,m="`AliasSource` class `%1` is configured to store weapon aliases, but it seems to be invalid. This is a bug and not configuration file problem, but issue might be avoided by using a different `AliasSource`.") invalidWeaponAliasSource = (l=LOG_Error,m="`AliasSource` class `%1` is configured to store weapon aliases, but it seems to be invalid. This is a bug and not configuration file problem, but issue might be avoided by using a different `AliasSource`.")
noColorAliasSource = (l=LOG_Error,m="No color aliases source configured for Acedia's alias API. Error is most likely cause by erroneous config.") noColorAliasSource = (l=LOG_Error,m="No color aliases source configured for Acedia's alias API. Error is most likely cause by erroneous config.")
invalidColorAliasSource = (l=LOG_Error,m="`AliasSource` class `%1` is configured to store color aliases, but it seems to be invalid. This is a bug and not configuration file problem, but issue might be avoided by using a different `AliasSource`.") invalidColorAliasSource = (l=LOG_Error,m="`AliasSource` class `%1` is configured to store color aliases, but it seems to be invalid. This is a bug and not configuration file problem, but issue might be avoided by using a different `AliasSource`.")
noFeatureAliasSource = (l=LOG_Error,m="No feature aliases source configured for Acedia's alias API. Error is most likely cause by erroneous config.") noFeatureAliasSource = (l=LOG_Error,m="No feature aliases source configured for Acedia's alias API. Error is most likely cause by erroneous config.")
invalidFeatureAliasSource = (l=LOG_Error,m="`AliasSource` class `%1` is configured to store feature aliases, but it seems to be invalid. This is a bug and not configuration file problem, but issue might be avoided by using a different `AliasSource`.") invalidFeatureAliasSource = (l=LOG_Error,m="`AliasSource` class `%1` is configured to store feature aliases, but it seems to be invalid. This is a bug and not configuration file problem, but issue might be avoided by using a different `AliasSource`.")
noEntityAliasSource = (l=LOG_Error,m="No entity aliases source configured for Acedia's alias API. Error is most likely cause by erroneous config.")
invalidEntityAliasSource = (l=LOG_Error,m="`AliasSource` class `%1` is configured to store entity aliases, but it seems to be invalid. This is a bug and not configuration file problem, but issue might be avoided by using a different `AliasSource`.")
} }

26
sources/Aliases/BuiltInSources/EntityAliasSource.uc

@ -0,0 +1,26 @@
/**
* Source intended for entity 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 EntityAliasSource extends AliasSource
config(AcediaAliases);
defaultproperties
{
aliasesClass = class'EntityAliases'
}

28
sources/Aliases/BuiltInSources/EntityAliases.uc

@ -0,0 +1,28 @@
/**
* Per-object-configuration intended for entity 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 EntityAliases extends Aliases
perObjectConfig
config(AcediaAliases_Entities);
defaultproperties
{
configName = "AcediaAliases_Entities"
sourceClass = class'EntityAliasSource'
}

1
sources/Manifest.uc

@ -28,6 +28,7 @@ defaultproperties
aliasSources(1) = class'WeaponAliasSource' aliasSources(1) = class'WeaponAliasSource'
aliasSources(2) = class'ColorAliasSource' aliasSources(2) = class'ColorAliasSource'
aliasSources(3) = class'FeatureAliasSource' aliasSources(3) = class'FeatureAliasSource'
aliasSources(4) = class'EntityAliasSource'
testCases(0) = class'TEST_Base' testCases(0) = class'TEST_Base'
testCases(1) = class'TEST_ActorService' testCases(1) = class'TEST_ActorService'
testCases(2) = class'TEST_Boxes' testCases(2) = class'TEST_Boxes'

Loading…
Cancel
Save