diff --git a/include/engine/Module.hpp b/include/engine/Module.hpp index 9fcd4d4b..75a7aac6 100644 --- a/include/engine/Module.hpp +++ b/include/engine/Module.hpp @@ -387,6 +387,12 @@ struct Module { */ virtual void onSave(const SaveEvent& e) {} + struct SetPrimaryEvent {}; + virtual void onSetPrimary(const SetPrimaryEvent& e) {} + + struct UnsetPrimaryEvent {}; + virtual void onUnsetPrimary(const UnsetPrimaryEvent& e) {} + /** DEPRECATED. Override `onAdd(e)` instead. */ virtual void onAdd() {} /** DEPRECATED. Override `onRemove(e)` instead. */ diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index 1332a6fc..0958fa9b 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -577,7 +577,20 @@ void Engine::stepBlock(int frames) { void Engine::setPrimaryModule(Module* module) { WriteLock lock(internal->mutex); + + if (internal->primaryModule) { + // Trigger UnsetPrimaryEvent + Module::UnsetPrimaryEvent e; + internal->primaryModule->onUnsetPrimary(e); + } + internal->primaryModule = module; + + if (internal->primaryModule) { + // Trigger SetPrimaryEvent + Module::SetPrimaryEvent e; + internal->primaryModule->onSetPrimary(e); + } }