Skip to content

Commit

Permalink
Event V2 system
Browse files Browse the repository at this point in the history
  • Loading branch information
camila314 committed Jan 13, 2025
1 parent b8cff6d commit 728df4e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions loader/include/Geode/Loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
23 changes: 23 additions & 0 deletions loader/include/Geode/loader/EventV2.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "Event.hpp"

namespace geode::event::v2 {
template <is_event T>
struct GEODE_DLL WrapFilter : public EventFilter<T> {
std::function<bool(T*)> m_filterFunc;

WrapFilter(std::function<bool(T*)> ff) : m_filterFunc(ff) {}

ListenerResult handle(std::function<ListenerResult(T*)> fn, T* event) {
if (m_filterFunc(event))
return fn(event);
return ListenerResult::Propagate;
}
};

template <typename T>
struct GEODE_DLL EventHandler : public EventListener<WrapFilter<T>> {
EventHandler(std::function<bool(T*)> filterFunc) : EventListener<WrapFilter<T>>(WrapFilter(filterFunc)) {}
};
}

0 comments on commit 728df4e

Please sign in to comment.