diff --git a/CInterface/Library/PokemonSpecies.cpp b/CInterface/Library/PokemonSpecies.cpp new file mode 100644 index 0000000..20408a8 --- /dev/null +++ b/CInterface/Library/PokemonSpecies.cpp @@ -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)); +} \ No newline at end of file diff --git a/src/Library/Species/PokemonSpecies.hpp b/src/Library/Species/PokemonSpecies.hpp index 61f13ee..c36cc17 100644 --- a/src/Library/Species/PokemonSpecies.hpp +++ b/src/Library/Species/PokemonSpecies.hpp @@ -8,14 +8,13 @@ namespace PkmnLib::Library { class PokemonSpecies : public CreatureLib::Library::CreatureSpecies { private: uint8_t _baseHappiness; - std::vector _evolutions; + Arbutils::Collections::List _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(CreatureSpecies::GetVariant(key)); } - inline void AddEvolution(const EvolutionData* data) { _evolutions.push_back(data); } - const std::vector& GetEvolutions() const { return _evolutions; } + inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); } + const Arbutils::Collections::List& GetEvolutions() const noexcept { return _evolutions; } }; } diff --git a/tests/LibraryTests/SpeciesTests.cpp b/tests/LibraryTests/SpeciesTests.cpp index a505d9a..7233412 100644 --- a/tests/LibraryTests/SpeciesTests.cpp +++ b/tests/LibraryTests/SpeciesTests.cpp @@ -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);