Tweaks and fixes for AttackData, added C interface.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2020-03-02 15:38:18 +01:00
parent 81ae0e8454
commit 461da76f59
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
3 changed files with 43 additions and 3 deletions

View File

@ -0,0 +1,36 @@
#include "../../src/Library/Attacks/AttackData.hpp"
#define export extern "C"
using namespace CreatureLib::Library;
export AttackData* CreatureLib_AttackData_Construct(const char* name, uint8_t type, AttackCategory category,
uint8_t power, uint8_t accuracy, uint8_t baseUsage,
AttackTarget target, int8_t priority, 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 AttackData(ConstString(name), type, category, power, accuracy, baseUsage, target, priority,
conversedFlags);
};
export void CreatureLib_AttackData_Destruct(const AttackData* 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_AttackData_GetName(const AttackData* p) { return p->GetName().c_str(); }
SIMPLE_GET_FUNC(AttackData, GetType, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetCategory, AttackCategory);
SIMPLE_GET_FUNC(AttackData, GetBasePower, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetAccuracy, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetBaseUsages, uint8_t);
SIMPLE_GET_FUNC(AttackData, GetTarget, AttackTarget);
SIMPLE_GET_FUNC(AttackData, GetPriority, int8_t);
export bool CreatureLib_AttackData_HasFlag(const AttackData* p, const char* key) {
return p->HasFlag(ConstString::GetHash(key));
}
#undef SIMPLE_GET_FUNC

View File

@ -5,10 +5,13 @@ CreatureLib::Library::AttackData::AttackData(const ConstString& name, uint8_t ty
CreatureLib::Library::AttackCategory category, uint8_t power,
uint8_t accuracy, uint8_t baseUsage,
CreatureLib::Library::AttackTarget target, int8_t priority,
std::unordered_set<Arbutils::CaseInsensitiveConstString> flags)
std::unordered_set<uint32_t> flags)
: _name(std::move(name)), _type(type), _category(category), _basePower(power), _accuracy(accuracy),
_baseUsages(baseUsage), _target(target), _priority(priority), _flags(std::move(flags)) {}
bool CreatureLib::Library::AttackData::HasFlag(const ConstString& key) const {
return this->_flags.find(key) != this->_flags.end();
}
bool CreatureLib::Library::AttackData::HasFlag(uint32_t key) const {
return this->_flags.find(key) != this->_flags.end();
}

View File

@ -20,11 +20,11 @@ namespace CreatureLib::Library {
uint8_t _baseUsages;
AttackTarget _target;
int8_t _priority;
std::unordered_set<ConstString> _flags;
std::unordered_set<uint32_t> _flags;
public:
AttackData(const ConstString& name, uint8_t type, AttackCategory category, uint8_t power, uint8_t accuracy,
uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set<ConstString> flags);
uint8_t baseUsage, AttackTarget target, int8_t priority, std::unordered_set<uint32_t> flags);
virtual ~AttackData() = default;
inline const ConstString& GetName() const { return _name; }
@ -37,6 +37,7 @@ namespace CreatureLib::Library {
inline int8_t GetPriority() const { return _priority; }
bool HasFlag(const ConstString& key) const;
bool HasFlag(uint32_t keyHash) const;
};
}