refactor: move event disptacher into service locator

This commit is contained in:
k0t9i
2023-10-16 23:38:01 +04:00
parent b948273172
commit ede55a870e
15 changed files with 160 additions and 94 deletions

View File

@@ -5,10 +5,10 @@
#include "../GameStructs/NetworkHandlerWrapper.h"
#include "Domain/Repositories/EntityRepositoryInterface.h"
#include "../Factories/NPCFactory.h"
#include "../../../Events/EventDispatcher.h"
#include "../../../Events/SpoiledEvent.h"
#include "../../../Events/CreatureDiedEvent.h"
#include "../../GameStructs/FindObjectsTrait.h"
#include "../../../Services/ServiceLocator.h"
using namespace L2Bot::Domain;
@@ -55,17 +55,21 @@ namespace Interlude
m_Npcs.clear();
}
void Init() override
{
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(SpoiledEvent::name, [this](const Event& evt) {
OnSpoiled(evt);
});
ServiceLocator::GetInstance().GetEventDispatcher()->Subscribe(CreatureDiedEvent::name, [this](const Event& evt) {
OnCreatureDied(evt);
});
}
NPCRepository(const NetworkHandlerWrapper& networkHandler, const NPCFactory& factory, const uint16_t radius) :
m_NetworkHandler(networkHandler),
m_Factory(factory),
m_Radius(radius)
{
EventDispatcher::GetInstance().Subscribe(SpoiledEvent::name, [this](const Event& evt) {
OnSpoiled(evt);
});
EventDispatcher::GetInstance().Subscribe(CreatureDiedEvent::name, [this](const Event& evt) {
OnCreatureDied(evt);
});
}
NPCRepository() = delete;