#ifndef PKMNLIB_NATURELIBRARY_HPP #define PKMNLIB_NATURELIBRARY_HPP #include #include #include #include #include "Nature.hpp" namespace PkmnLib::Library { class NatureLibrary { private: std::unordered_map _keyLookup; std::vector _natures; uint8_t _current = 0; public: NatureLibrary(uint8_t size = 32) : _keyLookup(std::unordered_map(size)), _natures(std::vector(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