mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-27 01:45:35 -05:00
add AttributeSetEvent
This commit is contained in:
parent
7963469f1e
commit
69bd0d99ef
2 changed files with 38 additions and 1 deletions
23
loader/include/Geode/cocos/base_nodes/CCNode.h
vendored
23
loader/include/Geode/cocos/base_nodes/CCNode.h
vendored
|
@ -1725,4 +1725,27 @@ protected:
|
|||
|
||||
NS_CC_END
|
||||
|
||||
namespace geode {
|
||||
struct GEODE_DLL AttributeSetEvent : public Event {
|
||||
cocos2d::CCNode* node;
|
||||
const std::string id;
|
||||
json::Value& value;
|
||||
|
||||
AttributeSetEvent(cocos2d::CCNode* node, std::string const& id, json::Value& value);
|
||||
};
|
||||
|
||||
class GEODE_DLL AttributeSetFilter : public EventFilter<AttributeSetEvent> {
|
||||
public:
|
||||
using Callback = void(AttributeSetEvent*);
|
||||
|
||||
protected:
|
||||
std::string m_targetID;
|
||||
|
||||
public:
|
||||
ListenerResult handle(utils::MiniFunction<Callback> fn, AttributeSetEvent* event);
|
||||
|
||||
AttributeSetFilter(std::string const& id);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __PLATFORM_CCNODE_H__
|
||||
|
|
|
@ -169,8 +169,22 @@ void CCNode::updateLayout(bool updateChildOrder) {
|
|||
}
|
||||
}
|
||||
|
||||
AttributeSetEvent::AttributeSetEvent(CCNode* node, std::string const& id, json::Value& value)
|
||||
: node(node), id(id), value(value) {}
|
||||
|
||||
ListenerResult AttributeSetFilter::handle(MiniFunction<Callback> fn, AttributeSetEvent* event) {
|
||||
if (event->id == m_targetID) {
|
||||
fn(event);
|
||||
}
|
||||
return ListenerResult::Propagate;
|
||||
}
|
||||
|
||||
AttributeSetFilter::AttributeSetFilter(std::string const& id) : m_targetID(id) {}
|
||||
|
||||
void CCNode::setAttribute(std::string const& attr, json::Value const& value) {
|
||||
GeodeNodeMetadata::set(this)->m_attributes[attr] = value;
|
||||
auto meta = GeodeNodeMetadata::set(this);
|
||||
meta->m_attributes[attr] = value;
|
||||
AttributeSetEvent(this, attr, meta->m_attributes.at(attr)).post();
|
||||
}
|
||||
|
||||
std::optional<json::Value> CCNode::getAttributeInternal(std::string const& attr) {
|
||||
|
|
Loading…
Reference in a new issue