CreatureLib/CInterface/Library/CreatureSpecies.cpp

58 lines
3.0 KiB
C++

#include "../../src/Library/CreatureData/CreatureSpecies.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Library;
export uint8_t CreatureLib_CreatureSpecies_Construct(CreatureSpecies*& out, uint16_t id, const char* name,
SpeciesVariant* defaultVariant, float genderRatio,
const char* growthRate, uint8_t captureRate) {
Try(out = new CreatureSpecies(id, Arbutils::CaseInsensitiveConstString(name), defaultVariant, genderRatio,
Arbutils::CaseInsensitiveConstString(growthRate), captureRate);)
}
export void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; }
#define SIMPLE_GET_FUNC(type, name, returnType) \
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
SIMPLE_GET_FUNC(CreatureSpecies, GetId, uint16_t);
SIMPLE_GET_FUNC(CreatureSpecies, GetGenderRate, float);
SIMPLE_GET_FUNC(CreatureSpecies, GetCaptureRate, uint8_t);
export const char* CreatureLib_CreatureSpecies_GetName(const CreatureSpecies* p) { return p->GetName().c_str(); }
export const char* CreatureLib_CreatureSpecies_GetGrowthRate(const CreatureSpecies* p) {
return p->GetGrowthRate().c_str();
}
export bool CreatureLib_CreatureSpecies_HasVariant(const CreatureSpecies* p, const char* name) {
return p->HasVariant(Arbutils::CaseInsensitiveConstString::GetHash(name));
}
export bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureSpecies* p, uint32_t hash) {
return p->HasVariant(hash);
}
export bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p, const char* name,
const SpeciesVariant*& out) {
borrowed_ptr<const SpeciesVariant> o;
auto res = p->TryGetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name), o);
out = o.GetRaw();
return res;
}
export bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpecies* p, uint32_t hash,
const SpeciesVariant*& out) {
borrowed_ptr<const SpeciesVariant> o;
auto res = p->TryGetVariant(hash, o);
out = o.GetRaw();
return res;
}
export uint8_t CreatureLib_CreatureSpecies_GetVariant(const SpeciesVariant*& out, const CreatureSpecies* p,
const char* name) {
Try(out = p->GetVariant(Arbutils::CaseInsensitiveConstString::GetHash(name)).GetRaw();)
}
export uint8_t CreatureLib_CreatureSpecies_GetVariantWithHash(const SpeciesVariant* out, const CreatureSpecies* p,
uint32_t hash) {
Try(out = p->GetVariant(hash).GetRaw();)
}
export uint8_t CreatureLib_CreatureSpecies_SetVariant(CreatureSpecies* p, const char* name, SpeciesVariant* variant) {
Try(p->SetVariant(Arbutils::CaseInsensitiveConstString(name), variant);)
}
#undef SIMPLE_GET_FUNC