#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 class GEODE_DLL AEnterLayerEvent : public Event { protected: std::string m_layerID; cocos2d::CCNode* m_layer; public: AEnterLayerEvent( std::string const& layerID, cocos2d::CCNode* layer ); std::string getID() const; cocos2d::CCNode* getLayer() const; }; class GEODE_DLL AEnterLayerFilter : public EventFilter { public: using Callback = std::function; protected: std::optional m_targetID; public: ListenerResult handle(Callback 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(m_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) {} }; }