C Interface for PokemonSpecies
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-04-16 15:04:53 +02:00
parent c11da2d966
commit 8344f33e95
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 37 additions and 9 deletions

View File

@ -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));
}

View File

@ -8,14 +8,13 @@ namespace PkmnLib::Library {
class PokemonSpecies : public CreatureLib::Library::CreatureSpecies { class PokemonSpecies : public CreatureLib::Library::CreatureSpecies {
private: private:
uint8_t _baseHappiness; uint8_t _baseHappiness;
std::vector<const EvolutionData*> _evolutions; Arbutils::Collections::List<const EvolutionData*> _evolutions;
public: public:
PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, PokemonSpecies(uint16_t id, const Arbutils::CaseInsensitiveConstString& name, const PokemonForme* defaultForme,
const PokemonForme* defaultVariant, float genderRatio, float genderRatio, const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate,
const Arbutils::CaseInsensitiveConstString& growthRate, uint8_t captureRate, uint8_t baseHappiness) noexcept
uint8_t baseHappiness) : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate),
: CreatureSpecies(id, name, defaultVariant, genderRatio, growthRate, captureRate),
_baseHappiness(baseHappiness) {} _baseHappiness(baseHappiness) {}
~PokemonSpecies() override { ~PokemonSpecies() override {
@ -40,8 +39,8 @@ namespace PkmnLib::Library {
return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant(key)); return reinterpret_cast<const PokemonForme*>(CreatureSpecies::GetVariant(key));
} }
inline void AddEvolution(const EvolutionData* data) { _evolutions.push_back(data); } inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); }
const std::vector<const EvolutionData*>& GetEvolutions() const { return _evolutions; } const Arbutils::Collections::List<const EvolutionData*>& GetEvolutions() const noexcept { return _evolutions; }
}; };
} }

View File

@ -146,7 +146,7 @@ TEST_CASE("Able to set and get evolution", "library") {
species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2)); species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2));
auto evolutions = species->GetEvolutions(); auto evolutions = species->GetEvolutions();
REQUIRE(evolutions.size() == 1); REQUIRE(evolutions.Count() == 1);
auto evo = evolutions[0]; auto evo = evolutions[0];
CHECK(evo->GetMethod() == PkmnLib::Library::EvolutionMethod::Level); CHECK(evo->GetMethod() == PkmnLib::Library::EvolutionMethod::Level);
CHECK(evo->GetNewSpecies() == species2); CHECK(evo->GetNewSpecies() == species2);