Implement basic library class that other libraries inherit from for performance.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user