Implements TryGet functions on several libraries.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
dba271681d
commit
bb9b9609a6
|
@ -1,5 +1,16 @@
|
|||
#include "AttackLibrary.hpp"
|
||||
|
||||
bool CreatureLib::Library::AttackLibrary::TryGetAttack(const std::string& name,
|
||||
const CreatureLib::Library::AttackData*& move) const {
|
||||
auto find = _attacks.find(name);
|
||||
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 {
|
||||
return this->_attacks.at(name);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace CreatureLib::Library {
|
|||
_attacks.clear();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool TryGetAttack(const std::string& name, const AttackData*& move) const;
|
||||
[[nodiscard]] const AttackData* GetAttack(const std::string& name) const;
|
||||
[[nodiscard]] const AttackData* operator[](const std::string& name) const;
|
||||
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
#include "ItemLibrary.hpp"
|
||||
|
||||
bool CreatureLib::Library::ItemLibrary::TryGetItem(const std::string& name,
|
||||
const CreatureLib::Library::Item*& item) const {
|
||||
auto find = this->_items.find(name);
|
||||
if (find == this->_items.end()) {
|
||||
item = nullptr;
|
||||
return false;
|
||||
}
|
||||
item = find->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::Item* CreatureLib::Library::ItemLibrary::GetItem(const std::string& name) const {
|
||||
return this->_items.at(name);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace CreatureLib::Library {
|
|||
: _items(std::unordered_map<std::string, const Item*>(initialCapacity)){};
|
||||
virtual ~ItemLibrary() { _items.clear(); }
|
||||
|
||||
[[nodiscard]] bool TryGetItem(const std::string& name, const Item*& item) const;
|
||||
[[nodiscard]] const Item* GetItem(const std::string& name) const;
|
||||
[[nodiscard]] const Item* operator[](const std::string& name) const;
|
||||
|
||||
|
|
|
@ -1,5 +1,16 @@
|
|||
#include "SpeciesLibrary.hpp"
|
||||
|
||||
bool CreatureLib::Library::SpeciesLibrary::TryGetSpecies(
|
||||
const std::string& name, const CreatureLib::Library::CreatureSpecies*& outSpecies) const {
|
||||
auto find = _species.find(name);
|
||||
if (find == _species.end()) {
|
||||
outSpecies = nullptr;
|
||||
return false;
|
||||
}
|
||||
outSpecies = find->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
const CreatureLib::Library::CreatureSpecies*
|
||||
CreatureLib::Library::SpeciesLibrary::GetSpecies(const std::string& name) const {
|
||||
return _species.at(name);
|
||||
|
|
|
@ -20,6 +20,7 @@ namespace CreatureLib::Library {
|
|||
_species.clear();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool TryGetSpecies(const std::string& name, const CreatureSpecies*& outSpecies) const;
|
||||
[[nodiscard]] const CreatureSpecies* GetSpecies(const std::string& name) const;
|
||||
[[nodiscard]] const CreatureSpecies* operator[](const std::string& name) const;
|
||||
|
||||
|
|
Loading…
Reference in New Issue