Browse Source

Add aliases functionality

Add aliases functionality to acedia.
Aliases allow to add "synonyms" to class names or other text values.
develop
Anton Tarasenko 5 years ago
parent
commit
c690572663
  1. 569
      config/AcediaAliases.ini
  2. 140
      sources/Core/Aliases/Aliases.uc
  3. 43
      sources/Core/Aliases/AliasesAPI.uc
  4. 53
      sources/Core/Aliases/Tests/TEST_Aliases.uc
  5. 6
      sources/Global.uc
  6. 1
      sources/Manifest.uc

569
config/AcediaAliases.ini

@ -0,0 +1,569 @@
; Field Medic weapons
[weapon/KFMod:MP7MMedicGun Aliases]
Alias="MP7M"
Alias="MP7"
[weapon/KFMod:MP5MMedicGun Aliases]
Alias="MP5M"
Alias="MP5"
Alias="MP"
Alias="M5"
[weapon/KFMod:CamoMP5MMedicGun Aliases]
Alias="CamoMP5M"
Alias="CamoMP5"
Alias="CamoMP"
Alias="CamoM5"
[weapon/KFMod:M7A3MMedicGun Aliases]
Alias="M7A3"
Alias="M7A"
Alias="M7"
[weapon/KFMod:KrissMMedicGun Aliases]
Alias="Schneidzekk"
Alias="Schneidzek"
Alias="Kriss"
Alias="Kris"
[weapon/KFMod:NeonKrissMMedicGun Aliases]
Alias="NeonSchneidzekk"
Alias="NeonSchneidzek"
Alias="NeonKriss"
Alias="NeonKris"
[weapon/KFMod:BlowerThrower Aliases]
Alias="BlowerThrower"
Alias="Blower"
Alias="Thrower"
Alias="BThrower"
Alias="PoopGun"
Alias="BileGun"
Alias="BloatGun"
; Support Specialist weapons
[weapon/KFMod:Shotgun Aliases]
Alias="Shotgun"
[weapon/KFMod:CamoShotgun Aliases]
Alias="CamoShotgun"
[weapon/KFMod:BoomStick Aliases]
Alias="HuntingShotgun"
Alias="BoomStick"
Alias="Hunting"
[weapon/KFMod:KSGShotgun Aliases]
Alias="HSG-1Shotgun"
Alias="HSG1Shotgun"
Alias="HSGShotgun"
Alias="HSG"
Alias="KSG-1Shotgun"
Alias="KSG1Shotgun"
Alias="KSGShotgun"
Alias="KSG"
[weapon/KFMod:NeonKSGShotgun Aliases]
Alias="NeonHSG-1Shotgun"
Alias="NeonHSG1Shotgun"
Alias="NeonHSGShotgun"
Alias="NeonHSG"
Alias="NeonKSG-1Shotgun"
Alias="NeonKSG1Shotgun"
Alias="NeonKSGShotgun"
Alias="NeonKSG"
[weapon/KFMod:NailGun Aliases]
Alias="VladTheImpaler"
Alias="VladImpaler"
Alias="Vlad"
Alias="Impaler"
Alias="NailGun"
Alias="Nails"
Alias="Nail"
[weapon/KFMod:SPAutoShotgun Aliases]
Alias="MultichamberZEDThrower"
Alias="ZEDThrower"
Alias="ZThrower"
[weapon/KFMod:BenelliShotgun Aliases]
Alias="CombatShotgun"
Alias="Combat"
Alias="CShotgun"
Alias="BenelliShotgun"
Alias="BeneliShotgun"
Alias="Benelli"
Alias="Beneli"
[weapon/KFMod:GoldenBenelliShotgun Aliases]
Alias="GoldCombatShotgun"
Alias="GoldCombat"
Alias="GoldCShotgun"
Alias="GoldBenelliShotgun"
Alias="GoldBeneliShotgun"
Alias="GoldBenelli"
Alias="GoldBeneli"
[weapon/KFMod:AA12AutoShotgun Aliases]
Alias="AA12"
Alias="AA12AutoShotgun"
Alias="AA12Shotgun"
[weapon/KFMod:GoldenAA12AutoShotgun Aliases]
Alias="GoldAA12"
Alias="GoldAA12AutoShotgun"
Alias="GoldAA12Shotgun"
; Sharpshooter weapons
[weapon/KFMod:Single Aliases]
Alias="9mmTactical"
Alias="9mmTact"
Alias="9mm"
Alias="Single"
Alias="Pistol"
[weapon/KFMod:Dualies Aliases]
Alias="Dual9mms"
Alias="Dual9mm"
Alias="9mmDual"
Alias="Dualies"
Alias="Dual"
[weapon/KFMod:Magnum44Pistol Aliases]
Alias="Magnum44Pistol"
Alias="Magnum44"
Alias="44Magnum"
Alias="Magnum"
Alias="44"
[weapon/KFMod:Dual44Magnum Aliases]
Alias="DualMagnum44Pistols"
Alias="DualMagnum44s"
Alias="DualMagnums"
Alias="DualMagnumPistols"
Alias="Dual44Magnums"
Alias="Dual44Magnum"
Alias="DualMagnum"
Alias="Dual44ss"
Alias="Dual44"
[weapon/KFMod:MK23Pistol Aliases]
Alias="MK23"
Alias="MK"
Alias="23"
[weapon/KFMod:DualMK23Pistol Aliases]
Alias="DualMK23s"
Alias="DualMK23"
Alias="DualMKs"
Alias="DualMK"
Alias="Dual23s"
Alias="Dual23"
[weapon/KFMod:Deagle Aliases]
Alias="Handcannon"
Alias="Deagle"
Alias="HC"
[weapon/KFMod:DualDeagle Aliases]
Alias="DualHandcannons"
Alias="DualHC"
Alias="DualDeagle"
[weapon/KFMod:GoldenDeagle Aliases]
Alias="GoldHandcannon"
Alias="GoldDeagle"
Alias="GoldHC"
[weapon/KFMod:GoldenDualDeagle Aliases]
Alias="GoldDualHandcannons"
Alias="GoldDualHC"
Alias="GoldDualDeagle"
[weapon/KFMod:Winchester Aliases]
Alias="Winchester"
Alias="LeverActionRifle"
Alias="LAR"
[weapon/KFMod:SPSniperRifle Aliases]
Alias="SPMusket"
Alias="Musket"
Alias="SPSniperRifle"
Alias="SPRifle"
Alias="SPSniper"
Alias="SPMauler"
Alias="Mauler"
[weapon/KFMod:M14EBRBattleRifle Aliases]
Alias="M14EBR"
Alias="M14"
Alias="EBR"
Alias="M14EBRRifle"
Alias="M14EBRBattleRifle"
[weapon/KFMod:Crossbow Aliases]
Alias="CompoundCrossbow"
Alias="CCrossbow"
Alias="Crossbow"
Alias="XBow"
[weapon/KFMod:M99SniperRifle Aliases]
Alias="M99AMR"
Alias="M99"
Alias="M99SniperRifle"
Alias="M99Sniper"
Alias="M99Rifle"
Alias="M99SR"
; Commando weapons
[weapon/KFMod:Bullpup Aliases]
Alias="Bullpup"
Alias="Bulpup"
[weapon/KFMod:ThompsonSMG Aliases]
Alias="ThompsonSMG"
Alias="Thompson"
Alias="Thomp"
Alias="TommyGun"
Alias="TomyGun"
Alias="Tommy"
Alias="Tomy"
[weapon/KFMod:SPThompsonSMG Aliases]
Alias="SPThompsonSMG"
Alias="SPThompson"
Alias="SPThomp"
Alias="Dr.T'sLeadDeliverySystem"
Alias="Dr.TsLeadDeliverySystem"
Alias="DrT'sLeadDeliverySystem"
Alias="DrTsLeadDeliverySystem"
Alias="Dr.T'LeadDeliverySystem"
Alias="Dr.TLeadDeliverySystem"
Alias="DrT'LeadDeliverySystem"
Alias="DrTLeadDeliverySystem"
Alias="DrTDeliverySystem"
Alias="DrTLeadSystem"
Alias="DrTLeadDelivery"
Alias="DrTDelivery"
Alias="LeadDelivery"
Alias="LeadSystem"
Alias="DeliverySystem"
Alias="LeadDS"
Alias="LeadD"
[weapon/KFMod:ThompsonDrumSMG Aliases]
Alias="ThompsonDrumSMG"
Alias="ThompsonDrum"
Alias="ThompDrum"
Alias="RisingStormTommyGun"
Alias="RisingStormTommy"
Alias="RisingStormTomyGun"
Alias="RisingStormTomy"
Alias="RSTommyGun"
Alias="RSTommy"
Alias="RSTomyGun"
Alias="RSTomy"
[weapon/KFMod:AK47AssaultRifle Aliases]
Alias="AK47AssaultRifle"
Alias="AK47Assault"
Alias="AK47Rifle"
Alias="AK47AR"
Alias="AK47"
Alias="AK"
Alias="47"
[weapon/KFMod:GoldenAK47AssaultRifle Aliases]
Alias="GoldAK47AssaultRifle"
Alias="GoldAK47Assault"
Alias="GoldAK47Rifle"
Alias="GoldAK47AR"
Alias="GoldAK47"
Alias="GoldAK"
Alias="Gold47"
[weapon/KFMod:NeonAK47AssaultRifle Aliases]
Alias="NeonAK47AssaultRifle"
Alias="NeonAK47Assault"
Alias="NeonAK47Rifle"
Alias="NeonAK47AR"
Alias="NeonAK47"
Alias="NeonAK"
Alias="Neon47"
[weapon/KFMod:M4AssaultRifle Aliases]
Alias="M4AssaultRifle"
Alias="M4Assault"
Alias="M4Rifle"
Alias="M4"
[weapon/KFMod:M4AssaultRifle Aliases]
Alias="CamoM4AssaultRifle"
Alias="CamoM4Assault"
Alias="CamoM4Rifle"
Alias="CamoM4"
[weapon/KFMod:M4AssaultRifle Aliases]
Alias="CamoM4AssaultRifle"
Alias="CamoM4Assault"
Alias="CamoM4Rifle"
Alias="CamoM4"
[weapon/KFMod:MKb42AssaultRifle Aliases]
Alias="MKb42AssaultRifle"
Alias="MKb42Assault"
Alias="MKb42Rifle"
Alias="MKb42"
Alias="MK42"
Alias="MKb"
[weapon/KFMod:SCARMK17AssaultRifle Aliases]
Alias="SCARMK17AssaultRifle"
Alias="SCARMK17Assault"
Alias="SCARMK17Rifle"
Alias="SCARMKAssaultRifle"
Alias="SCARMKAssault"
Alias="SCARMKRifle"
Alias="SCAR17AssaultRifle"
Alias="SCAR17Assault"
Alias="SCAR17Rifle"
Alias="SCARAssaultRifle"
Alias="SCARAssault"
Alias="SCARRifle"
Alias="SCAR17"
Alias="SCARMK"
Alias="SCAR"
[weapon/KFMod:NeonSCARMK17AssaultRifle Aliases]
Alias="NeonSCARMK17AssaultRifle"
Alias="NeonSCARMK17Assault"
Alias="NeonSCARMK17Rifle"
Alias="NeonSCARMKAssaultRifle"
Alias="NeonSCARMKAssault"
Alias="NeonSCARMKRifle"
Alias="NeonSCAR17AssaultRifle"
Alias="NeonSCAR17Assault"
Alias="NeonSCAR17Rifle"
Alias="NeonSCARAssaultRifle"
Alias="NeonSCARAssault"
Alias="NeonSCARRifle"
Alias="NeonSCAR17"
Alias="NeonSCARMK"
Alias="NeonSCAR"
[weapon/KFMod:FNFAL_ACOG_AssaultRifle Aliases]FNFAL ACOG
Alias="FNFALACOGAssaultRifle"
Alias="FNFALACOGAssault"
Alias="FNFALACOGRifle"
Alias="FNFALAssaultRifle"
Alias="FNFALAssault"
Alias="FNFALRifle"
Alias="FALACOGAssaultRifle"
Alias="FALACOGAssault"
Alias="FALACOGRifle"
Alias="FALAssaultRifle"
Alias="FALAssault"
Alias="FALRifle"
Alias="FNFALACOG"
Alias="FNFAL"
Alias="FALACOG"
Alias="FAL"
Alias="FN"
; Berserker weapons
[weapon/KFMod:Knife Aliases]
Alias="Knife"
[weapon/KFMod:Machete Aliases]
Alias="Machete"
Alias="Chete"
[weapon/KFMod:Axe Aliases]
Alias="Axe"
Alias="FireAxe"
[weapon/KFMod:Katana Aliases]
Alias="Katana"
[weapon/KFMod:GoldenKatana Aliases]
Alias="GoldKatana"
[weapon/KFMod:Scythe Aliases]
Alias="Scythe"
Alias="Scyte"
Alias="Sickle"
Alias="Sickl"
[weapon/KFMod:Chainsaw Aliases]
Alias="Chainsaw"
Alias="Saw"
Alias="Denji"
Alias="Pochita"
[weapon/KFMod:GoldenChainsaw Aliases]
Alias="GoldChainsaw"
Alias="GoldSaw"
Alias="GoldDenji"
Alias="GoldPochita"
[weapon/KFMod:DwarfAxe Aliases]
Alias="DwarfsAxe"
Alias="DwarfAxe"
Alias="ShitAxe"
Alias="CrapAxe"
Alias="PushAxe"
Alias="GnomeAxe"
Alias="TrollAxe"
Alias="NoobAxe"
[weapon/KFMod:ClaymoreSword Aliases]
Alias="ClaymoreSword"
Alias="ClaymoreBlade"
Alias="Claymore"
Alias="Claymor"
Alias="ClaimoreSword"
Alias="ClaimoreBlade"
Alias="Claimore"
Alias="Claimor"
Alias="Sword"
Alias="Blade"
[weapon/KFMod:Crossbuzzsaw Aliases]
Alias="Crossbuzzsaw"
Alias="Buzzsaw"
Alias="Buzz"
Alias="BuzzsawBow"
Alias="BuzzBow"
Alias="ZerkBow"
; Firebug weapons
[weapon/KFMod:MAC10MP Aliases]
Alias="MAC10MP"
Alias="MAC10"
Alias="MAC"
[weapon/KFMod:FlareRevolver Aliases]
Alias="FlareRevolver"
Alias="FireRevolver"
Alias="FlareGun"
Alias="Flares"
Alias="Flare"
[weapon/KFMod:DualFlareRevolver Aliases]
Alias="DualFlareRevolvers"
Alias="DualFlareRevolver"
Alias="DualFireRevolvers"
Alias="DualFireRevolver"
Alias="DualFlareGuns"
Alias="DualFlareGun"
Alias="DualFlares"
Alias="DualFlare"
[weapon/KFMod:FlameThrower Aliases]
Alias="FlameThrower"
Alias="FireThrower"
Alias="FThrower"
Alias="Flamer"
Alias="FireSpam"
[weapon/KFMod:GoldenFlamethrower Aliases]
Alias="GoldFlameThrower"
Alias="GoldFireThrower"
Alias="GoldFThrower"
Alias="GoldFlamer"
Alias="GoldFireSpam"
[weapon/KFMod:Trenchgun Aliases]
Alias="DragonsBreathTrenchgun"
Alias="DragonsBreathGun"
Alias="DragonsBreath"
Alias="DragBreathTrenchgun"
Alias="DragBreathGun"
Alias="DragBreath"
Alias="Trenchgun"
Alias="FireShotgun"
Alias="Flameshotgun"
[weapon/KFMod:HuskGun Aliases]
Alias="HuskFireballLauncher"
Alias="HuskFireball"
Alias="FireballLauncher"
Alias="HuskLauncher"
Alias="HuskFirebalLauncher"
Alias="HuskFirebal"
Alias="FirebalLauncher"
Alias="HuskLauncher"
Alias="HuskGun"
Alias="Husk"
; Demolition weapons
[weapon/KFMod:M79GrenadeLauncher Aliases]
Alias="M79GrenadeLauncher"
Alias="M79Grenade"
Alias="M79Launcher"
Alias="M79NadeLauncher"
Alias="M79Nade"
Alias="M79GrenadeLauncher"
Alias="M79"
[weapon/KFMod:GoldenM79GrenadeLauncher Aliases]
Alias="GoldM79GrenadeLauncher"
Alias="GoldM79Grenade"
Alias="GoldM79Launcher"
Alias="GoldM79NadeLauncher"
Alias="GoldM79Nade"
Alias="GoldM79GrenadeLauncher"
Alias="GoldM79"
[weapon/KFMod:SPGrenadeLauncher Aliases]
Alias="SPGrenadeLauncher"
Alias="SPNadeLauncher"
Alias="SPLauncher"
Alias="SPNade"
Alias="TheOrcaBombPropeller"
Alias="TheOrcaBombPropeler"
Alias="TheOrcaBomb"
Alias="TheOrca"
Alias="TheOrcaLauncher"
Alias="OrcaBombPropeller"
Alias="OrcaBombPropeler"
Alias="OrcaBomb"
Alias="Orca"
Alias="OrcaLauncher"
[weapon/KFMod:PipeBombExplosive Aliases]
Alias="PipeBombExplosive"
Alias="PipeExplosive"
Alias="PipeBomb"
Alias="Pipes"
Alias="Pipe"
[weapon/KFMod:SealSquealHarpoonBomber Aliases]
Alias="SealSquealHarpoonBomber"
Alias="SealSquealHarpoon"
Alias="SealSquealBomber"
Alias="SealHarpoonBomber"
Alias="SealHarpoon"
Alias="SealBomber"
Alias="SealSqueal"
Alias="HarpoonBomber"
Alias="Harpoon"
Alias="Harp"
[weapon/KFMod:SeekerSixRocketLauncher Aliases]
Alias="SeekerSixRocketLauncher"
Alias="SeekerSixLauncher"
Alias="Seeker6RocketLauncher"
Alias="Seeker6Launcher"
Alias="SeekerRocketLauncher"
Alias="SeekerLauncher"
Alias="SeekerSix"
Alias="Seeker6"
Alias="Seeker"
Alias="SuckerSix"
Alias="Sucker6"
Alias="Sucker"
[weapon/KFMod:M4203AssaultRifle Aliases]
Alias="M4203Assault"
Alias="M4203Rifle"
Alias="M4203"
Alias="M4200"
Alias="M420"
Alias="M42"
[weapon/KFMod:LAW Aliases]
Alias="LAW"
[weapon/KFMod:M32GrenadeLauncher Aliases]
Alias="M32GrenadeLauncher"
Alias="M32Grenade"
Alias="M32Launcher"
Alias="M32NadeLauncher"
Alias="M32Nade"
Alias="M32GrenadeLauncher"
Alias="M32"
[weapon/KFMod:CamoM32GrenadeLauncher Aliases]
Alias="CamoM32GrenadeLauncher"
Alias="CamoM32Grenade"
Alias="CamoM32Launcher"
Alias="CamoM32NadeLauncher"
Alias="CamoM32Nade"
Alias="CamoM32GrenadeLauncher"
Alias="CamoM32"
; Off-perk weapons
[weapon/KFMod:ZEDGun Aliases]
Alias="ZedEradicationDevice"
Alias="ZedEradication"
Alias="ZedDevice"
Alias="ZEDGun"
Alias="ZED"
[weapon/KFMod:ZEDMKIIWeapon Aliases]
Alias="ZedEradicationDeviceMKII"
Alias="ZedEradicationMKII"
Alias="ZedDeviceMKII"
Alias="ZEDGunMKII"
Alias="ZEDMKII"
Alias="ZedEradicationDeviceMK2"
Alias="ZedEradicationMK2"
Alias="ZedDeviceMK2"
Alias="ZEDGunMK2"
Alias="ZEDMK2"
Alias="ZedEradicationDeviceMK"
Alias="ZedEradicationMK"
Alias="ZedDeviceMK"
Alias="ZEDGunMK"
Alias="ZEDMK"
Alias="ZedEradicationDevice2"
Alias="ZedEradication2"
Alias="ZedDevice2"
Alias="ZEDGun2"
Alias="ZED2"
; For the puposes of unit-testing.
; Changing these can break unit tests.
;
; If you don't plan to run unit tests or do not know what they are, -
; feel free to remove records below.
[test/car Aliases]
Alias="Ford"
Alias="Delorean"
Alias="Audi"
[test/scifi Aliases]
Alias="Spice"
Alias="HardToBeAGod"

