Make Attack, Item and Species libraries be case insensitive.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-02-13 16:05:27 +01:00
parent 8d4860f553
commit 611198009b
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 42 additions and 12 deletions

View File

@ -2,7 +2,9 @@
bool CreatureLib::Library::AttackLibrary::TryGetAttack(const std::string& name, bool CreatureLib::Library::AttackLibrary::TryGetAttack(const std::string& name,
const CreatureLib::Library::AttackData*& move) const { const CreatureLib::Library::AttackData*& move) const {
auto find = _attacks.find(name); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = _attacks.find(key);
if (find == _attacks.end()) { if (find == _attacks.end()) {
move = nullptr; move = nullptr;
return false; return false;
@ -12,7 +14,9 @@ bool CreatureLib::Library::AttackLibrary::TryGetAttack(const std::string& name,
} }
const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::GetAttack(const std::string& name) const { const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::GetAttack(const std::string& name) const {
return this->_attacks.at(name); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return this->_attacks.at(key);
} }
const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::operator[](const std::string& name) const { const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::operator[](const std::string& name) const {
@ -21,7 +25,13 @@ const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::ope
void CreatureLib::Library::AttackLibrary::LoadAttack(const std::string& name, void CreatureLib::Library::AttackLibrary::LoadAttack(const std::string& name,
const CreatureLib::Library::AttackData* attack) { const CreatureLib::Library::AttackData* attack) {
this->_attacks.insert({name, attack}); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
this->_attacks.insert({key, attack});
} }
void CreatureLib::Library::AttackLibrary::DeleteAttack(const std::string& name) { this->_attacks.erase(name); } void CreatureLib::Library::AttackLibrary::DeleteAttack(const std::string& name) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
this->_attacks.erase(key);
}

View File

@ -2,7 +2,9 @@
bool CreatureLib::Library::ItemLibrary::TryGetItem(const std::string& name, bool CreatureLib::Library::ItemLibrary::TryGetItem(const std::string& name,
const CreatureLib::Library::Item*& item) const { const CreatureLib::Library::Item*& item) const {
auto find = this->_items.find(name); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = this->_items.find(key);
if (find == this->_items.end()) { if (find == this->_items.end()) {
item = nullptr; item = nullptr;
return false; return false;
@ -12,7 +14,9 @@ bool CreatureLib::Library::ItemLibrary::TryGetItem(const std::string& name,
} }
const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::GetItem(const std::string& name) const { const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::GetItem(const std::string& name) const {
return this->_items.at(name); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return this->_items.at(key);
} }
const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::operator[](const std::string& name) const { const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::operator[](const std::string& name) const {
@ -20,7 +24,13 @@ const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::operator[](
} }
void CreatureLib::Library::ItemLibrary::LoadItem(const std::string& name, const CreatureLib::Library::Item* item) { void CreatureLib::Library::ItemLibrary::LoadItem(const std::string& name, const CreatureLib::Library::Item* item) {
this->_items.insert({name, item}); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
this->_items.insert({key, item});
} }
void CreatureLib::Library::ItemLibrary::DeleteItem(const std::string& name) { this->_items.erase(name); } void CreatureLib::Library::ItemLibrary::DeleteItem(const std::string& name) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
this->_items.erase(key);
}

View File

@ -2,7 +2,9 @@
bool CreatureLib::Library::SpeciesLibrary::TryGetSpecies( bool CreatureLib::Library::SpeciesLibrary::TryGetSpecies(
const std::string& name, const CreatureLib::Library::CreatureSpecies*& outSpecies) const { const std::string& name, const CreatureLib::Library::CreatureSpecies*& outSpecies) const {
auto find = _species.find(name); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = _species.find(key);
if (find == _species.end()) { if (find == _species.end()) {
outSpecies = nullptr; outSpecies = nullptr;
return false; return false;
@ -13,7 +15,9 @@ bool CreatureLib::Library::SpeciesLibrary::TryGetSpecies(
const CreatureLib::Library::CreatureSpecies* const CreatureLib::Library::CreatureSpecies*
CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const { CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const {
return _species.at(name); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
return _species.at(key);
} }
const CreatureLib::Library::CreatureSpecies* const CreatureLib::Library::CreatureSpecies*
@ -23,7 +27,13 @@ const CreatureLib::Library::CreatureSpecies*
void CreatureLib::Library::SpeciesLibrary::LoadSpecies(const std::string& name, void CreatureLib::Library::SpeciesLibrary::LoadSpecies(const std::string& name,
const CreatureLib::Library::CreatureSpecies* species) { const CreatureLib::Library::CreatureSpecies* species) {
_species.insert({name, species}); std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
_species.insert({key, species});
} }
void CreatureLib::Library::SpeciesLibrary::DeleteSpecies(const std::string& name) { _species.erase(name); } void CreatureLib::Library::SpeciesLibrary::DeleteSpecies(const std::string& name) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
_species.erase(key);
}