Fixes for FindPreEvolution from C Interface
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user