140
sources/Core/Aliases/Aliases.uc

@ -0,0 +1,140 @@
/**
* Aliases allow users to define human-readable and easier to use
* "synonyms" to some symbol sequences (mainly names of UnrealScript classes).
* Due to how aliases are stored, there is a limitation on original
* values to which aliases refer: it must be a valid object name to store via
* `perObjectConfig`. For example it cannot contain `]` or a dot `.`
* (use `:` as a delimiter for class names: `KFMod:M14EBRBattleRifle`).
* Aliases can be grouped into categories: "weapons", "test", "maps", etc.
* Aliases can be configured in `AcediaAliases` in form:
* ________________________________________________________________________
* | [<groupName>/<aliasesValue> Aliases]
* | Alias="<alias1>"
* | Alias="<alias2>"
* | ...
* |_______________________________________________________________________
* where <groupName>, <aliasesValue>, <alias1>, ... can be replaced with
* desired values.
* Copyright 2020 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 Aliases extends AcediaObject
perObjectConfig
config(AcediaAliases);
/**
* All data is stored in config as a bunch of named `Aliases` objects
* (via `perObjectConfig`). Name of each object records both aliases group and
* value (see class description for details).
* Aliases themselves are recorded into the `alias` array.
*/
// Stores name of the configuration file.
var private const string configName;
// Both value
// Symbol (or symbol sequence) that separates value from the group in
// `[<groupName>/<aliasesValue> Aliases]`.
var private const string delimiter;
// Set once to prevent more than one object loading.
var private bool initialized;
// All aliases objects, specified by the configuration file.
var private array<Aliases> availableRecords;
// Data loaded from the configuration file into the `Aliases` object.
// Value to which all aliases refer to.
var private string originalValue;
// Group to which this object's aliases belong to.
var private string groupName;
// Recorded aliases ("synonyms") for the `originalValue`.
var public config array<string> alias;
// Initializes data that we can not directly read from the configuration file.
private final function Initialize()
{
if (initialized) return;
availableRecords.length = 0;
ParseObjectName(string(self.name));
initialized = true;
}
private final function ParseObjectName(string configName)
{
local int i;
local array<string> splitName;
Split(configName, "/", splitName);
groupName = splitName[0];
originalValue = "";
for (i = 1; i < splitName.length; i += 1)
{
originalValue $= splitName[i];
}
}
// This function loads all the defined aliases from the config file.
// Need to only be called once, further calls do nothing.
public static final function LoadAliases()
{
local int i;
local array<string> recordNames;
if (default.initialized) return;
recordNames =
GetPerObjectNames(default.configName, string(class'Aliases'.name));
for (i = 0; i < recordNames.length; i += 1)
{
default.availableRecords[i] = new(none, recordNames[i]) class'Aliases';
if (default.availableRecords[i] != none)
{
default.availableRecords[i].Initialize();
}
}
default.initialized = true;
}
// Tries to find original value for a given alias in a given group.
public static final function bool ResolveAlias
(
string group,
string alias,
out string result
)
{
local int i, j;
if (!default.initialized) return false;
for (i = 0; i < default.availableRecords.length; i += 1)
{
if (!(default.availableRecords[i].groupName ~= group)) continue;
for (j = 0; j < default.availableRecords[i].alias.length; j += 1)
{
if (default.availableRecords[i].alias[j] ~= alias)
{
result = default.availableRecords[i].originalValue;
return true;
}
}
}
return false;
}
defaultproperties
{
initialized = false
configName = "AcediaAliases"
delimiter = "/"
}

