Fix parsing of ability descriptions to use owning strings and to retrieve from the proper keys. (Except for non-enchants.)
All checks were successful
Emscripten Build / Build_and_Deploy_Web_Build (push) Successful in 7m47s
All checks were successful
Emscripten Build / Build_and_Deploy_Web_Build (push) Successful in 7m47s
This commit is contained in:
parent
93298e05d3
commit
cb3f38e07c
@ -68,7 +68,7 @@ const bool Ability::operator==(const Ability&a)const{
|
||||
return name==a.name&&isOriginalAbility==a.isOriginalAbility;
|
||||
}
|
||||
|
||||
const std::string_view Ability::GetName()const{
|
||||
const std::string&Ability::GetName()const{
|
||||
return name;
|
||||
}
|
||||
|
||||
@ -87,37 +87,6 @@ const std::string Ability::GetNameWithPlayerModifiers()const{
|
||||
if(modifiers.newName)newName=modifiers.newName.value();
|
||||
if(suffixName.length()>0&&modifiers.preName)suffixName+=" ";
|
||||
suffixName+=modifiers.postName.value_or("");
|
||||
|
||||
const auto ParseVariables=[&](const std::string_view abilityText)->std::string{
|
||||
std::string finalText{};
|
||||
size_t marker{};
|
||||
std::string variableName{};
|
||||
bool bracesFound{false};
|
||||
|
||||
const auto FindAndParse=[&finalText,&bracesFound,&variableName](datafile&data)->bool{
|
||||
if(data.HasProperty(variableName)){
|
||||
if(finalText.length()>0)finalText+=' ';
|
||||
finalText+=data.GetProperty(variableName).GetFullString();
|
||||
bracesFound=false;
|
||||
variableName="";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
while(abilityText.length()>marker){
|
||||
const char c{abilityText[marker]};
|
||||
if(!bracesFound&&c=='{')bracesFound=true;
|
||||
else if(bracesFound&&c=='}'){ //Parse the variable.
|
||||
if(!FindAndParse(enchant["Ability Settings"]))
|
||||
if(!FindAndParse(enchant))
|
||||
if(!FindAndParse((*(*newEnchant.GetAbility())->abilityConfig).get()))
|
||||
ERR(std::format("Could not find variable {} for enchant Ability Settings of enchantment {}",variableName,newEnchant.Name()));
|
||||
}else if(bracesFound)variableName+=c;
|
||||
marker++;
|
||||
}
|
||||
return finalText;
|
||||
};
|
||||
}
|
||||
return std::format("{}{}{}",prefixName,newName,suffixName);
|
||||
}
|
||||
@ -133,6 +102,40 @@ const std::string Ability::GetDescriptionWithPlayerModifiers()const{
|
||||
if(modifiers.newDescription)newDescription=*modifiers.newDescription;
|
||||
if(suffixDescription.length()>0&&modifiers.preDescription)suffixDescription+=" ";
|
||||
suffixDescription+=modifiers.postDescription.value_or("");
|
||||
|
||||
const auto ParseVariables=[&](const std::string_view abilityText)->std::string{
|
||||
std::string finalText{};
|
||||
size_t marker{};
|
||||
std::string variableName{};
|
||||
bool bracesFound{false};
|
||||
|
||||
const auto FindAndParse=[&finalText,&bracesFound,&variableName](datafile&data)->bool{
|
||||
if(data.HasProperty(variableName)){
|
||||
finalText+=data.GetProperty(variableName).GetFullString();
|
||||
bracesFound=false;
|
||||
variableName="";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
while(abilityText.length()>marker){
|
||||
const char c{abilityText[marker]};
|
||||
if(!bracesFound&&c=='{')bracesFound=true;
|
||||
else if(bracesFound&&c=='}'){ //Parse the variable.
|
||||
if(!FindAndParse(enchant.get().GetData()["Ability Settings"]))
|
||||
if(!FindAndParse(enchant.get().GetData()))
|
||||
if(!FindAndParse((*(*enchant.get().GetAbility())->abilityConfig).get()))
|
||||
ERR(std::format("Could not find variable {} for enchant Ability Settings of enchantment {}",variableName,enchant.get().Name()));
|
||||
}else if(bracesFound)variableName+=c;
|
||||
else finalText+=c;
|
||||
marker++;
|
||||
}
|
||||
return finalText;
|
||||
};
|
||||
prefixDescription=ParseVariables(prefixDescription);
|
||||
newDescription=ParseVariables(newDescription);
|
||||
suffixDescription=ParseVariables(suffixDescription);
|
||||
}
|
||||
return std::format("{}{}{}",prefixDescription,newDescription,suffixDescription);
|
||||
}
|
@ -95,7 +95,7 @@ struct Ability{
|
||||
Ability();
|
||||
//NOTE: icon expects the actual name relative to the "Ability Icons" directory for this constructor!
|
||||
Ability(std::string name,std::string shortName,std::string description,float cooldownTime,int manaCost,InputGroup*input,std::string icon,Pixel barColor1=VERY_DARK_RED,Pixel barColor2=DARK_RED,PrecastData precastInfo={},bool canCancelCast=false);
|
||||
const std::string_view GetName()const;
|
||||
const std::string&GetName()const;
|
||||
const std::string_view GetDescription()const;
|
||||
|
||||
const std::string GetNameWithPlayerModifiers()const;
|
||||
|
@ -121,12 +121,12 @@ void ItemEnchantInfo::Initialize(){
|
||||
if(enchant.HasProperty("Ability Settings")){
|
||||
for(const auto&[key,size]:enchant["Ability Settings"]){
|
||||
|
||||
if(key=="Pre-Name")modifiers.preName=ParseVariables(enchant["Ability Settings"][key].GetString());
|
||||
else if(key=="Post-Name")modifiers.postName=ParseVariables(enchant["Ability Settings"][key].GetString());
|
||||
else if(key=="Name")modifiers.newName=ParseVariables(enchant["Ability Settings"][key].GetString());
|
||||
else if(key=="Pre-Description")modifiers.preDescription=ParseVariables(enchant["Ability Settings"][key].GetString());
|
||||
else if(key=="Post-Description")modifiers.postDescription=ParseVariables(enchant["Ability Settings"][key].GetString());
|
||||
else if(key=="Description")modifiers.newDescription=ParseVariables(enchant["Ability Settings"][key].GetString());
|
||||
if(key=="Pre-Name")modifiers.preName=enchant["Ability Settings"][key].GetFullString();
|
||||
else if(key=="Post-Name")modifiers.postName=enchant["Ability Settings"][key].GetFullString();
|
||||
else if(key=="Name")modifiers.newName=enchant["Ability Settings"][key].GetFullString();
|
||||
else if(key=="Pre-Description")modifiers.preDescription=enchant["Ability Settings"][key].GetFullString();
|
||||
else if(key=="Post-Description")modifiers.postDescription=enchant["Ability Settings"][key].GetFullString();
|
||||
else if(key=="Description")modifiers.newDescription=enchant["Ability Settings"][key].GetFullString();
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ ItemEnchant::ItemEnchant(const std::string_view enchantName)
|
||||
}
|
||||
}
|
||||
|
||||
const ItemEnchantInfo&ItemEnchantInfo::GetEnchant(const std::string_view enchantName){
|
||||
ItemEnchantInfo&ItemEnchantInfo::GetEnchant(const std::string_view enchantName){
|
||||
return ENCHANT_LIST.at(std::string(enchantName));
|
||||
}
|
||||
|
||||
@ -365,14 +365,29 @@ const bool ItemEnchant::HasAttributes()const{
|
||||
const std::optional<Class>&ItemEnchant::GetClass()const{
|
||||
return ItemEnchantInfo::GetEnchant(Name()).GetClass();
|
||||
}
|
||||
const std::vector<std::reference_wrapper<const ItemEnchantInfo>>ItemEnchantInfo::GetAllEnchantsAffectingAbility(const std::string_view ability){
|
||||
std::vector<std::reference_wrapper<const ItemEnchantInfo>>enchantsAffectingList{};
|
||||
const std::vector<std::reference_wrapper<ItemEnchantInfo>>ItemEnchantInfo::GetAllEnchantsAffectingAbility(const std::string_view ability){
|
||||
std::vector<std::reference_wrapper<ItemEnchantInfo>>enchantsAffectingList{};
|
||||
for(const auto&enchantName:game->GetPlayer()->GetEnchants()){
|
||||
const ItemEnchantInfo&enchant{ItemEnchantInfo::GetEnchant(enchantName)};
|
||||
if(enchant.GetAbility()&&(*enchant.GetAbility())->GetName()==ability)enchantsAffectingList.emplace_back(std::cref(enchant));
|
||||
ItemEnchantInfo&enchant{ItemEnchantInfo::GetEnchant(enchantName)};
|
||||
if(enchant.GetAbility()&&(*enchant.GetAbility())->GetName()==ability)enchantsAffectingList.emplace_back(std::ref(enchant));
|
||||
}
|
||||
return enchantsAffectingList;
|
||||
}
|
||||
const ItemEnchantInfo::AbilityDescriptionModifiers ItemEnchantInfo::GetModifiers()const{
|
||||
return modifiers;
|
||||
}
|
||||
datafile&ItemEnchantInfo::GetData(){
|
||||
switch(Category()){
|
||||
case ItemEnchantCategory::CLASS:{
|
||||
return DATA["Item Enchants"]["Class Enchants"][classutils::ClassToString(*GetClass())][Name()];
|
||||
}break;
|
||||
case ItemEnchantCategory::GENERAL:{
|
||||
return DATA["Item Enchants"]["General Enchants"];
|
||||
}break;
|
||||
case ItemEnchantCategory::UNIQUE:{
|
||||
return DATA["Item Enchants"]["Unique Enchants"];
|
||||
}break;
|
||||
}
|
||||
ERR(std::format("An undefined return path was reached for some reason while trying to retrieve data! Category: {}",int(Category())));
|
||||
return DATA;
|
||||
}
|
@ -65,18 +65,18 @@ public:
|
||||
};
|
||||
|
||||
struct AbilityDescriptionModifiers{
|
||||
std::optional<std::string_view>preName;
|
||||
std::optional<std::string_view>postName;
|
||||
std::optional<std::string_view>newName;
|
||||
std::optional<std::string_view>preDescription;
|
||||
std::optional<std::string_view>postDescription;
|
||||
std::optional<std::string_view>newDescription;
|
||||
std::optional<std::string>preName;
|
||||
std::optional<std::string>postName;
|
||||
std::optional<std::string>newName;
|
||||
std::optional<std::string>preDescription;
|
||||
std::optional<std::string>postDescription;
|
||||
std::optional<std::string>newDescription;
|
||||
};
|
||||
|
||||
const static Pixel enchantAttributeCol;
|
||||
|
||||
static void Initialize();
|
||||
const static ItemEnchantInfo&GetEnchant(const std::string_view enchantName);
|
||||
static ItemEnchantInfo&GetEnchant(const std::string_view enchantName);
|
||||
const static std::unordered_map<std::string,ItemEnchantInfo>&GetEnchants();
|
||||
static std::unordered_map<ItemEnchantCategory,Pixel>enchantTextDisplayCol;
|
||||
|
||||
@ -87,10 +87,11 @@ public:
|
||||
const std::optional<AbilitySlot>&GetAbilitySlot()const;
|
||||
const std::optional<Ability*>GetAbility()const; //Get the ability this enchant is tied to.
|
||||
const Pixel&DisplayCol()const;
|
||||
const float GetConfigValue(const std::string_view keyName)const;
|
||||
const float GetConfigValue(const std::string_view keyName)const;
|
||||
const float operator[](const std::string&name)const;
|
||||
const AbilityDescriptionModifiers GetModifiers()const;
|
||||
static const std::vector<std::reference_wrapper<const ItemEnchantInfo>>GetAllEnchantsAffectingAbility(const std::string_view ability);
|
||||
static const std::vector<std::reference_wrapper<ItemEnchantInfo>>GetAllEnchantsAffectingAbility(const std::string_view ability);
|
||||
datafile&GetData();
|
||||
private:
|
||||
class ItemEnchantCategoryData{
|
||||
friend class ItemEnchantInfo;
|
||||
|
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 3
|
||||
#define VERSION_PATCH 0
|
||||
#define VERSION_BUILD 12164
|
||||
#define VERSION_BUILD 12173
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Loading…
x
Reference in New Issue
Block a user