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

This commit is contained in:
Deukhoofd 2020-04-18 13:43:05 +02:00
parent 66060c68c0
commit caa353191d
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
5 changed files with 50 additions and 13 deletions

View File

@ -0,0 +1,38 @@
#include "../../src/Battling/Pokemon/Pokemon.hpp"
#include "../Core.hpp"
using namespace PkmnLib::Battling;
export Pokemon* PkmnLib_Pokemon_Construct(const BattleLibrary* library, const PkmnLib::Library::PokemonSpecies* species,
const PkmnLib::Library::PokemonForme* forme, uint8_t level,
uint32_t experience, uint32_t uid, CreatureLib::Library::Gender gender,
uint8_t coloring, const PkmnLib::Library::Item* heldItem,
const char* nickname, bool hiddenAbility, uint8_t abilityIndex,
CreatureLib::Battling::LearnedAttack* const* moves, size_t moveCount,
uint8_t hpIv, uint8_t attIv, uint8_t defIv, uint8_t sAtIv, uint8_t sDeIv,
uint8_t spIv, uint8_t hpEv, uint8_t attEv, uint8_t defEv, uint8_t sAtEv,
uint8_t sDeEv, uint8_t spEv, const PkmnLib::Library::Nature* nature) {
std::string nick(nickname);
Arbutils::Collections::List<CreatureLib::Battling::LearnedAttack*> cMoves(moves, moves + moveCount);
return new Pokemon(library, species, forme, level, experience, uid, gender, coloring, heldItem, nick,
CreatureLib::Library::TalentIndex(hiddenAbility, abilityIndex), cMoves,
CreatureLib::Library::StatisticSet<uint8_t>(hpIv, attIv, defIv, sAtIv, sDeIv, spIv),
CreatureLib::Library::StatisticSet<uint8_t>(hpEv, attEv, defEv, sAtEv, sDeEv, spEv), nature);
};
export void PkmnLib_Pokemon_Destruct(const Pokemon* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType PkmnLib_##type##_##name(const PkmnLib::Battling::type* p) { return p->name(); }
SIMPLE_GET_FUNC(Pokemon, IsShiny, bool)
SIMPLE_GET_FUNC(Pokemon, GetNature, const PkmnLib::Library::Nature*)
#undef SIMPLE_GET_FUNC
export uint8_t PkmnLib_Pokemon_GetIndividualValue(const Pokemon* p, CreatureLib::Library::Statistic stat) {
return p->GetIndividualValue(stat);
}
export uint8_t PkmnLib_Pokemon_GetEffortValue(const Pokemon* p, CreatureLib::Library::Statistic stat) {
return p->GetEffortValue(stat);
}

View File

@ -1,4 +1 @@
#include "Pokemon.hpp"
const PkmnLib::Library::Nature* PkmnLib::Battling::Pokemon::GetNature() const{
return _nature;
}

View File

@ -22,7 +22,7 @@ namespace PkmnLib::Battling {
const Library::PokemonForme* forme, uint8_t level, uint32_t experience, uint32_t uid,
CreatureLib::Library::Gender gender, uint8_t coloring, const Library::Item* heldItem,
const std::string& nickname, const CreatureLib::Library::TalentIndex& talent,
List<CreatureLib::Battling::LearnedAttack*> moves,
const List<CreatureLib::Battling::LearnedAttack*>& moves,
CreatureLib::Library::StatisticSet<uint8_t> individualValues,
CreatureLib::Library::StatisticSet<uint8_t> effortValues, const PkmnLib::Library::Nature* nature)
: CreatureLib::Battling::Creature(library, species, forme, level, experience, uid, gender, coloring,
@ -33,17 +33,19 @@ namespace PkmnLib::Battling {
return dynamic_cast<const Library::PokemonForme*>(GetVariant());
}
bool IsShiny() const { return _coloring == 1; }
inline bool IsShiny() const noexcept { return _coloring == 1; }
const std::vector<LearnedMove*>& GetMoves() const {
return reinterpret_cast<const std::vector<LearnedMove*>&>(_attacks);
const Arbutils::Collections::List<LearnedMove*>& GetMoves() const {
return reinterpret_cast<const Arbutils::Collections::List<LearnedMove*>&>(_attacks);
}
const Library::Nature* GetNature() const;
uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const {
inline const Library::Nature* GetNature() const noexcept { return _nature; }
inline uint8_t GetIndividualValue(CreatureLib::Library::Statistic stat) const {
return _individualValues.GetStat(stat);
}
uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const { return _effortValues.GetStat(stat); }
inline uint8_t GetEffortValue(CreatureLib::Library::Statistic stat) const {
return _effortValues.GetStat(stat);
}
};
}

View File

@ -74,8 +74,8 @@ CScriptArray* GetMoves(const PkmnLib::Battling::Pokemon* obj) {
asIScriptEngine* engine = ctx->GetEngine();
asITypeInfo* t = engine->GetTypeInfoByDecl("array<LearnedMove@>");
auto a = obj->GetMoves();
CScriptArray* arr = CScriptArray::Create(t, a.size());
for (size_t i = 0; i < a.size(); i++) {
CScriptArray* arr = CScriptArray::Create(t, a.Count());
for (size_t i = 0; i < a.Count(); i++) {
arr->SetValue(i, &a[i]);
}
return arr;

View File

@ -321,7 +321,7 @@ TEST_CASE("Validate Pokemon GetMoves in Script") {
->LearnMove("testMove2"_cnc, CreatureLib::Battling::AttackLearnMethod::Unknown)
->Build();
for (size_t i = 0; i < mon->GetMoves().size(); i++) {
for (size_t i = 0; i < mon->GetMoves().Count(); i++) {
auto data = GetScript(mainLib, "testMove"_cnc);
data.Context->SetArgObject(0, const_cast<PkmnLib::Battling::Pokemon*>(mon));