Initial support for Event Hooks.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
25
src/Battling/EventHooks/EventHook.hpp
Normal file
25
src/Battling/EventHooks/EventHook.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef CREATURELIB_EVENTHOOK_HPP
|
||||
#define CREATURELIB_EVENTHOOK_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "EventData.hpp"
|
||||
|
||||
#define EVENT_HOOK_FUNC(name) void (*name)(const EventData*)
|
||||
|
||||
namespace CreatureLib::Battling {
|
||||
/// The Event Hook class allows users to write consumers for the battle events, for example to write User Interfaces
|
||||
/// for it.
|
||||
class EventHook {
|
||||
std::vector<EVENT_HOOK_FUNC()> _listeners;
|
||||
|
||||
public:
|
||||
void RegisterListener(EVENT_HOOK_FUNC(func)) { _listeners.push_back(func); }
|
||||
|
||||
void TriggerEvent(EventData* eventData) {
|
||||
for (auto listener : _listeners) {
|
||||
listener(eventData);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
#endif // CREATURELIB_EVENTHOOK_HPP
|
||||
Reference in New Issue
Block a user