Implements outlines for ItemLibrary, MoveLibrary and implements NatureLibrary.
This commit is contained in:
49
src/Library/Natures/NatureLibrary.hpp
Normal file
49
src/Library/Natures/NatureLibrary.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef PKMNLIB_NATURELIBRARY_HPP
|
||||
#define PKMNLIB_NATURELIBRARY_HPP
|
||||
|
||||
#include <Core/Exceptions/CreatureException.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "Nature.hpp"
|
||||
namespace PkmnLib::Library {
|
||||
class NatureLibrary {
|
||||
private:
|
||||
std::unordered_map<std::string, uint8_t> _keyLookup;
|
||||
std::vector<Nature> _natures;
|
||||
|
||||
public:
|
||||
void LoadNature(const std::string& name, const Nature& nature) {
|
||||
auto find = _keyLookup.find(name);
|
||||
if (find != _keyLookup.end()) {
|
||||
auto key = _keyLookup[name];
|
||||
_natures[key] = nature;
|
||||
} else {
|
||||
_keyLookup[name] = _natures.size();
|
||||
_natures.push_back(nature);
|
||||
}
|
||||
}
|
||||
|
||||
const Nature& GetNatureByName(const std::string& name) const {
|
||||
auto find = _keyLookup.find(name);
|
||||
if (find == _keyLookup.end()) {
|
||||
throw CreatureException("Invalid nature name.");
|
||||
}
|
||||
return _natures[_keyLookup.at(name)];
|
||||
}
|
||||
|
||||
const Nature& GetNature(uint8_t id) const{
|
||||
return _natures[id];
|
||||
}
|
||||
|
||||
uint8_t GetNatureId(const std::string& name) const{
|
||||
auto find = _keyLookup.find(name);
|
||||
if (find == _keyLookup.end()) {
|
||||
throw CreatureException("Invalid nature name.");
|
||||
}
|
||||
return _keyLookup.at(name);
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // PKMNLIB_NATURELIBRARY_HPP
|
||||
Reference in New Issue
Block a user