mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 07:57:51 -05:00
add a special case for null mod to allow listening for all mod events
This commit is contained in:
parent
473a15b55a
commit
fe27260abc
2 changed files with 14 additions and 1 deletions
|
@ -17,6 +17,9 @@ namespace geode {
|
||||||
DataSaved,
|
DataSaved,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event that is fired when a mod is loaded / unloaded / enabled / disabled
|
||||||
|
*/
|
||||||
class GEODE_DLL ModStateEvent : public Event {
|
class GEODE_DLL ModStateEvent : public Event {
|
||||||
protected:
|
protected:
|
||||||
ModEventType m_type;
|
ModEventType m_type;
|
||||||
|
@ -28,6 +31,9 @@ namespace geode {
|
||||||
Mod* getMod() const;
|
Mod* getMod() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listener for mod load/enable/disable/unload/data save events
|
||||||
|
*/
|
||||||
class GEODE_DLL ModStateFilter : public EventFilter<ModStateEvent> {
|
class GEODE_DLL ModStateFilter : public EventFilter<ModStateEvent> {
|
||||||
public:
|
public:
|
||||||
using Callback = void(ModStateEvent*);
|
using Callback = void(ModStateEvent*);
|
||||||
|
@ -38,6 +44,13 @@ namespace geode {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ListenerResult handle(utils::MiniFunction<Callback> fn, ModStateEvent* event);
|
ListenerResult handle(utils::MiniFunction<Callback> fn, ModStateEvent* event);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a mod state listener
|
||||||
|
* @param mod The mod whose events to listen to, or nullptr to listen to
|
||||||
|
* all mods' all state events
|
||||||
|
* @param type Type of event to listen to. Ignored if mod is nullptr
|
||||||
|
*/
|
||||||
ModStateFilter(Mod* mod, ModEventType type);
|
ModStateFilter(Mod* mod, ModEventType type);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ Mod* ModStateEvent::getMod() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ListenerResult ModStateFilter::handle(utils::MiniFunction<Callback> fn, ModStateEvent* event) {
|
ListenerResult ModStateFilter::handle(utils::MiniFunction<Callback> fn, ModStateEvent* event) {
|
||||||
if (event->getMod() == m_mod && event->getType() == m_type) {
|
if (!m_mod || (event->getMod() == m_mod && event->getType() == m_type)) {
|
||||||
fn(event);
|
fn(event);
|
||||||
}
|
}
|
||||||
return ListenerResult::Propagate;
|
return ListenerResult::Propagate;
|
||||||
|
|
Loading…
Reference in a new issue