diff --git a/loader/include/Geode/loader/Event.hpp b/loader/include/Geode/loader/Event.hpp index 8f88cb54e..9b23fc783 100644 --- a/loader/include/Geode/loader/Event.hpp +++ b/loader/include/Geode/loader/Event.hpp @@ -3,11 +3,14 @@ #include "../utils/casts.hpp" #include +#include +#include +#include #include #include #include -#include #include +#include namespace geode { class Mod; @@ -190,6 +193,32 @@ namespace geode { this->enable(); } + EventListener& operator=(EventListener const& other) { + if (this == &other) { + return *this; + } + + m_callback = other.m_callback; + m_filter = other.m_filter; + m_filter.setListener(this); + + return *this; + } + + EventListener& operator=(EventListener&& other) { + if (this == &other) { + return *this; + } + + m_callback = std::move(other.m_callback); + m_filter = std::move(other.m_filter); + + m_filter.setListener(this); + other.disable(); + + return *this; + } + void bind(std::function fn) { m_callback = fn; } @@ -239,4 +268,10 @@ namespace geode { virtual ~Event(); }; -} + + // Creates an EventListener that is active for the entire lifetime of the game. You have no way of disabling the listener, so only use this if you want to always listen for certain events! + template + void globalListen(typename T::Callback callback, T filter = T()) { + new EventListener(callback, filter); + } +} \ No newline at end of file