From 82e0774b40ce1deb93f27337d6d7bc741c91e759 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Thu, 16 Apr 2020 16:18:09 +0200 Subject: [PATCH] C Interface for EvolutionData --- CInterface/Library/EvolutionData.cpp | 64 ++++++++++++++++++++++++ src/Library/Evolutions/EvolutionData.cpp | 26 ++++++++++ src/Library/Evolutions/EvolutionData.hpp | 38 ++++---------- 3 files changed, 101 insertions(+), 27 deletions(-) create mode 100644 CInterface/Library/EvolutionData.cpp diff --git a/CInterface/Library/EvolutionData.cpp b/CInterface/Library/EvolutionData.cpp new file mode 100644 index 0000000..64829cd --- /dev/null +++ b/CInterface/Library/EvolutionData.cpp @@ -0,0 +1,64 @@ +#include "../../src/Library/Evolutions/EvolutionData.hpp" +#include "../Core.hpp" +using namespace PkmnLib::Library; + +export const EvolutionData* PkmnLib_EvolutionData_CreateLevelEvolution(uint8_t level, const PokemonSpecies* into) { + return EvolutionData::CreateLevelEvolution(level, into); +} +export const EvolutionData* PkmnLib_EvolutionData_CreateFriendshipEvolution(uint8_t friendship, + const PokemonSpecies* into) { + return EvolutionData::CreateFriendshipEvolution(friendship, into); +} +export const EvolutionData* PkmnLib_EvolutionData_CreateKnownMoveEvolution(const MoveData* move, + const PokemonSpecies* into) { + return EvolutionData::CreateKnownMoveEvolution(move, into); +} +export const EvolutionData* PkmnLib_EvolutionData_CreateLocationEvolution(const char* location, + const PokemonSpecies* into) { + return EvolutionData::CreateLocationEvolution(Arbutils::CaseInsensitiveConstString(location), into); +} +export const EvolutionData* PkmnLib_Evolution_CreateTimeEvolution(TimeOfDay time, const PokemonSpecies* into) { + return EvolutionData::CreateTimeEvolution(time, into); +} +export const EvolutionData* PkmnLib_Evolution_CreateItemEvolution(const Item* item, const PokemonSpecies* into) { + return EvolutionData::CreateHeldItemEvolution(item, into); +} +export const EvolutionData* PkmnLib_Evolution_CreateGenderBasedEvolution(CreatureLib::Library::Gender gender, + uint8_t level, const PokemonSpecies* into) { + return EvolutionData::CreateGenderBasedEvolution(gender, level, into); +} +export const EvolutionData* PkmnLib_Evolution_CreateItemUseEvolution(const Item* item, const PokemonSpecies* into) { + return EvolutionData::CreateItemUseEvolution(item, into); +} + +export const EvolutionData* PkmnLib_Evolution_CreateItemUseWithGenderEvolution(const Item* item, + CreatureLib::Library::Gender gender, + const PokemonSpecies* into) { + return EvolutionData::CreateItemUseWithGenderEvolution(item, gender, into); +} +export const EvolutionData* PkmnLib_Evolution_CreateTradeEvolution(const PokemonSpecies* into) { + return EvolutionData::CreateTradeEvolution(into); +} +export const EvolutionData* PkmnLib_Evolution_CreateTradeWithItemEvolution(const Item* item, + const PokemonSpecies* into) { + return EvolutionData::CreateTradeWithItemEvolution(item, into); +} +export const EvolutionData* PkmnLib_Evolution_CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, + const PokemonSpecies* into) { + return EvolutionData::CreateTradeWithSpeciesEvolution(traded, into); +} +export const EvolutionData* PkmnLib_Evolution_CreateCustomEvolution(const CreatureLib::Library::EffectParameter** data, + size_t dataLength, const PokemonSpecies* into) { + auto list = Arbutils::Collections::List(data, data + dataLength); + return EvolutionData::CreateCustomEvolution(list, into); +} + +export EvolutionMethod PkmnLib_Evolution_GetMethod(const EvolutionData* data) { return data->GetMethod(); } +export const PokemonSpecies* PkmnLib_Evolution_GetNewSpecies(const EvolutionData* data) { + return data->GetNewSpecies(); +} +export size_t PkmnLib_Evolution_GetDataCount(const EvolutionData* data) { return data->GetDataCount(); } +export uint8_t PkmnLib_Evolution_GetData(const EvolutionData* data, size_t index, + const CreatureLib::Library::EffectParameter*& out) { + Try(out = data->GetData(index)); +} diff --git a/src/Library/Evolutions/EvolutionData.cpp b/src/Library/Evolutions/EvolutionData.cpp index 82fad07..9c8e3ff 100644 --- a/src/Library/Evolutions/EvolutionData.cpp +++ b/src/Library/Evolutions/EvolutionData.cpp @@ -1,5 +1,7 @@ #include "EvolutionData.hpp" +#include "../Items/Item.hpp" #include "../Moves/MoveData.hpp" +#include "../Species/PokemonSpecies.hpp" using namespace PkmnLib::Library; const EvolutionData* PkmnLib::Library::EvolutionData::CreateKnownMoveEvolution(const MoveData* move, @@ -7,3 +9,27 @@ const EvolutionData* PkmnLib::Library::EvolutionData::CreateKnownMoveEvolution(c return new EvolutionData(EvolutionMethod::KnownMove, {new CreatureLib::Library::EffectParameter(move->GetName())}, into); } +const EvolutionData* EvolutionData::CreateHeldItemEvolution(const Item* item, const PokemonSpecies* into) { + return new EvolutionData(EvolutionMethod::HoldsItem, {new CreatureLib::Library::EffectParameter(item->GetName())}, + into); +} +const EvolutionData* EvolutionData::CreateItemUseEvolution(const Item* item, const PokemonSpecies* into) { + return new EvolutionData(EvolutionMethod::EvolutionItemUse, + {new CreatureLib::Library::EffectParameter(item->GetName())}, into); +} +const EvolutionData* EvolutionData::CreateItemUseWithGenderEvolution(const Item* item, + CreatureLib::Library::Gender gender, + const PokemonSpecies* into) { + return new EvolutionData(EvolutionMethod::EvolutionItemUseWithGender, + {new CreatureLib::Library::EffectParameter(item->GetName()), + new CreatureLib::Library::EffectParameter((int64_t)gender)}, + into); +} +const EvolutionData* EvolutionData::CreateTradeWithItemEvolution(const Item* item, const PokemonSpecies* into) { + return new EvolutionData(EvolutionMethod::TradeWithHeldItem, + {new CreatureLib::Library::EffectParameter(item->GetName())}, into); +} +const EvolutionData* EvolutionData::CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, const PokemonSpecies* into) { + return new EvolutionData(EvolutionMethod::TradeWithSpecificPokemon, + {new CreatureLib::Library::EffectParameter(traded->GetName())}, into); +} diff --git a/src/Library/Evolutions/EvolutionData.hpp b/src/Library/Evolutions/EvolutionData.hpp index 945ffa2..b089ae5 100644 --- a/src/Library/Evolutions/EvolutionData.hpp +++ b/src/Library/Evolutions/EvolutionData.hpp @@ -49,10 +49,7 @@ namespace PkmnLib::Library { return new EvolutionData(EvolutionMethod::TimeBased, {new CreatureLib::Library::EffectParameter((int64_t)time)}, into); } - static inline const EvolutionData* CreateHeldItemEvolution(const Item* item, const PokemonSpecies* into) { - return new EvolutionData(EvolutionMethod::HoldsItem, {new CreatureLib::Library::EffectParameter(item)}, - into); - } + static const EvolutionData* CreateHeldItemEvolution(const Item* item, const PokemonSpecies* into); static inline const EvolutionData* CreateGenderBasedEvolution(CreatureLib::Library::Gender gender, uint8_t level, const PokemonSpecies* into) { return new EvolutionData(EvolutionMethod::IsGenderAndLevel, @@ -60,38 +57,25 @@ namespace PkmnLib::Library { new CreatureLib::Library::EffectParameter((int64_t)level)}, into); } - static inline const EvolutionData* CreateItemUseEvolution(const Item* item, const PokemonSpecies* into) { - return new EvolutionData(EvolutionMethod::EvolutionItemUse, - {new CreatureLib::Library::EffectParameter(item)}, into); - } - static inline const EvolutionData* CreateItemUseWithGenderEvolution(const Item* item, - CreatureLib::Library::Gender gender, - const PokemonSpecies* into) { - return new EvolutionData(EvolutionMethod::EvolutionItemUseWithGender, - {new CreatureLib::Library::EffectParameter(item), - new CreatureLib::Library::EffectParameter((int64_t)gender)}, - into); - } + static const EvolutionData* CreateItemUseEvolution(const Item* item, const PokemonSpecies* into); + static const EvolutionData* CreateItemUseWithGenderEvolution(const Item* item, + CreatureLib::Library::Gender gender, + const PokemonSpecies* into); static inline const EvolutionData* CreateTradeEvolution(const PokemonSpecies* into) { return new EvolutionData(EvolutionMethod::Trade, {}, into); } - static inline const EvolutionData* CreateTradeWithItemEvolution(const Item* item, const PokemonSpecies* into) { - return new EvolutionData(EvolutionMethod::TradeWithHeldItem, - {new CreatureLib::Library::EffectParameter(item)}, into); - } - static inline const EvolutionData* CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, - const PokemonSpecies* into) { - return new EvolutionData(EvolutionMethod::TradeWithSpecificPokemon, - {new CreatureLib::Library::EffectParameter(traded)}, into); - } + static const EvolutionData* CreateTradeWithItemEvolution(const Item* item, const PokemonSpecies* into); + static const EvolutionData* CreateTradeWithSpeciesEvolution(const PokemonSpecies* traded, + const PokemonSpecies* into); static inline const EvolutionData* CreateCustomEvolution(const Arbutils::Collections::List& data, const PokemonSpecies* into) { return new EvolutionData(EvolutionMethod::Custom, data, into); } - [[nodiscard]] inline const PokemonSpecies* GetNewSpecies() const { return _evolvesInto; } - [[nodiscard]] inline EvolutionMethod GetMethod() const { return _method; } + [[nodiscard]] inline const PokemonSpecies* GetNewSpecies() const noexcept { return _evolvesInto; } + [[nodiscard]] inline EvolutionMethod GetMethod() const noexcept { return _method; } + [[nodiscard]] inline size_t GetDataCount() const noexcept { return _evolutionData.Count(); } [[nodiscard]] inline const CreatureLib::Library::EffectParameter* GetData(size_t index) const { return _evolutionData.At(index); }