CreatureLib/CInterface/Library/CreatureSpecies.cpp

73 lines
3.6 KiB
C++

#include "../../src/Library/CreatureData/CreatureSpecies.hpp"
#include "../Core.hpp"
using namespace CreatureLib::Library;
export_func u8 CreatureLib_CreatureSpecies_Construct(CreatureSpecies*& out, u16 id, const char* name,
SpeciesVariant* defaultVariant, float genderRatio,
const char* growthRate, u8 captureRate, const char* flags[],
size_t flagsCount) {
Try(std::unordered_set<u32> conversedFlags(flagsCount);
for (size_t i = 0; i < flagsCount; i++) { conversedFlags.insert(ArbUt::StringView::CalculateHash(flags[i])); }
out = new CreatureSpecies(id, ArbUt::StringView(name), defaultVariant, genderRatio,
ArbUt::StringView(growthRate), captureRate, conversedFlags);)
}
export_func void CreatureLib_CreatureSpecies_Destruct(const CreatureSpecies* p) { delete p; }
SIMPLE_GET_FUNC(CreatureSpecies, GetId, u16);
SIMPLE_GET_FUNC(CreatureSpecies, GetGenderRate, float);
SIMPLE_GET_FUNC(CreatureSpecies, GetCaptureRate, u8);
export_func const char* CreatureLib_CreatureSpecies_GetName(const CreatureSpecies* p) { return p->GetName().c_str(); }
export_func const char* CreatureLib_CreatureSpecies_GetGrowthRate(const CreatureSpecies* p) {
return p->GetGrowthRate().c_str();
}
export_func bool CreatureLib_CreatureSpecies_HasVariant(const CreatureSpecies* p, const char* name) {
return p->HasVariant(ArbUt::StringView::CalculateHash(name));
}
export_func bool CreatureLib_CreatureSpecies_HasVariantWithHash(const CreatureSpecies* p, u32 hash) {
return p->HasVariant(hash);
}
export_func bool CreatureLib_CreatureSpecies_TryGetVariant(const CreatureSpecies* p, const char* name,
const SpeciesVariant*& out) {
auto res = p->TryGetVariant(ArbUt::StringView::CalculateHash(name));
if (!res.has_value())
return false;
out = res.value();
return true;
}
export_func bool CreatureLib_CreatureSpecies_TryGetVariantWithHash(const CreatureSpecies* p, u32 hash,
const SpeciesVariant*& out) {
auto res = p->TryGetVariant(hash);
if (!res.has_value())
return false;
out = res.value();
return true;
}
export_func u8 CreatureLib_CreatureSpecies_GetVariant(const SpeciesVariant*& out, const CreatureSpecies* p,
const char* name) {
Try(out = p->GetVariant(ArbUt::StringView::CalculateHash(name)).GetRaw();)
}
export_func u8 CreatureLib_CreatureSpecies_GetVariantWithHash(const SpeciesVariant*& out, const CreatureSpecies* p,
u32 hash) {
Try(out = p->GetVariant(hash).GetRaw();)
}
export_func u8 CreatureLib_CreatureSpecies_SetVariant(CreatureSpecies* p, const char* name, SpeciesVariant* variant) {
Try(p->SetVariant(ArbUt::StringView(name), variant);)
}
export_func Gender CreatureLib_CreatureSpecies_GetRandomGender(CreatureSpecies* p, ArbUt::Random* random) {
return p->GetRandomGender(*random);
}
export_func size_t CreatureLib_CreatureSpecies_GetVariantsCount(CreatureSpecies* p) {
return p->GetVariantsIterator().Count();
}
export_func const SpeciesVariant* const* CreatureLib_CreatureSpecies_GetVariants(CreatureSpecies* p) {
return reinterpret_cast<const SpeciesVariant* const*>(p->GetVariantsIterator().RawData());
}
export_func bool CreatureLib_CreatureSpecies_HasFlag(const CreatureSpecies* p, const char* key) {
return p->HasFlag(ArbUt::StringView::CalculateHash(key));
}