#ifndef PKMNLIB_NATURELIBRARY_HPP #define PKMNLIB_NATURELIBRARY_HPP #include #include #include #include #include "Nature.hpp" namespace PkmnLib::Library { class NatureLibrary { private: ArbUt::StringViewDictionary> _items; public: explicit NatureLibrary(size_t size = 32) noexcept : _items(size) {} ~NatureLibrary() = default; inline void LoadNature(const ArbUt::StringView& name, const Nature* nature) { _items.GetStdMap().insert({name, std::unique_ptr(nature)}); } inline ArbUt::BorrowedPtr GetNatureByName(const ArbUt::StringView& name) const { return _items.Get(name); } inline ArbUt::BorrowedPtr GetNatureByHash(u32 hash) const { return _items.GetFromHash(hash); } inline const ArbUt::StringView& GetRandomNatureName(ArbUt::Random rand = ArbUt::Random()) const { auto i = rand.Get(_items.Count()); return std::next(std::begin(_items), i)->first; } inline const ArbUt::StringView& GetNatureName(ArbUt::BorrowedPtr nature) { for (const auto& v : _items) { if (v.second.get() == nature.GetRaw()) { return v.first; } } throw ArbUt::Exception("Nature not found."); } size_t GetNatureCount() const noexcept { return _items.Count(); } inline const ArbUt::StringView& GetNatureFromIndex(size_t index) const { return std::next(std::begin(_items), index)->first; } }; } #endif // PKMNLIB_NATURELIBRARY_HPP