Nature Library C Interface.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a9075d7ef3
commit
bd3e274d3d
|
@ -0,0 +1,23 @@
|
||||||
|
#include "../../src/Library/Natures/NatureLibrary.hpp"
|
||||||
|
#include "../Core.hpp"
|
||||||
|
using namespace PkmnLib::Library;
|
||||||
|
|
||||||
|
export NatureLibrary* PkmnLib_NatureLibrary_Construct(size_t initialCapacity) {
|
||||||
|
return new NatureLibrary(initialCapacity);
|
||||||
|
}
|
||||||
|
export void PkmnLib_NatureLibrary_Destruct(const NatureLibrary* p) { delete p; }
|
||||||
|
|
||||||
|
export uint8_t PkmnLib_NatureLibrary_LoadNature(NatureLibrary* p, const char* name, const Nature* nature) {
|
||||||
|
Try(p->LoadNature(Arbutils::CaseInsensitiveConstString(name), nature);)
|
||||||
|
}
|
||||||
|
export uint8_t PkmnLib_NatureLibrary_GetNatureByName(NatureLibrary* p, const char* name, const Nature*& out) {
|
||||||
|
Try(out = p->GetNatureByName(Arbutils::CaseInsensitiveConstString(name)));
|
||||||
|
}
|
||||||
|
|
||||||
|
export const char* PkmnLib_NatureLibrary_GetRandomNatureName(NatureLibrary* p, Arbutils::Random* rand) {
|
||||||
|
return p->GetRandomNatureName(rand).c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
export uint8_t PkmnLib_NatureLibrary_GetNatureName(NatureLibrary* p, const Nature* nature, const char*& out) {
|
||||||
|
Try(out = p->GetNatureName(nature).c_str());
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ namespace PkmnLib::Library {
|
||||||
Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*> _items;
|
Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*> _items;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NatureLibrary(uint8_t size = 32)
|
explicit NatureLibrary(size_t size = 32) noexcept
|
||||||
: _items(Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*>(size)) {}
|
: _items(Arbutils::Collections::Dictionary<Arbutils::CaseInsensitiveConstString, const Nature*>(size)) {}
|
||||||
|
|
||||||
~NatureLibrary() {
|
~NatureLibrary() {
|
||||||
|
@ -38,6 +38,12 @@ namespace PkmnLib::Library {
|
||||||
auto& map = _items.GetStdMap();
|
auto& map = _items.GetStdMap();
|
||||||
return std::next(std::begin(map), i)->first;
|
return std::next(std::begin(map), i)->first;
|
||||||
}
|
}
|
||||||
|
inline const Arbutils::CaseInsensitiveConstString&
|
||||||
|
GetRandomNatureName(Arbutils::Random* rand) const {
|
||||||
|
auto i = rand->Get(_items.Count());
|
||||||
|
auto& map = _items.GetStdMap();
|
||||||
|
return std::next(std::begin(map), i)->first;
|
||||||
|
}
|
||||||
|
|
||||||
inline Arbutils::CaseInsensitiveConstString GetNatureName(const Nature* nature) {
|
inline Arbutils::CaseInsensitiveConstString GetNatureName(const Nature* nature) {
|
||||||
for (const auto& v : _items) {
|
for (const auto& v : _items) {
|
||||||
|
|
Loading…
Reference in New Issue