#pragma once #include "../loader/Event.hpp" namespace cocos2d { class CCNode; } namespace geode { template concept InheritsCCNode = std::is_base_of_v; // Base class; exists so event listeners can be placed dynamically at runtime struct GEODE_DLL AEnterLayerEvent : public Event { const std::string layerID; cocos2d::CCNode* layer; AEnterLayerEvent( std::string const& layerID, cocos2d::CCNode* layer ); }; class GEODE_DLL AEnterLayerFilter : public EventFilter { public: using Callback = void(AEnterLayerEvent*); protected: std::optional m_targetID; public: ListenerResult handle(std::function fn, AEnterLayerEvent* event); AEnterLayerFilter( std::optional const& id ); }; template class EnterLayerEvent : public AEnterLayerEvent { public: EnterLayerEvent( std::string const& layerID, T* layer ) : AEnterLayerEvent(layerID, layer) {} T* getLayer() const { return static_cast(this->layer); } }; template concept InheritsEnterLayer = std::is_base_of_v, T>; template T> class EnterLayerFilter : public EventFilter> { public: using Callback = void(T*); protected: std::optional m_targetID; public: ListenerResult handle(std::function fn, EnterLayerEvent* event) { if (m_targetID == event->getID()) { fn(static_cast(event)); } return ListenerResult::Propagate; } EnterLayerFilter( std::optional const& id ) : m_targetID(id) {} }; }