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.
This commit is contained in:
Kelsi 2026-03-20 11:23:38 -07:00
parent 7da1f6f5ca
commit 510f03fa32
6 changed files with 148 additions and 14 deletions

View file

@ -660,6 +660,9 @@ void Application::setState(AppState newState) {
}
// Ensure no stale in-world player model leaks into the next login attempt.
// If we reuse a previously spawned instance without forcing a respawn, appearance (notably hair) can desync.
if (addonManager_ && addonsLoaded_) {
addonManager_->fireEvent("PLAYER_LEAVING_WORLD");
}
npcsSpawned = false;
playerCharacterSpawned = false;
addonsLoaded_ = false;
@ -5049,6 +5052,7 @@ void Application::loadOnlineWorldTerrain(uint32_t mapId, float x, float y, float
if (addonManager_ && !addonsLoaded_) {
addonManager_->loadAllAddons();
addonsLoaded_ = true;
addonManager_->fireEvent("PLAYER_ENTERING_WORLD");
}
}