Added C interface for EventData.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
cc43e4fb8a
commit
3efd7a6974
|
@ -0,0 +1,19 @@
|
|||
#include "../../src/Battling/EventHooks/EventData.hpp"
|
||||
#define export extern "C"
|
||||
using namespace CreatureLib::Battling;
|
||||
|
||||
export void CreatureLib_EventData_Destruct(const EventData* p) { delete p; }
|
||||
|
||||
#define SIMPLE_GET_FUNC(type, name, returnType) \
|
||||
export returnType CreatureLib_##type##_##name(const type* p) { return p->name(); }
|
||||
|
||||
SIMPLE_GET_FUNC(EventData, GetKind, EventDataKind);
|
||||
|
||||
SIMPLE_GET_FUNC(DamageEvent, GetCreature, Creature*);
|
||||
SIMPLE_GET_FUNC(DamageEvent, GetDamageSource, DamageSource);
|
||||
SIMPLE_GET_FUNC(DamageEvent, GetOriginalHealth, uint32_t);
|
||||
SIMPLE_GET_FUNC(DamageEvent, GetNewHealth, uint32_t);
|
||||
|
||||
SIMPLE_GET_FUNC(HealEvent, GetCreature, Creature*);
|
||||
SIMPLE_GET_FUNC(HealEvent, GetOriginalHealth, uint32_t);
|
||||
SIMPLE_GET_FUNC(HealEvent, GetNewHealth, uint32_t);
|
|
@ -10,7 +10,7 @@ namespace CreatureLib::Battling {
|
|||
class EventData {
|
||||
public:
|
||||
virtual ~EventData() = default;
|
||||
virtual EventDataKind GetKind() = 0;
|
||||
virtual EventDataKind GetKind() const = 0;
|
||||
};
|
||||
|
||||
class DamageEvent : public EventData {
|
||||
|
@ -22,7 +22,7 @@ namespace CreatureLib::Battling {
|
|||
public:
|
||||
DamageEvent(Creature* c, DamageSource s, uint32_t oHealth, uint32_t newHealth)
|
||||
: _creature(c), _damageSource(s), _originalHealth(oHealth), _newHealth(newHealth) {}
|
||||
EventDataKind GetKind() override { return EventDataKind ::Damage; }
|
||||
EventDataKind GetKind() const override { return EventDataKind ::Damage; }
|
||||
Creature* GetCreature() const { return _creature; }
|
||||
DamageSource GetDamageSource() const { return _damageSource; }
|
||||
uint32_t GetOriginalHealth() const { return _originalHealth; }
|
||||
|
@ -37,7 +37,7 @@ namespace CreatureLib::Battling {
|
|||
public:
|
||||
HealEvent(Creature* c, uint32_t oHealth, uint32_t newHealth)
|
||||
: _creature(c), _originalHealth(oHealth), _newHealth(newHealth) {}
|
||||
EventDataKind GetKind() override { return EventDataKind ::Damage; }
|
||||
EventDataKind GetKind() const override { return EventDataKind ::Heal; }
|
||||
Creature* GetCreature() const { return _creature; }
|
||||
uint32_t GetOriginalHealth() const { return _originalHealth; }
|
||||
uint32_t GetNewHealth() const { return _newHealth; }
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef CREATURELIB_EVENTDATAKIND_HPP
|
||||
#define CREATURELIB_EVENTDATAKIND_HPP
|
||||
#include <Arbutils/Enum.hpp>
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
enum EventDataKind { Damage };
|
||||
ENUM(EventDataKind, uint8_t, Damage, Heal)
|
||||
}
|
||||
|
||||
#endif // CREATURELIB_EVENTDATAKIND_HPP
|
||||
|
|
Loading…
Reference in New Issue