Make type library work case insensitive.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-08 17:50:27 +01:00
parent 925763752f
commit 52d24922ff
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 10 additions and 3 deletions

View File

@ -27,7 +27,7 @@ namespace CreatureLib::Library {
void LoadSpecies(const std::string& name, const CreatureSpecies* species);
void DeleteSpecies(const std::string& name);
size_t GetCount() const { return _species.count(); }
size_t GetCount() const { return _species.size(); }
};
}

View File

@ -1,4 +1,5 @@
#include "TypeLibrary.hpp"
#include <algorithm>
using namespace CreatureLib::Library;
@ -14,10 +15,16 @@ float TypeLibrary::GetSingleEffectiveness(uint8_t attacking, uint8_t defensive)
return _effectiveness[attacking][defensive];
}
uint8_t TypeLibrary::GetTypeId(const std::string& s) const { return _types.at(s); }
uint8_t TypeLibrary::GetTypeId(const std::string& s) const {
std::string key = s;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return _types.at(key);
}
uint8_t TypeLibrary::RegisterType(const std::string& typeName) {
_types.insert({typeName, _types.size()});
std::string key = typeName;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
_types.insert({key, _types.size()});
_effectiveness.resize(_types.size());
for (auto& eff : _effectiveness) {
eff.resize(_types.size(), 1);