Make growth rate library case insensitive, add exception if not found.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f37e27378e
commit
252be18630
|
@ -1,11 +1,31 @@
|
|||
#include "GrowthRateLibrary.hpp"
|
||||
#include <algorithm>
|
||||
#include "../../Core/Exceptions/CreatureException.hpp"
|
||||
|
||||
uint8_t CreatureLib::Library::GrowthRateLibrary::CalculateLevel(const std::string& growthRate,
|
||||
uint32_t experience) const {
|
||||
return _growthRates.at(growthRate)->CalculateLevel(experience);
|
||||
auto g = growthRate;
|
||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
||||
auto find = _growthRates.find(g);
|
||||
if (find == _growthRates.end()) {
|
||||
throw CreatureException("Invalid growth rate was requested.");
|
||||
}
|
||||
return find->second->CalculateLevel(experience);
|
||||
}
|
||||
|
||||
uint32_t CreatureLib::Library::GrowthRateLibrary::CalculateExperience(const std::string& growthRate,
|
||||
uint8_t level) const {
|
||||
return _growthRates.at(growthRate)->CalculateExperience(level);
|
||||
auto g = growthRate;
|
||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
||||
auto find = _growthRates.find(g);
|
||||
if (find == _growthRates.end()) {
|
||||
throw CreatureException("Invalid growth rate was requested.");
|
||||
}
|
||||
return find->second->CalculateExperience(level);
|
||||
}
|
||||
void CreatureLib::Library::GrowthRateLibrary::AddGrowthRate(const std::string& name,
|
||||
CreatureLib::Library::GrowthRate* rate) {
|
||||
auto g = name;
|
||||
std::transform(g.begin(), g.end(), g.begin(), ::tolower);
|
||||
_growthRates.insert({g, rate});
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace CreatureLib::Library {
|
|||
[[nodiscard]] uint8_t CalculateLevel(const std::string& growthRate, uint32_t experience) const;
|
||||
[[nodiscard]] uint32_t CalculateExperience(const std::string& growthRate, uint8_t level) const;
|
||||
|
||||
void AddGrowthRate(std::string name, GrowthRate* rate) { _growthRates.insert({name, rate}); }
|
||||
void AddGrowthRate(const std::string& name, GrowthRate* rate);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue