diff --git a/CInterface/Library/PokemonSpecies.cpp b/CInterface/Library/PokemonSpecies.cpp index cba6296..047f4da 100644 --- a/CInterface/Library/PokemonSpecies.cpp +++ b/CInterface/Library/PokemonSpecies.cpp @@ -4,9 +4,16 @@ using namespace PkmnLib::Library; export uint8_t PkmnLib_PokemonSpecies_Construct(const PokemonSpecies*& out, uint16_t id, const char* name, const PokemonForme* defaultForme, float genderRatio, - const char* growthRate, uint8_t captureRate, uint8_t baseHappiness) { - Try(auto cName = ArbUt::StringView(name); auto cGrowthRate = ArbUt::StringView(growthRate); - out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness);) + const char* growthRate, uint8_t captureRate, uint8_t baseHappiness, + const char* const* eggGroupsRaw, size_t eggGroupsLength) { + + Try( + ArbUt::List eggGroups(eggGroupsLength); + for (size_t i = 0; i < eggGroupsLength; i++) { eggGroups.Append(ArbUt::StringView(eggGroupsRaw[i])); } + auto cName = ArbUt::StringView(name); + auto cGrowthRate = ArbUt::StringView(growthRate); + out = new PokemonSpecies(id, cName, defaultForme, genderRatio, cGrowthRate, captureRate, baseHappiness, + eggGroups);) } export void PkmnLib_PokemonSpecies_Destruct(const PokemonSpecies* p) { delete p; } @@ -22,4 +29,11 @@ export uint8_t PkmnLib_PokemonSpecies_GetEvolution(const PokemonSpecies* p, size export uint8_t PkmnLib_PokemonSpecies_GetEvolutions(const PokemonSpecies* p, const EvolutionData* const*& out) { Try(out = p->GetEvolutions().RawData()); +} + +export size_t PkmnLib_PokemonSpecies_GetEggGroupCount(const PokemonSpecies* p) { + return p->GetEggGroups().Count(); +} +export const char* PkmnLib_PokemonSpecies_GetEggGroup(const PokemonSpecies* p, size_t index){ + return p->GetEggGroups()[index].c_str(); } \ No newline at end of file diff --git a/src/Library/Species/PokemonSpecies.hpp b/src/Library/Species/PokemonSpecies.hpp index dbc5153..479901f 100644 --- a/src/Library/Species/PokemonSpecies.hpp +++ b/src/Library/Species/PokemonSpecies.hpp @@ -10,12 +10,14 @@ namespace PkmnLib::Library { private: uint8_t _baseHappiness; ArbUt::UniquePtrList _evolutions; + ArbUt::List _eggGroups; public: PokemonSpecies(uint16_t id, const ArbUt::StringView& name, const PokemonForme* defaultForme, float genderRatio, - const ArbUt::StringView& growthRate, uint8_t captureRate, uint8_t baseHappiness) noexcept + const ArbUt::StringView& growthRate, uint8_t captureRate, uint8_t baseHappiness, + const ArbUt::List& eggGroups) noexcept : CreatureSpecies(id, name, defaultForme, genderRatio, growthRate, captureRate), - _baseHappiness(baseHappiness) {} + _baseHappiness(baseHappiness), _eggGroups(eggGroups) {} ~PokemonSpecies() override = default; @@ -41,6 +43,9 @@ namespace PkmnLib::Library { inline void AddEvolution(const EvolutionData* data) noexcept { _evolutions.Append(data); } const ArbUt::UniquePtrList& GetEvolutions() const noexcept { return _evolutions; } + + bool HasEggGroup(const ArbUt::StringView& sv) const noexcept { return _eggGroups.Contains(sv); } + const ArbUt::List& GetEggGroups() const noexcept { return _eggGroups; } }; } diff --git a/tests/LibraryTests/SpeciesLibraryTests.cpp b/tests/LibraryTests/SpeciesLibraryTests.cpp index 4048519..c2c1523 100644 --- a/tests/LibraryTests/SpeciesLibraryTests.cpp +++ b/tests/LibraryTests/SpeciesLibraryTests.cpp @@ -17,7 +17,7 @@ TEST_CASE("Able to build, destroy and insert library", "library") { "default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100)); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); delete lib; } @@ -30,7 +30,7 @@ TEST_CASE("Able to insert and retrieve from library", "library") { "default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100)); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); auto val = lib->Get("foo"_cnc); REQUIRE(val->GetName() == "foo"); delete lib; diff --git a/tests/LibraryTests/SpeciesTests.cpp b/tests/LibraryTests/SpeciesTests.cpp index 62e50d2..7508bfc 100644 --- a/tests/LibraryTests/SpeciesTests.cpp +++ b/tests/LibraryTests/SpeciesTests.cpp @@ -9,7 +9,7 @@ TEST_CASE("Able to create and destroy species", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); delete species; } @@ -20,7 +20,7 @@ TEST_CASE("Able to get default forme", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); auto forme = species->GetDefaultForme(); REQUIRE(forme != nullptr); @@ -35,7 +35,7 @@ TEST_CASE("Able to get default forme name", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); auto forme = species->GetDefaultForme(); REQUIRE(forme != nullptr); @@ -51,7 +51,7 @@ TEST_CASE("Able to get species name", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetName() == "foo"); @@ -65,7 +65,7 @@ TEST_CASE("Able to get species id", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetId() == 1); @@ -79,7 +79,7 @@ TEST_CASE("Able to get species gender ratio", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetGenderRate() == 0.5f); @@ -93,7 +93,7 @@ TEST_CASE("Able to get species growth rate", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetGrowthRate() == "testGrowthRate"); @@ -107,7 +107,7 @@ TEST_CASE("Able to get species capture rate", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetCaptureRate() == 100); @@ -121,7 +121,7 @@ TEST_CASE("Able to get species base happiness", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); REQUIRE(species->GetBaseHappiness() == 100); @@ -135,14 +135,14 @@ TEST_CASE("Able to set and get evolution", "library") { CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); auto species2 = new PkmnLib::Library::PokemonSpecies( 2, "bar"_cnc, new PkmnLib::Library::PokemonForme("default"_cnc, 1.0f, 1.0f, 100, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc}); species->AddEvolution(PkmnLib::Library::EvolutionData::CreateLevelEvolution(16, species2)); auto& evolutions = species->GetEvolutions(); diff --git a/tests/TestLibrary/TestLibrary.cpp b/tests/TestLibrary/TestLibrary.cpp index 0b993b9..27cb62c 100644 --- a/tests/TestLibrary/TestLibrary.cpp +++ b/tests/TestLibrary/TestLibrary.cpp @@ -11,7 +11,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { "default"_cnc, 1.0f, 1.0f, 236, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100)); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); lib->Insert("testSpecies2"_cnc, new PkmnLib::Library::PokemonSpecies( 2, "testSpecies2"_cnc, @@ -19,7 +19,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { "default"_cnc, 1.0f, 1.0f, 306, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100)); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); lib->Insert("statTestSpecies1"_cnc, new PkmnLib::Library::PokemonSpecies( 3, "statTestSpecies1"_cnc, @@ -27,7 +27,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { "default"_cnc, 1.0f, 1.0f, 236, {0}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100)); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); lib->Insert("testSpecies3"_cnc, new PkmnLib::Library::PokemonSpecies( 2, "testSpecies3"_cnc, @@ -35,7 +35,7 @@ PkmnLib::Library::SpeciesLibrary* TestLibrary::BuildSpeciesLibrary() { "default"_cnc, 1.0f, 1.0f, 236, {0, 4}, CreatureLib::Library::StatisticSet(100, 100, 100, 100, 100, 100), {"testAbility"_cnc}, {"testHiddenAbility"_cnc}, new CreatureLib::Library::LearnableAttacks(100)), - 0.5f, "testGrowthRate"_cnc, 100, 100)); + 0.5f, "testGrowthRate"_cnc, 100, 100, {"testEggGroup"_cnc})); return lib; }