From 17a2c5e88bfecf5ac57216f6fef681f68293af04 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Sat, 18 Jun 2022 01:13:19 +0700 Subject: [PATCH] Add Feature aliases --- config/AcediaAliases.ini | 117 ++++++++++++++++++ config/AcediaSystem.ini | 1 + sources/Aliases/AliasService.uc | 6 +- sources/Aliases/AliasesAPI.uc | 67 ++++++++++ .../BuiltInSources/FeatureAliasSource.uc | 26 ++++ .../Aliases/BuiltInSources/FeatureAliases.uc | 28 +++++ 6 files changed, 243 insertions(+), 2 deletions(-) create mode 100644 sources/Aliases/BuiltInSources/FeatureAliasSource.uc create mode 100644 sources/Aliases/BuiltInSources/FeatureAliases.uc diff --git a/config/AcediaAliases.ini b/config/AcediaAliases.ini index e69de29..32a300e 100644 --- a/config/AcediaAliases.ini +++ b/config/AcediaAliases.ini @@ -0,0 +1,117 @@ +[AcediaCore.FeatureAliasSource] +; Field Medic weapons +[AcediaCore:Commands_Feature FeatureAliases] +Alias="commands" +Alias="command" +Alias="comands" +Alias="comand" +Alias="cmds" +Alias="cmd" + +[AcediaFixes:FixAmmoSelling_Feature FeatureAliases] +Alias="FixAmmoSelling" +Alias="FixSelling" +Alias="FixAmmo" +Alias="AmmoSellingFix" +Alias="SellingFix" +Alias="AmmoFix" +Alias="FixAmmoSell" +Alias="FixSell" +Alias="AmmoSellFix" +Alias="SellFix" +Alias="FixAmmoPrinting" +Alias="FixPrinting" +Alias="AmmoPrintingFix" +Alias="PrintingFix" +Alias="FixAmmoPrint" +Alias="FixPrint" +Alias="AmmoPrintFix" +Alias="PrintFix" + +[AcediaFixes:FixDoshSpam_Feature FeatureAliases] +Alias="DoshSpamFix" +Alias="DoshFix" +Alias="CashSpamFix" +Alias="CashFix" +Alias="FixDoshSpamF" +Alias="FixDosh" +Alias="FixCashSpam" +Alias="FixCash" + +[AcediaFixes:FixDualiesCost_Feature FeatureAliases] +Alias="FixDualiesCost" +Alias="FixDualies" +Alias="DualiesCostFix" +Alias="DualiesFix" + +[AcediaFixes:FixFFHack_Feature FeatureAliases] +Alias="FixFFHack" +Alias="FixFriendlyFireHack" +Alias="FixFriendFireHack" +Alias="FixFFHack" +Alias="FFHackFix" +Alias="FriendlyFireHackFix" +Alias="FriendFireHackFix" +Alias="FFHackFix" + +[AcediaFixes:FixInfiniteNades_Feature FeatureAliases] +Alias="FixInfiniteNades" +Alias="FixInfiniteNade" +Alias="FixInfNades" +Alias="FixInfNade" +Alias="FixNades" +Alias="FixNade" +Alias="InfiniteNadesFix" +Alias="InfiniteNadeFix" +Alias="InfNadesFix" +Alias="InfNadeFix" +Alias="NadesFix" +Alias="NadeFix" + +[AcediaFixes:FixInventoryAbuse_Feature FeatureAliases] +Alias="FixInventoryAbuse" +Alias="FixInventory" +Alias="InventoryAbuseFix" +Alias="InventoryFix" + +[AcediaFixes:FixLogSpam_Feature FeatureAliases] +Alias="FixLogSpam" +Alias="FixLog" +Alias="LogSpamFix" +Alias="LogFix" + +[AcediaFixes:FixPipes_Feature FeatureAliases] +Alias="FixPipes" +Alias="FixPipe" +Alias="PipesFix" +Alias="PipeFix" + +[AcediaFixes:FixProjectileFF_Feature FeatureAliases] +Alias="FixProjectileFriendlyFire" +Alias="FixProjectileFF" +Alias="FixProjFriendlyFire" +Alias="FixProjFF" +Alias="FixFriendlyFire" +Alias="FixFF" +Alias="ProjectileFriendlyFireFix" +Alias="ProjectileFFFix" +Alias="ProjFriendlyFireFix" +Alias="ProjFFFix" +Alias="FriendlyFireFix" +Alias="FFFix" + +[AcediaFixes:FixSpectatorCrash_Feature FeatureAliases] +Alias="FixSpectatorCrash" +Alias="FixSpecCrash" +Alias="SpectatorCrashFix" +Alias="SpecCrashFix" + +[AcediaFixes:FixZedTimeLags_Feature FeatureAliases] +Alias="FixZedTimeLags" +Alias="FixZedTime" +Alias="FixZTLags" +Alias="FixZT" +Alias="ZedTimeLagsFix" +Alias="ZedTimeFix" +Alias="ZTLagsFix" +Alias="ZTFix" \ No newline at end of file diff --git a/config/AcediaSystem.ini b/config/AcediaSystem.ini index 5cdb002..14773ce 100644 --- a/config/AcediaSystem.ini +++ b/config/AcediaSystem.ini @@ -56,6 +56,7 @@ autoEnable=true ; looks for weapon and color aliases. weaponAliasesSource=Class'WeaponAliasSource' colorAliasesSource=Class'ColorAliasSource' +featureAliasesSource=Class'FeatureAliasSource' ; How often are different alias-storing objects are allowed to record ; their updated data into a config. ; Negative or zero values would be reset to `0.05`. diff --git a/sources/Aliases/AliasService.uc b/sources/Aliases/AliasService.uc index ac9cd94..537c46a 100644 --- a/sources/Aliases/AliasService.uc +++ b/sources/Aliases/AliasService.uc @@ -39,6 +39,7 @@ var public config const float saveInterval; // looks for weapon and color aliases. var public config const class weaponAliasesSource; var public config const class colorAliasesSource; +var public config const class featureAliasesSource; protected function OnLaunch() { @@ -130,6 +131,7 @@ event Timer() defaultproperties { saveInterval = 0.05 - weaponAliasesSource = class'WeaponAliasSource' - colorAliasesSource = class'ColorAliasSource' + weaponAliasesSource = class'WeaponAliasSource' + colorAliasesSource = class'ColorAliasSource' + featureAliasesSource = class'FeatureAliasSource' } \ No newline at end of file diff --git a/sources/Aliases/AliasesAPI.uc b/sources/Aliases/AliasesAPI.uc index e43468d..97bb59c 100644 --- a/sources/Aliases/AliasesAPI.uc +++ b/sources/Aliases/AliasesAPI.uc @@ -22,6 +22,7 @@ class AliasesAPI extends AcediaObject var private LoggerAPI.Definition noWeaponAliasSource, invalidWeaponAliasSource; var private LoggerAPI.Definition noColorAliasSource, invalidColorAliasSource; +var private LoggerAPI.Definition noFeatureAliasSource, invalidFeatureAliasSource; /** * Provides an easier access to the instance of the `AliasSource` of @@ -101,6 +102,37 @@ public final function AliasSource GetColorSource() return colorSource; } +/** + * Returns `AliasSource` that is designated in configuration files as + * a source for feature aliases. + * + * NOTE: while by default feature aliases source will contain only feature + * 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 feature aliases. + * Can return `none` if no source for features was configured or + * the configured source is incorrectly defined. + */ +public final function AliasSource GetFeatureSource() +{ + local AliasSource colorSource; + local class sourceClass; + sourceClass = class'AliasService'.default.colorAliasesSource; + if (sourceClass == none) + { + _.logger.Auto(noColorAliasSource); + return none; + } + colorSource = AliasSource(sourceClass.static.GetInstance(true)); + if (colorSource == none) + { + _.logger.Auto(invalidColorAliasSource).ArgClass(sourceClass); + return none; + } + return colorSource; +} + /** * Tries to look up a value stored for given alias in an `AliasSource` * configured to store weapon aliases. Returns `none` on failure. @@ -165,10 +197,45 @@ public final function Text ResolveColor(Text alias, optional bool copyOnFailure) return none; } +/** + * Tries to look up a value stored for given alias in an `AliasSource` + * configured to store feature aliases. Reports error on failure. + * + * Lookup of alias can fail if either alias does not exist in feature alias + * source or feature alias source itself does not exist + * (due to either faulty configuration or incorrect definition). + * To determine if feature alias source exists you can check + * `_.alias.GetFeatureSource()` 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 ResolveFeature( + Text alias, + optional bool copyOnFailure) +{ + local AliasSource source; + source = GetFeatureSource(); + if (source != none) { + return source.Resolve(alias, copyOnFailure); + } + return none; +} + defaultproperties { 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`.") } \ No newline at end of file diff --git a/sources/Aliases/BuiltInSources/FeatureAliasSource.uc b/sources/Aliases/BuiltInSources/FeatureAliasSource.uc new file mode 100644 index 0000000..9167b6d --- /dev/null +++ b/sources/Aliases/BuiltInSources/FeatureAliasSource.uc @@ -0,0 +1,26 @@ +/** + * Source intended for feature 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 FeatureAliasSource extends AliasSource + config(AcediaAliases); + +defaultproperties +{ + aliasesClass = class'FeatureAliases' +} \ No newline at end of file diff --git a/sources/Aliases/BuiltInSources/FeatureAliases.uc b/sources/Aliases/BuiltInSources/FeatureAliases.uc new file mode 100644 index 0000000..7acc0b6 --- /dev/null +++ b/sources/Aliases/BuiltInSources/FeatureAliases.uc @@ -0,0 +1,28 @@ +/** + * Per-object-configuration intended for feature 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 FeatureAliases extends Aliases + perObjectConfig + config(AcediaAliases); + +defaultproperties +{ + configName = "AcediaAliases" + sourceClass = class'FeatureAliasSource' +} \ No newline at end of file