mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-22 02:45:49 -04:00
add generic AEnterLayerEvent for my spooky textureldr stuff
This commit is contained in:
parent
e37dd6dc55
commit
6059a15dff
3 changed files with 65 additions and 18 deletions
loader
|
@ -10,25 +10,49 @@ namespace geode {
|
|||
template<class T>
|
||||
concept InheritsCCNode = std::is_base_of_v<cocos2d::CCNode, T>;
|
||||
|
||||
template<InheritsCCNode T>
|
||||
class EnterLayerEvent : public Event {
|
||||
// Base class; exists so event listeners can be placed dynamically at runtime
|
||||
class GEODE_DLL AEnterLayerEvent : public Event {
|
||||
protected:
|
||||
std::string m_layerID;
|
||||
T* m_layer;
|
||||
cocos2d::CCNode* m_layer;
|
||||
|
||||
public:
|
||||
AEnterLayerEvent(
|
||||
std::string const& layerID,
|
||||
cocos2d::CCNode* layer
|
||||
);
|
||||
|
||||
std::string getID() const;
|
||||
cocos2d::CCNode* getLayer() const;
|
||||
};
|
||||
|
||||
class GEODE_DLL AEnterLayerEventHandler : public EventHandler<AEnterLayerEvent> {
|
||||
public:
|
||||
using Consumer = std::function<void(AEnterLayerEvent*)>;
|
||||
|
||||
protected:
|
||||
Consumer m_consumer;
|
||||
std::optional<std::string> m_targetID;
|
||||
|
||||
public:
|
||||
PassThrough handle(AEnterLayerEvent* event) override;
|
||||
|
||||
AEnterLayerEventHandler(
|
||||
std::optional<std::string> const& id,
|
||||
Consumer handler
|
||||
);
|
||||
};
|
||||
|
||||
template<InheritsCCNode T>
|
||||
class EnterLayerEvent : public AEnterLayerEvent {
|
||||
public:
|
||||
EnterLayerEvent(
|
||||
std::string const& layerID,
|
||||
T* layer
|
||||
) : m_layerID(layerID),
|
||||
m_layer(layer) {}
|
||||
|
||||
std::string getID() const {
|
||||
return m_layerID;
|
||||
}
|
||||
) : AEnterLayerEvent(layerID, layer) {}
|
||||
|
||||
T* getLayer() const {
|
||||
return m_layer;
|
||||
return static_cast<T*>(m_layer);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -38,7 +62,7 @@ namespace geode {
|
|||
template<class N, InheritsEnterLayer<N> T>
|
||||
class EnterLayerEventHandler : public EventHandler<EnterLayerEvent<N>> {
|
||||
public:
|
||||
using Consumer = void(*)(T*);
|
||||
using Consumer = std::function<void(T*)>;
|
||||
|
||||
protected:
|
||||
Consumer m_consumer;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include <Geode/DefaultInclude.hpp>
|
||||
#include <Geode/loader/Loader.hpp>
|
||||
#include <Geode/loader/Mod.hpp>
|
||||
#include <Geode/utils/timer.hpp>
|
||||
#undef snprintf
|
||||
|
||||
USE_GEODE_NAMESPACE();
|
||||
|
@ -24,16 +23,12 @@ bool Mod::validateID(std::string const& id) {
|
|||
}
|
||||
|
||||
Result<Mod*> Loader::loadModFromFile(std::string const& path) {
|
||||
Timer timer;
|
||||
|
||||
// load mod.json
|
||||
auto res = ModInfo::createFromGeodeFile(path);
|
||||
if (!res) {
|
||||
return Err(res.error());
|
||||
}
|
||||
|
||||
log::debug("ModInfo::createFromGeodeFile took {}", timer.elapsedAsString());
|
||||
|
||||
// check that a duplicate has not been loaded
|
||||
if (m_mods.count(res.value().m_id)) {
|
||||
return Err("Mod with ID \"" + res.value().m_id + "\" has already been loaded!");
|
||||
|
@ -60,7 +55,5 @@ Result<Mod*> Loader::loadModFromFile(std::string const& path) {
|
|||
this->updateModResources(mod);
|
||||
});
|
||||
|
||||
log::debug("Loader::loadModFromFile took {}", timer.elapsedAsString());
|
||||
|
||||
return Ok(mod);
|
||||
}
|
||||
|
|
30
loader/src/ui/nodes/EnterLayerEvent.cpp
Normal file
30
loader/src/ui/nodes/EnterLayerEvent.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <Geode/ui/EnterLayerEvent.hpp>
|
||||
|
||||
USE_GEODE_NAMESPACE();
|
||||
|
||||
AEnterLayerEvent::AEnterLayerEvent(
|
||||
std::string const& layerID,
|
||||
cocos2d::CCNode* layer
|
||||
) : m_layerID(layerID),
|
||||
m_layer(layer) {}
|
||||
|
||||
std::string AEnterLayerEvent::getID() const {
|
||||
return m_layerID;
|
||||
}
|
||||
|
||||
cocos2d::CCNode* AEnterLayerEvent::getLayer() const {
|
||||
return m_layer;
|
||||
}
|
||||
|
||||
PassThrough AEnterLayerEventHandler::handle(AEnterLayerEvent* event) {
|
||||
if (m_targetID == event->getID()) {
|
||||
m_consumer(event);
|
||||
}
|
||||
return PassThrough::Propagate;
|
||||
}
|
||||
|
||||
AEnterLayerEventHandler::AEnterLayerEventHandler(
|
||||
std::optional<std::string> const& id,
|
||||
Consumer handler
|
||||
) : m_targetID(id),
|
||||
m_consumer(handler) {}
|
Loading…
Reference in a new issue