43
sources/Core/Aliases/AliasesAPI.uc

@ -0,0 +1,43 @@
/**
* Provides convenient access to Aliases-related functions.
* Copyright 2019 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 AliasesAPI extends Singleton;
// Resolves original value for given alias and it's group.
// Returns `false` if there no such alias and `true` if there is.
public function bool Resolve(string group, string alias, out string result)
{
return class'Aliases'.static.ResolveAlias(group, alias, result);
}
// Tries to resolve given alias.
// If fails - returns passed `alias` value back.
public function string Try(string group, string alias)
{
local string result;
if (class'Aliases'.static.ResolveAlias(group, alias, result))
{
return result;
}
return alias;
}
defaultproperties
{
}

53
sources/Core/Aliases/Tests/TEST_Aliases.uc

@ -0,0 +1,53 @@
/**
* Set of tests for Aliases system.
* Copyright 2020 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 TEST_Aliases extends TestCase
abstract;
protected static function TESTS()
{
local string result;
Context("Testing Aliases loading.");
Issue("`Try` cannot resolve correct alias");
TEST_ExpectTrue(_().alias.Try("test", "Ford") == "car");
TEST_ExpectTrue(_().alias.Try("test", "Delorean") == "car");
TEST_ExpectTrue(_().alias.Try("test", "HardToBeAGod") == "scifi");
Issue("`Resolve` cannot resolve correct alias");
_().alias.Resolve("test", "Ford", result);
TEST_ExpectTrue(result == "car");
_().alias.Resolve("test", "Audi", result);
TEST_ExpectTrue(result == "car");
_().alias.Resolve("test", "Spice", result);
TEST_ExpectTrue(result == "scifi");
Issue("`Try` does not return original alias for non-existing alias record");
TEST_ExpectTrue(_().alias.Try("test", "AllFiction") == "AllFiction");
Issue("`Resolve` reports success when it failed");
TEST_ExpectFalse(_().alias.Resolve("test", "KarmicJustice", result));
Issue("`Resolve` reports failure when it succeeds");
TEST_ExpectTrue(_().alias.Resolve("test", "Delorean", result));
}
defaultproperties
{
caseName = "Aliases"
}

6
sources/Global.uc

@ -21,12 +21,14 @@
*/
class Global extends Singleton;
var public Acedia acedia;
var public JSONAPI json;
var public Acedia acedia;
var public JSONAPI json;
var public AliasesAPI alias;
protected function OnCreated()
{
acedia = class'Acedia'.static.GetInstance();
Spawn(class'JSONAPI');
json = JSONAPI(class'JSONAPI'.static.GetInstance());
alias = AliasesAPI(class'AliasesAPI'.static.GetInstance());
}

1
sources/Manifest.uc

@ -46,4 +46,5 @@ defaultproperties
requiredListeners(0) = class'MutatorListener_Connection'
// Unit tests
testCases(0) = class'TEST_JSON'
testCases(1) = class'TEST_Aliases'
}
Loading…
Cancel
Save