Implement basic library class that other libraries inherit from for performance.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-02-15 18:51:21 +01:00
parent a47f60cdf7
commit d6ea16b467
11 changed files with 87 additions and 195 deletions

View File

@@ -1,37 +1 @@
#include "AttackLibrary.hpp"
bool CreatureLib::Library::AttackLibrary::TryGetAttack(const std::string& name,
const CreatureLib::Library::AttackData*& move) const {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
auto find = _attacks.find(key);
if (find == _attacks.end()) {
move = nullptr;
return false;
}
move = find->second;
return true;
}
const CreatureLib::Library::AttackData* CreatureLib::Library::AttackLibrary::GetAttack(const std::string& name) const {
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 {
return GetAttack(name);
}
void CreatureLib::Library::AttackLibrary::LoadAttack(const std::string& name,
const CreatureLib::Library::AttackData* 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) {
std::string key = name;
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
this->_attacks.erase(key);
}