60 lines
1.9 KiB
C++
60 lines
1.9 KiB
C++
#ifndef PKMNLIB_NATURELIBRARY_HPP
|
|
#define PKMNLIB_NATURELIBRARY_HPP
|
|
|
|
#include <CreatureLib/Core/Exceptions/CreatureException.hpp>
|
|
#include <Arbutils/Random.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;
|
|
uint8_t _current = 0;
|
|
|
|
public:
|
|
NatureLibrary(uint8_t size = 32)
|
|
: _keyLookup(std::unordered_map<std::string, uint8_t>(size)), _natures(std::vector<Nature>(size)) {}
|
|
|
|
uint8_t LoadNature(const std::string& name, const Nature& nature) {
|
|
auto find = _keyLookup.find(name);
|
|
if (find != _keyLookup.end()) {
|
|
auto key = _keyLookup[name];
|
|
_natures[key] = nature;
|
|
return key;
|
|
} else {
|
|
auto key = _current;
|
|
_keyLookup[name] = key;
|
|
_natures[_current++] = nature;
|
|
return key;
|
|
}
|
|
}
|
|
|
|
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]; }
|
|
const Nature* GetNaturePtr(uint8_t id) const { return &_natures[id]; }
|
|
|
|
uint8_t GetNatureIdByName(const std::string& name) const {
|
|
auto find = _keyLookup.find(name);
|
|
if (find == _keyLookup.end()) {
|
|
throw CreatureException("Invalid nature name.");
|
|
}
|
|
return _keyLookup.at(name);
|
|
}
|
|
|
|
uint8_t GetRandomNature(Arbutils::Random rand = Arbutils::Random()) const{
|
|
return rand.Get(_current);
|
|
}
|
|
};
|
|
}
|
|
|
|
#endif // PKMNLIB_NATURELIBRARY_HPP
|