From 52d24922ff6dfbe0b9fb128bbfa0637d147c47cc Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 8 Feb 2020 17:50:27 +0100 Subject: [PATCH] Make type library work case insensitive. --- src/Library/SpeciesLibrary.hpp | 2 +- src/Library/TypeLibrary.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Library/SpeciesLibrary.hpp b/src/Library/SpeciesLibrary.hpp index 9d95686..9b8175f 100644 --- a/src/Library/SpeciesLibrary.hpp +++ b/src/Library/SpeciesLibrary.hpp @@ -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(); } }; } diff --git a/src/Library/TypeLibrary.cpp b/src/Library/TypeLibrary.cpp index 0810960..045cb3e 100644 --- a/src/Library/TypeLibrary.cpp +++ b/src/Library/TypeLibrary.cpp @@ -1,4 +1,5 @@ #include "TypeLibrary.hpp" +#include 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);