diff --git a/loader/include/Geode/Loader.hpp b/loader/include/Geode/Loader.hpp index a1bb4c37e..94b8143e3 100644 --- a/loader/include/Geode/Loader.hpp +++ b/loader/include/Geode/Loader.hpp @@ -5,6 +5,7 @@ #include "loader/Log.hpp" #include "loader/Mod.hpp" #include "loader/ModEvent.hpp" +#include "loader/EventV2.hpp" #include "loader/Setting.hpp" #include "loader/Dirs.hpp" diff --git a/loader/include/Geode/loader/EventV2.hpp b/loader/include/Geode/loader/EventV2.hpp new file mode 100644 index 000000000..296c472c3 --- /dev/null +++ b/loader/include/Geode/loader/EventV2.hpp @@ -0,0 +1,23 @@ +#pragma once + +#include "Event.hpp" + +namespace geode::event::v2 { + template + struct GEODE_DLL WrapFilter : public EventFilter { + std::function m_filterFunc; + + WrapFilter(std::function ff) : m_filterFunc(ff) {} + + ListenerResult handle(std::function fn, T* event) { + if (m_filterFunc(event)) + return fn(event); + return ListenerResult::Propagate; + } + }; + + template + struct GEODE_DLL EventHandler : public EventListener> { + EventHandler(std::function filterFunc) : EventListener>(WrapFilter(filterFunc)) {} + }; +}