Tweaks and fixes for Item, added C interface.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
461da76f59
commit
33de8424be
|
@ -0,0 +1,28 @@
|
||||||
|
#include "../../src/Library/Items/Item.hpp"
|
||||||
|
#define export extern "C"
|
||||||
|
using namespace CreatureLib::Library;
|
||||||
|
using ConstString = Arbutils::CaseInsensitiveConstString;
|
||||||
|
|
||||||
|
export Item* CreatureLib_Item_Construct(const char* name, ItemCategory category, BattleItemCategory battleCategory,
|
||||||
|
int32_t price, const char* flags[], size_t flagsCount) {
|
||||||
|
std::unordered_set<uint32_t> conversedFlags(flagsCount);
|
||||||
|
for (size_t i = 0; i < flagsCount; i++) {
|
||||||
|
conversedFlags.insert(ConstString::GetHash(flags[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Item(ConstString(name), category, battleCategory, price, conversedFlags);
|
||||||
|
};
|
||||||
|
|
||||||
|
export void CreatureLib_Item_Destruct(const Item* p) { delete p; }
|
||||||
|
|
||||||
|
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
||||||
|
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
|
||||||
|
|
||||||
|
export const char* CreatureLib_Item_GetName(const Item* p) { return p->GetName().c_str(); }
|
||||||
|
SIMPLE_GET_FUNC(Item, GetCategory, ItemCategory);
|
||||||
|
SIMPLE_GET_FUNC(Item, GetBattleCategory, BattleItemCategory);
|
||||||
|
SIMPLE_GET_FUNC(Item, GetPrice, int32_t);
|
||||||
|
|
||||||
|
export bool CreatureLib_Item_HasFlag(const Item* p, const char* key) { return p->HasFlag(ConstString::GetHash(key)); }
|
||||||
|
|
||||||
|
#undef SIMPLE_GET_FUNC
|
|
@ -3,8 +3,10 @@
|
||||||
bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const {
|
bool CreatureLib::Library::Item::HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const {
|
||||||
return this->_flags.find(flag) != this->_flags.end();
|
return this->_flags.find(flag) != this->_flags.end();
|
||||||
}
|
}
|
||||||
|
bool CreatureLib::Library::Item::HasFlag(uint32_t flag) const { return this->_flags.find(flag) != this->_flags.end(); }
|
||||||
|
|
||||||
CreatureLib::Library::Item::Item(const Arbutils::CaseInsensitiveConstString& name,
|
CreatureLib::Library::Item::Item(const Arbutils::CaseInsensitiveConstString& name,
|
||||||
CreatureLib::Library::ItemCategory category,
|
CreatureLib::Library::ItemCategory category,
|
||||||
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
|
CreatureLib::Library::BattleItemCategory battleCategory, int32_t price,
|
||||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags)
|
std::unordered_set<uint32_t> flags)
|
||||||
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
|
: _name(name), _category(category), _battleCategory(battleCategory), _price(price), _flags(flags) {}
|
||||||
|
|
|
@ -14,11 +14,11 @@ namespace CreatureLib::Library {
|
||||||
ItemCategory _category;
|
ItemCategory _category;
|
||||||
BattleItemCategory _battleCategory;
|
BattleItemCategory _battleCategory;
|
||||||
int32_t _price;
|
int32_t _price;
|
||||||
std::unordered_set<Arbutils::CaseInsensitiveConstString> _flags;
|
std::unordered_set<uint32_t> _flags;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Item(const Arbutils::CaseInsensitiveConstString& name, ItemCategory category, BattleItemCategory battleCategory,
|
Item(const Arbutils::CaseInsensitiveConstString& name, ItemCategory category, BattleItemCategory battleCategory,
|
||||||
int32_t price, std::unordered_set<Arbutils::CaseInsensitiveConstString> flags);
|
int32_t price, std::unordered_set<uint32_t> flags);
|
||||||
|
|
||||||
inline const Arbutils::CaseInsensitiveConstString& GetName() const { return _name; }
|
inline const Arbutils::CaseInsensitiveConstString& GetName() const { return _name; }
|
||||||
inline ItemCategory GetCategory() const { return _category; }
|
inline ItemCategory GetCategory() const { return _category; }
|
||||||
|
@ -26,6 +26,7 @@ namespace CreatureLib::Library {
|
||||||
inline const int32_t GetPrice() const { return _price; }
|
inline const int32_t GetPrice() const { return _price; }
|
||||||
|
|
||||||
bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const;
|
bool HasFlag(const Arbutils::CaseInsensitiveConstString& flag) const;
|
||||||
|
bool HasFlag(uint32_t flag) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue