C Interface for PokemonSpecies
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
c11da2d966
commit
8344f33e95
|
@ -0,0 +1,29 @@
|
|||
#include "../../src/Library/Species/PokemonSpecies.hpp"
|
||||
#include "../Core.hpp"
|
||||
using namespace PkmnLib::Library;
|
||||
|
||||
export const PokemonSpecies* PkmnLib_PokemonSpecies_Construct(uint16_t id, const char* name,
|
||||
const PokemonForme* defaultForme, float genderRatio,
|
||||
const char* growthRate, uint8_t captureRate,
|
||||
uint8_t baseHappiness) {
|
||||
auto cName = Arbutils::CaseInsensitiveConstString(name);
|
||||
auto cGrowthRate = Arbutils::CaseInsensitiveConstString(growthRate);
|
||||
return new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness);
|
||||
}
|
||||
|
||||
export void PkmnLib_PokemonSpecies_Destruct(const PokemonSpecies* p) { delete p; }
|
||||
|
||||
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
||||
export returnType PkmnLib_##type##_##name(const PkmnLib::Library::type* p) { return p->name(); }
|
||||
|
||||
SIMPLE_GET_FUNC(PokemonSpecies, GetBaseHappiness, uint8_t);
|
||||
|
||||
#undef SIMPLE_GET_FUNC
|
||||
|
||||
export void PkmnLib_PokemonSpecies_AddEvolution(PokemonSpecies* p, EvolutionData* evo) { p->AddEvolution(evo); }
|
||||
|
||||
export size_t PkmnLib_PokemonSpecies_GetEvolutionCount(const PokemonSpecies* p) { return p->GetEvolutions().Count(); }
|
||||
|
||||
export uint8_t PkmnLib_PokemonSpecies_GetEvolution(const PokemonSpecies* p, size_t index, const EvolutionData*& out) {
|
||||
Try(out = p->GetEvolutions().At(index));
|
||||
}
|
|
@ -8,14 +8,13 @@ namespace PkmnLib::Library {
|
|||
class PokemonSpecies : public CreatureLib::Library::CreatureSpecies {
|
||||
private:
|
||||
uint8_t _baseHappiness;
|
||||
std::vector<const EvolutionData*> _evolutions;
|
||||
Arbutils::Collections::List<const EvolutionData*> _evolutions;
|
||||
|
||||
public:
|
||||
PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name,
|
||||
const PokemonForme* defaultVariant, float genderRatio,
|
||||
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate,
|
||||
uint8_t baseHappiness)
|
||||
: CreatureSpecies(id, name, defaultVariant, genderRatio, growthRate, captureRate),
|
||||
PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, const PokemonForme* defaultForme,
|
||||
float genderRatio, const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate,
|
||||
uint8_t baseHappiness) noexcept
|
||||
: CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate),
|
||||
_baseHappiness(baseHappiness) {}
|
||||
|
||||
~PokemonSpecies() override {
|
||||
|
@ -40,8 +39,8 @@ namespace PkmnLib::Library {
|
|||
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant(key));
|
||||
}
|
||||
|
||||
inline void AddEvolution(const EvolutionData* data) { _evolutions.push_back(data); }
|
||||
const std::vector<const EvolutionData*>& GetEvolutions() const { return _evolutions; }
|
||||
inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); }
|
||||
const Arbutils::Collections::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; }
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ TEST_CASE("Able to set and get evolution", "library") {
|
|||
|
||||
species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2));
|
||||
auto evolutions = species->GetEvolutions();
|
||||
REQUIRE(evolutions.size() == 1);
|
||||
REQUIRE(evolutions.Count() == 1);
|
||||
auto evo = evolutions[0];
|
||||
CHECK(evo->GetMethod() == PkmnLib::Library::EvolutionMethod::Level);
|
||||
CHECK(evo->GetNewSpecies() == species2);
|
||||
|
|
Loading…
Reference in New Issue