Fixes and tweaks for CreatureParty, added C Interface.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-08 13:53:58 +01:00
parent 1d18066bcc
commit bbe99da0f0
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
2 changed files with 30 additions and 2 deletions

View File

@ -0,0 +1,24 @@
#include "../../src/Battling/Models/CreatureParty.hpp"
#define export extern "C"
using namespace CreatureLib::Battling;
export CreatureParty* CreatureLib_CreatureParty_ConstructWithSize(size_t size) { return new CreatureParty(size); }
export CreatureParty* CreatureLib_CreatureParty_ConstructFromArray(Creature* creatures[], size_t size) {
return new CreatureParty(std::vector<Creature*>(creatures, creatures + size));
}
export void CreatureLib_CreatureParty_Destruct(const CreatureParty* p) { delete p; }
export Creature* CreatureLib_CreatureParty_GetAtIndex(const CreatureParty* p, size_t index) {
return p->GetAtIndex(index);
}
export void CreatureLib_CreatureParty_Switch(CreatureParty* p, size_t a, size_t b) { p->Switch(a, b); }
export bool CreatureLib_CreatureParty_HasAvailableCreatures(const CreatureParty* p) {
return p->HasAvailableCreatures();
}
export size_t CreatureLib_CreatureParty_GetLength(const CreatureParty* p) { return p->GetLength(); }
export Creature** CreatureLib_CreatureParty_GetParty(CreatureParty* p) { return p->GetParty().data(); }

View File

@ -9,6 +9,7 @@ namespace CreatureLib::Battling {
std::vector<Creature*> _party;
public:
CreatureParty(size_t size) : _party(size) {}
CreatureParty(std::vector<Creature*> party) : _party(party) {}
CreatureParty(std::initializer_list<Creature*> party) : _party(party) {}
@ -18,9 +19,9 @@ namespace CreatureLib::Battling {
}
}
Creature* GetAtIndex(int index) const { return _party[index]; }
Creature* GetAtIndex(size_t index) const { return _party[index]; }
void Switch(int a, int b) {
void Switch(size_t a, size_t b) {
auto ca = _party[a];
_party[a] = _party[b];
_party[b] = ca;
@ -38,6 +39,9 @@ namespace CreatureLib::Battling {
}
std::vector<Creature*>& GetParty() { return _party; }
const std::vector<Creature*>& GetParty() const { return _party; }
size_t GetLength() const { return _party.size(); }
};
}