Support for finding the previous evolution step of a Pokemon.
This commit is contained in:
parent
9274b675e9
commit
5e917b7047
|
@ -0,0 +1,8 @@
|
||||||
|
#include "../../src/Library/Species/SpeciesLibrary.hpp"
|
||||||
|
#include "../Core.hpp"
|
||||||
|
using namespace PkmnLib::Library;
|
||||||
|
|
||||||
|
export const PokemonSpecies* PkmnLib_PokemonLibrary_FindPreEvolution(const SpeciesLibrary* p,
|
||||||
|
const PokemonSpecies* species) {
|
||||||
|
return p->FindPreEvolution(species).GetRaw();
|
||||||
|
}
|
|
@ -1 +1,20 @@
|
||||||
#include "SpeciesLibrary.hpp"
|
#include "SpeciesLibrary.hpp"
|
||||||
|
namespace PkmnLib::Library {
|
||||||
|
ArbUt::BorrowedPtr<const PokemonSpecies>
|
||||||
|
SpeciesLibrary::FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept {
|
||||||
|
if (_preEvolutionCache.Has(species)) {
|
||||||
|
return _preEvolutionCache[species];
|
||||||
|
}
|
||||||
|
for (auto& s : _values) {
|
||||||
|
auto pkmn = (PokemonSpecies*)s.second.get();
|
||||||
|
for (auto& evo : pkmn->GetEvolutions()) {
|
||||||
|
if (evo->GetNewSpecies() == species) {
|
||||||
|
auto non_const = const_cast<SpeciesLibrary*>(this);
|
||||||
|
non_const->_preEvolutionCache[species] = pkmn;
|
||||||
|
return pkmn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
|
|
||||||
namespace PkmnLib::Library {
|
namespace PkmnLib::Library {
|
||||||
class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary {
|
class SpeciesLibrary : public CreatureLib::Library::SpeciesLibrary {
|
||||||
|
ArbUt::Dictionary<ArbUt::BorrowedPtr<const PokemonSpecies>, ArbUt::BorrowedPtr<const PokemonSpecies>>
|
||||||
|
_preEvolutionCache;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
inline bool TryGet(const ArbUt::BasicStringView& name,
|
inline bool TryGet(const ArbUt::BasicStringView& name,
|
||||||
ArbUt::BorrowedPtr<const PokemonSpecies>& outSpecies) const {
|
ArbUt::BorrowedPtr<const PokemonSpecies>& outSpecies) const {
|
||||||
|
@ -26,6 +29,9 @@ namespace PkmnLib::Library {
|
||||||
void Insert(const ArbUt::StringView& name, const PokemonSpecies* species) {
|
void Insert(const ArbUt::StringView& name, const PokemonSpecies* species) {
|
||||||
CreatureLib::Library::SpeciesLibrary::Insert(name, species);
|
CreatureLib::Library::SpeciesLibrary::Insert(name, species);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArbUt::BorrowedPtr<const PokemonSpecies>
|
||||||
|
FindPreEvolution(const ArbUt::BorrowedPtr<const PokemonSpecies>& species) const noexcept;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue