Kelsidavis-WoWee/include/addons/addon_manager.hpp
Kelsi 510f03fa32 feat: add WoW event system for Lua addons
Implement the WoW-compatible event system that lets addons react to
gameplay events in real-time:

- RegisterEvent(eventName, handler) — register a Lua function for an event
- UnregisterEvent(eventName, handler) — remove a handler
- fireEvent() dispatches events to all registered handlers with args

Currently fired events:
- PLAYER_ENTERING_WORLD — after addons load and world entry completes
- PLAYER_LEAVING_WORLD — before logout/disconnect

Events are stored in a __WoweeEvents Lua table, dispatched via
LuaEngine::fireEvent() which is called from AddonManager::fireEvent().
Error handling logs Lua errors without crashing.

Updated HelloWorld addon to use RegisterEvent for world entry/exit.
2026-03-20 11:23:38 -07:00

34 lines
860 B
C++

#pragma once
#include "addons/lua_engine.hpp"
#include "addons/toc_parser.hpp"
#include <memory>
#include <string>
#include <vector>
namespace wowee::addons {
class AddonManager {
public:
AddonManager();
~AddonManager();
bool initialize(game::GameHandler* gameHandler);
void scanAddons(const std::string& addonsPath);
void loadAllAddons();
bool runScript(const std::string& code);
void fireEvent(const std::string& event, const std::vector<std::string>& args = {});
void shutdown();
const std::vector<TocFile>& getAddons() const { return addons_; }
LuaEngine* getLuaEngine() { return &luaEngine_; }
bool isInitialized() const { return luaEngine_.isInitialized(); }
private:
LuaEngine luaEngine_;
std::vector<TocFile> addons_;
bool loadAddon(const TocFile& addon);
};
} // namespace wowee::addons