Fixes for FindPreEvolution from C Interface
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
94de55f933
commit
1f298cef08
|
@ -2,10 +2,16 @@
|
|||
#include "../Core.hpp"
|
||||
using namespace PkmnLib::Library;
|
||||
|
||||
export const PokemonSpecies* PkmnLib_SpeciesLibrary_FindPreEvolution(const SpeciesLibrary* p,
|
||||
export const SpeciesLibrary* PkmnLib_SpeciesLibrary_Construct(size_t initialCapacity) {
|
||||
return new SpeciesLibrary(initialCapacity);
|
||||
};
|
||||
|
||||
export u8 PkmnLib_SpeciesLibrary_FindPreEvolution(const PokemonSpecies*& out, const SpeciesLibrary* p,
|
||||
const PokemonSpecies* species) {
|
||||
Try(
|
||||
auto v = p->FindPreEvolution(species);
|
||||
if (!v.has_value())
|
||||
return nullptr;
|
||||
return v.value().GetRaw();
|
||||
out = nullptr;
|
||||
out = v.value().GetRaw();
|
||||
)
|
||||
}
|
|
@ -2,15 +2,19 @@
|
|||
namespace PkmnLib::Library {
|
||||
std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>>
|
||||
SpeciesLibrary::FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept {
|
||||
if (_preEvolutionCache.Has(species)) {
|
||||
return _preEvolutionCache[species];
|
||||
auto tryGet = _preEvolutionCache.TryGet(species);
|
||||
if (tryGet.has_value()) {
|
||||
return tryGet->get();
|
||||
}
|
||||
for (const auto& s : _values) {
|
||||
auto* pkmn = (PokemonSpecies*)s.second.get();
|
||||
const auto* pkmn = dynamic_cast<const PokemonSpecies*>(s.second.get());
|
||||
if (pkmn == nullptr){
|
||||
continue;
|
||||
}
|
||||
for (const auto& evo : pkmn->GetEvolutions()) {
|
||||
if (evo->GetNewSpecies() == species) {
|
||||
auto* non_const = const_cast<SpeciesLibrary*>(this);
|
||||
non_const->_preEvolutionCache[species] = pkmn;
|
||||
non_const->_preEvolutionCache.Insert(species, pkmn);
|
||||
return pkmn;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ namespace PkmnLib::Library {
|
|||
_preEvolutionCache;
|
||||
|
||||
public:
|
||||
SpeciesLibrary(size_t initialCapacity = 32) : CreatureLib::Library::SpeciesLibrary(initialCapacity) {}
|
||||
|
||||
inline std::optional<ArbUt::BorrowedPtr<const PokemonSpecies>>
|
||||
TryGet(const ArbUt::BasicStringView& name) const {
|
||||
auto res = CreatureLib::Library::SpeciesLibrary::TryGet(name);
|
||||
|
|
Loading…
Reference in New Issue