PkmnLib/src/Library/Species/SpeciesLibrary.hpp

44 lines
1.9 KiB
C++
Raw Normal View History

2019-12-29 14:29:52 +00:00
#ifndef PKMNLIB_SPECIESLIBRARY_HPP
#define PKMNLIB_SPECIESLIBRARY_HPP
#include <CreatureLib/Library/SpeciesLibrary.hpp>
2019-12-29 14:29:52 +00:00
#include "PokemonSpecies.hpp"
namespace PkmnLib::Library {
class SpeciesLibrary final : public CreatureLib::Library::SpeciesLibrary {
ArbUt::Dictionary<ArbUt::BorrowedPtr<const PokemonSpecies>, ArbUt::BorrowedPtr<const PokemonSpecies>>
_preEvolutionCache;
2019-12-29 14:29:52 +00:00
public:
SpeciesLibrary(size_t initialCapacity = 32) : CreatureLib::Library::SpeciesLibrary(initialCapacity) {}
2022-05-16 16:16:15 +00:00
inline std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>> TryGet(const ArbUt::StringView& name) const {
2020-12-12 13:25:27 +00:00
auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name);
if (!res.has_value())
return {};
return res.value().ForceAs<const PokemonSpecies>();
}
2022-05-16 16:16:15 +00:00
inline std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>> TryGetByHash(u32 hashedKey) const {
auto res = CreatureLib::Library::SpeciesLibrary::TryGetByHash(hashedKey);
if (!res.has_value())
return {};
return res.value().ForceAs<const PokemonSpecies>();
}
inline ArbUt::BorrowedPtr<const PokemonSpecies> Get(const ArbUt::StringView& name) const {
2020-05-27 15:26:25 +00:00
return CreatureLib::Library::SpeciesLibrary::Get(name).As<const PokemonSpecies>();
2019-12-29 14:29:52 +00:00
}
2022-05-16 16:16:15 +00:00
inline ArbUt::BorrowedPtr<const PokemonSpecies> GetByHash(u32 hashedKey) const {
return CreatureLib::Library::SpeciesLibrary::GetByHash(hashedKey).As<const PokemonSpecies>();
}
2019-12-29 14:29:52 +00:00
2022-06-07 21:23:40 +00:00
ArbUt::BorrowedPtr<const PokemonSpecies> operator[](const ArbUt::StringView& name) const { return Get(name); }
2019-12-29 14:29:52 +00:00
2020-12-12 13:25:27 +00:00
std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>>
FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept;
2019-12-29 14:29:52 +00:00
};
}
#endif // PKMNLIB_SPECIESLIBRARY_HPP