diff --git a/config/AcediaAliases_Entities.ini b/config/AcediaAliases_Entities.ini new file mode 100644 index 0000000..6a048b3 --- /dev/null +++ b/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" \ No newline at end of file diff --git a/sources/Aliases/AliasService.uc b/sources/Aliases/AliasService.uc index 537c46a..9617a21 100644 --- a/sources/Aliases/AliasService.uc +++ b/sources/Aliases/AliasService.uc @@ -40,6 +40,7 @@ var public config const float saveInterval; var public config const class weaponAliasesSource; var public config const class colorAliasesSource; var public config const class featureAliasesSource; +var public config const class entityAliasesSource; protected function OnLaunch() { @@ -134,4 +135,5 @@ defaultproperties weaponAliasesSource = class'WeaponAliasSource' colorAliasesSource = class'ColorAliasSource' featureAliasesSource = class'FeatureAliasSource' + entityAliasesSource = class'EntityAliasSource' } \ No newline at end of file diff --git a/sources/Aliases/AliasesAPI.uc b/sources/Aliases/AliasesAPI.uc index 2f5a641..8b63dd4 100644 --- a/sources/Aliases/AliasesAPI.uc +++ b/sources/Aliases/AliasesAPI.uc @@ -23,6 +23,7 @@ class AliasesAPI extends AcediaObject var private LoggerAPI.Definition noWeaponAliasSource, invalidWeaponAliasSource; var private LoggerAPI.Definition noColorAliasSource, invalidColorAliasSource; var private LoggerAPI.Definition noFeatureAliasSource, invalidFeatureAliasSource; +var private LoggerAPI.Definition noEntityAliasSource, invalidEntityAliasSource; /** * Provides an easier access to the instance of the `AliasSource` of @@ -133,6 +134,37 @@ public final function AliasSource GetFeatureSource() 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 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` * configured to store weapon aliases. Returns `none` on failure. @@ -232,12 +264,48 @@ public final function Text ResolveFeature( 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 { + // 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.") 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.") 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.") 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`.") } \ No newline at end of file diff --git a/sources/Aliases/BuiltInSources/EntityAliasSource.uc b/sources/Aliases/BuiltInSources/EntityAliasSource.uc new file mode 100644 index 0000000..5b6e368 --- /dev/null +++ b/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 . + */ +class EntityAliasSource extends AliasSource + config(AcediaAliases); + +defaultproperties +{ + aliasesClass = class'EntityAliases' +} \ No newline at end of file diff --git a/sources/Aliases/BuiltInSources/EntityAliases.uc b/sources/Aliases/BuiltInSources/EntityAliases.uc new file mode 100644 index 0000000..3b41559 --- /dev/null +++ b/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 . + */ +class EntityAliases extends Aliases + perObjectConfig + config(AcediaAliases_Entities); + +defaultproperties +{ + configName = "AcediaAliases_Entities" + sourceClass = class'EntityAliasSource' +} \ No newline at end of file diff --git a/sources/Manifest.uc b/sources/Manifest.uc index ec74b1b..4ac17f6 100644 --- a/sources/Manifest.uc +++ b/sources/Manifest.uc @@ -28,6 +28,7 @@ defaultproperties aliasSources(1) = class'WeaponAliasSource' aliasSources(2) = class'ColorAliasSource' aliasSources(3) = class'FeatureAliasSource' + aliasSources(4) = class'EntityAliasSource' testCases(0) = class'TEST_Base' testCases(1) = class'TEST_ActorService' testCases(2) = class'TEST_Boxes'