2019-12-30 15:19:53 +00:00
|
|
|
#ifndef PKMNLIB_NATURELIBRARY_HPP
|
|
|
|
#define PKMNLIB_NATURELIBRARY_HPP
|
|
|
|
|
2022-05-16 16:16:15 +00:00
|
|
|
#include <Arbutils/Collections/StringViewDictionary.hpp>
|
2021-10-30 12:29:57 +00:00
|
|
|
#include <Arbutils/Memory/Memory.hpp>
|
2020-02-27 17:59:15 +00:00
|
|
|
#include <Arbutils/Random.hpp>
|
2020-04-17 16:20:48 +00:00
|
|
|
#include <CreatureLib/Library/Exceptions/CreatureException.hpp>
|
2019-12-30 15:19:53 +00:00
|
|
|
#include "Nature.hpp"
|
2020-06-02 18:37:21 +00:00
|
|
|
|
2019-12-30 15:19:53 +00:00
|
|
|
namespace PkmnLib::Library {
|
|
|
|
class NatureLibrary {
|
|
|
|
private:
|
2022-05-16 16:16:15 +00:00
|
|
|
ArbUt::StringViewDictionary<std::unique_ptr<const Nature>> _items;
|
2019-12-30 15:19:53 +00:00
|
|
|
|
|
|
|
public:
|
2020-06-02 18:37:21 +00:00
|
|
|
explicit NatureLibrary(size_t size = 32) noexcept : _items(size) {}
|
2019-12-31 09:39:20 +00:00
|
|
|
|
2020-06-02 18:37:21 +00:00
|
|
|
~NatureLibrary() = default;
|
2020-04-17 16:50:26 +00:00
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
inline void LoadNature(const ArbUt::StringView& name, const Nature* nature) {
|
2022-05-16 16:16:15 +00:00
|
|
|
_items.GetStdMap().insert({name, std::unique_ptr<const Nature>(nature)});
|
2019-12-30 15:19:53 +00:00
|
|
|
}
|
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
inline ArbUt::BorrowedPtr<const Nature> GetNatureByName(const ArbUt::StringView& name) const {
|
2022-05-16 16:16:15 +00:00
|
|
|
return _items.Get(name);
|
|
|
|
}
|
|
|
|
|
2022-06-07 21:23:40 +00:00
|
|
|
inline ArbUt::BorrowedPtr<const Nature> GetNatureByHash(u32 hash) const { return _items.GetFromHash(hash); }
|
2020-01-02 19:26:01 +00:00
|
|
|
|
2020-07-04 13:50:30 +00:00
|
|
|
inline const ArbUt::StringView& GetRandomNatureName(ArbUt::Random rand = ArbUt::Random()) const {
|
2022-05-16 16:16:15 +00:00
|
|
|
auto i = rand.Get(_items.Count());
|
2020-06-02 18:37:21 +00:00
|
|
|
return std::next(std::begin(_items), i)->first;
|
2020-01-02 19:26:01 +00:00
|
|
|
}
|
2020-04-17 16:39:04 +00:00
|
|
|
|
2022-05-16 16:16:15 +00:00
|
|
|
inline const ArbUt::StringView& GetNatureName(ArbUt::BorrowedPtr<const Nature> nature) {
|
2020-04-17 18:03:01 +00:00
|
|
|
for (const auto& v : _items) {
|
2020-06-02 18:37:21 +00:00
|
|
|
if (v.second.get() == nature.GetRaw()) {
|
2020-04-17 16:39:04 +00:00
|
|
|
return v.first;
|
|
|
|
}
|
|
|
|
}
|
2020-08-16 09:12:04 +00:00
|
|
|
throw ArbUt::Exception("Nature not found.");
|
2020-04-17 16:39:04 +00:00
|
|
|
}
|
2020-08-09 09:31:22 +00:00
|
|
|
|
2022-05-16 16:16:15 +00:00
|
|
|
size_t GetNatureCount() const noexcept { return _items.Count(); }
|
2020-08-09 09:31:22 +00:00
|
|
|
inline const ArbUt::StringView& GetNatureFromIndex(size_t index) const {
|
|
|
|
return std::next(std::begin(_items), index)->first;
|
|
|
|
}
|
2019-12-30 15:19:53 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PKMNLIB_NATURELIBRARY_HPP
|