Add a const at version for datafile getters. Retrieve values from actual datafile provided instead of assuming the variable is from base ability with the data translation function. Fix names not properly spacing/appending. Add in unit tests for GetNameWithPlayerModifiers() and GetDescriptionWithPlayerModifiers(). Applied towards PR #79. Release Build 12191.
This commit is contained in:
parent
b9994242dd
commit
fab7f34afa
@ -47,7 +47,7 @@
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Unit Testing|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>C:\Users\LabUser\source\repos\AdventuresInLestoria\Adventures in Lestoria\include;C:\Users\LabUser\source\repos\AdventuresInLestoria\Adventures in Lestoria;C:\Users\LabUser\source\repos\AdventuresInLestoria\Adventures in Lestoria\include;$(ProjectDir)..\AdventuresInLestoria\Adventures in Lestoria;$(ProjectDir)..\AdventuresInLestoria\Adventures in Lestoria\include;$(IncludePath)</IncludePath>
|
||||
<IncludePath>C:\Users\LabUser\source\repos\AdventuresInLestoria\Adventures in Lestoria\include;C:\Users\LabUser\source\repos\AdventuresInLestoria\Adventures in Lestoria;$(SolutionDir)Adventures in Lestoria;$(SolutionDir)Adventures in Lestoria\include$(SolutionDir);$(IncludePath)</IncludePath>
|
||||
<OutDir>..\x64\Unit Testing</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Unit Testing|Win32'">
|
||||
|
@ -113,9 +113,18 @@ namespace EnchantTests
|
||||
testGame->OnUserUpdate(0.f);
|
||||
testGame.reset();
|
||||
}
|
||||
TEST_METHOD(EnchantAbilitySettingsReadProperly){
|
||||
Assert::AreEqual("Increases Maximum Health by 3%",ItemEnchant{"Health Boost"}.GetModifiedAbilityDescription().c_str(),L"Health Boost has its normal description.");
|
||||
Assert::AreEqual("Shoots nine arrows rapidly. Total Damage: 90",ItemEnchant{"Extreme Rapid Fire"}.GetModifiedAbilityDescription().c_str(),L"Extreme Rapid Fire should have ability description modifiers attached to it.");
|
||||
TEST_METHOD(AbilityNameWithPlayerModifiersWorks){
|
||||
Game::ChangeClass(player,RANGER);
|
||||
Assert::AreEqual("Rapid Fire",player->GetAbility1().GetNameWithPlayerModifiers().c_str(),L"Ability name should be unmodified with no modifiers applied.");
|
||||
Assert::AreEqual("Shoots #45F9FFfour#FFFFFF arrows rapidly. Total Damage: #45F9FF52#FFFFFF.",player->GetAbility1().GetDescriptionWithPlayerModifiers().c_str(),L"Ability descriptions should be unmodified with no modifiers applied.");
|
||||
|
||||
Game::GiveAndEquipEnchantedRing("Extreme Rapid Fire");
|
||||
Assert::AreEqual("Extreme Rapid Fire",player->GetAbility1().GetNameWithPlayerModifiers().c_str(),L"Ability name should be modified with appropriate modifier applied.");
|
||||
Assert::AreEqual("Shoots #45F9FFnine#FFFFFF arrows rapidly. Total Damage: #45F9FF117#FFFFFF.",player->GetAbility1().GetDescriptionWithPlayerModifiers().c_str(),L"Ability description should be modified with appropriate modifier applied.");
|
||||
|
||||
Inventory::UnequipItem(EquipSlot::RING1);
|
||||
Assert::AreEqual("Rapid Fire",player->GetAbility1().GetNameWithPlayerModifiers().c_str(),L"After unequipping Ability name should be back to normal with no modifiers applied.");
|
||||
Assert::AreEqual("Shoots #45F9FFfour#FFFFFF arrows rapidly. Total Damage: #45F9FF52#FFFFFF.",player->GetAbility1().GetDescriptionWithPlayerModifiers().c_str(),L"After unequipping Ability descriptions should be back to normal with no modifiers applied.");
|
||||
}
|
||||
TEST_METHOD(HealthBoostCheck){
|
||||
Assert::AreEqual(100,player->GetMaxHealth(),L"Player starts with 100 health.");
|
||||
|
@ -88,16 +88,21 @@ const std::string Ability::GetNameWithPlayerModifiers()const{
|
||||
if(suffixName.length()>0&&modifiers.preName)suffixName+=" ";
|
||||
suffixName+=modifiers.postName.value_or("");
|
||||
}
|
||||
return std::format("{}{}{}",prefixName,newName,suffixName);
|
||||
std::string finalName{prefixName};
|
||||
if(finalName.length()>0&&newName.length()>0)finalName+=' ';
|
||||
finalName+=newName;
|
||||
if(finalName.length()>0&&suffixName.length()>0)finalName+=' ';
|
||||
finalName+=suffixName;
|
||||
return finalName;
|
||||
}
|
||||
|
||||
const std::string Ability::GetDescriptionWithPlayerModifiers()const{
|
||||
using SpecialKey=std::string;
|
||||
using TranslateFunc=std::function<std::string(const std::string&val)>;
|
||||
using TranslateFunc=std::function<std::string(const datafile&data,const std::string&val)>;
|
||||
std::unordered_map<SpecialKey,TranslateFunc>specialPrefixes{
|
||||
#define TranslateFunc [&](const std::string&val)->std::string
|
||||
#define TranslateFunc [&](const datafile&data,const std::string&val)->std::string
|
||||
{"DamageMult",TranslateFunc{
|
||||
float damageMult{stof((*abilityConfig).get()[val].GetString())};
|
||||
float damageMult{stof(data.at(val).GetString())};
|
||||
int finalDmg{int(damageMult*game->GetPlayer()->GetAttack())};
|
||||
return std::format("{}",finalDmg);
|
||||
}},
|
||||
@ -121,7 +126,7 @@ const std::string Ability::GetDescriptionWithPlayerModifiers()const{
|
||||
std::string separatorVal{variableName.substr(separatorMarker+1)};
|
||||
if(!specialPrefixes.count(separatorKey))ERR(std::format("Could not find translation function for key {} inside special prefixes map!",separatorKey))
|
||||
else {
|
||||
finalText+=specialValCol.toHTMLColorCode()+specialPrefixes[separatorKey](separatorVal)+WHITE.toHTMLColorCode();
|
||||
finalText+=specialValCol.toHTMLColorCode()+specialPrefixes[separatorKey](data,separatorVal)+WHITE.toHTMLColorCode();
|
||||
bracesFound=false;
|
||||
return true;
|
||||
}
|
||||
@ -145,6 +150,7 @@ const std::string Ability::GetDescriptionWithPlayerModifiers()const{
|
||||
std::string prefixDescription{};
|
||||
std::string newDescription{ParseVariables(description)};
|
||||
std::string suffixDescription{};
|
||||
bool descriptionHasBeenModifiedAgain{false};
|
||||
for(const auto&enchant:ItemEnchantInfo::GetAllEnchantsAffectingAbility(name)){
|
||||
const ItemEnchantInfo::AbilityDescriptionModifiers&modifiers{enchant.get().GetModifiers()};
|
||||
if(prefixDescription.length()>0&&modifiers.preDescription)prefixDescription+=" ";
|
||||
@ -170,7 +176,7 @@ const std::string Ability::GetDescriptionWithPlayerModifiers()const{
|
||||
std::string separatorVal{variableName.substr(separatorMarker+1)};
|
||||
if(!specialPrefixes.count(separatorKey))ERR(std::format("Could not find translation function for key {} inside special prefixes map!",separatorKey))
|
||||
else {
|
||||
finalText+=specialValCol.toHTMLColorCode()+specialPrefixes[separatorKey](separatorVal)+WHITE.toHTMLColorCode();
|
||||
finalText+=specialValCol.toHTMLColorCode()+specialPrefixes[separatorKey](data,separatorVal)+WHITE.toHTMLColorCode();
|
||||
bracesFound=false;
|
||||
return true;
|
||||
}
|
||||
@ -193,6 +199,10 @@ const std::string Ability::GetDescriptionWithPlayerModifiers()const{
|
||||
return finalText;
|
||||
};
|
||||
prefixDescription=ParseVariablesForEnchant(prefixDescription);
|
||||
if(!descriptionHasBeenModifiedAgain){
|
||||
descriptionHasBeenModifiedAgain=true;
|
||||
newDescription=description;
|
||||
}
|
||||
newDescription=ParseVariablesForEnchant(newDescription);
|
||||
suffixDescription=ParseVariablesForEnchant(suffixDescription);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 12186
|
||||
#define VERSION_BUILD 12191
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
@ -546,6 +546,10 @@ namespace olc::utils
|
||||
return m_vecObjects[m_mapObjects[name]].second;
|
||||
}
|
||||
|
||||
inline const datafile&at(const std::string&name)const{
|
||||
return m_vecObjects.at(m_mapObjects.at(name)).second;
|
||||
}
|
||||
|
||||
inline auto begin(){
|
||||
return GetKeys().begin();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user