Added display text event hook.

This commit is contained in:
Deukhoofd 2020-03-09 17:43:36 +01:00
parent 314b8997be
commit 5a976e4031
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
6 changed files with 16 additions and 3 deletions

View File

@ -19,3 +19,5 @@ SIMPLE_GET_FUNC(HealEvent, GetOriginalHealth, uint32_t);
SIMPLE_GET_FUNC(HealEvent, GetNewHealth, uint32_t);
SIMPLE_GET_FUNC(FaintEvent, GetCreature, Creature*);
export const char* CreatureLib_DisplayTextEvent_GetText(const DisplayTextEvent* p) { return p->GetText().c_str(); }

View File

@ -52,6 +52,15 @@ namespace CreatureLib::Battling {
Creature* GetCreature() const { return _creature; }
};
class DisplayTextEvent : public EventData {
const std::string _text;
public:
DisplayTextEvent(const std::string& text) : _text(text) {}
EventDataKind GetKind() const override { return EventDataKind ::DisplayText; }
const std::string& GetText() const { return _text; }
};
}
#endif // CREATURELIB_EVENTDATA_HPP

View File

@ -3,7 +3,7 @@
#include <Arbutils/Enum.hpp>
namespace CreatureLib::Battling {
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint)
ENUM(EventDataKind, uint8_t, Damage, Heal, Faint, DisplayText)
}

View File

@ -15,7 +15,7 @@ namespace CreatureLib::Battling {
public:
void RegisterListener(EVENT_HOOK_FUNC(func)) { _listeners.push_back(func); }
void TriggerEvent(EventData* eventData) {
void TriggerEvent(EventData* eventData) const {
for (auto listener : _listeners) {
listener(eventData);
}

View File

@ -130,3 +130,4 @@ void Battle::AddVolatileScript(const ConstString& key) {
}
void Battle::AddVolatileScript(Script* script) { return _volatile.Add(script); }
void Battle::RemoveVolatileScript(Script* script) { _volatile.Remove(script->GetName()); }
void Battle::DisplayText(const std::string& text) const { TriggerEventListener(new DisplayTextEvent(text)); }

View File

@ -89,8 +89,9 @@ namespace CreatureLib::Battling {
bool HasVolatileScript(const ConstString& name) const { return _volatile.Has(name); }
bool HasVolatileScript(uint32_t keyHash) const { return _volatile.Has(keyHash); }
void DisplayText(const std::string& text) const;
void RegisterEventListener(EVENT_HOOK_FUNC(listener)) { this->_eventHook.RegisterListener(listener); }
void TriggerEventListener(EventData* data) { this->_eventHook.TriggerEvent(data); }
void TriggerEventListener(EventData* data) const { this->_eventHook.TriggerEvent(data); }
};
}