2022-10-06 13:46:07 -04:00
|
|
|
#include <Geode/Bindings.hpp>
|
|
|
|
#include <Geode/utils/Ref.hpp>
|
|
|
|
#include <Geode/utils/WackyGeodeMacros.hpp>
|
2022-10-13 04:31:23 -04:00
|
|
|
#include <Geode/modify/Field.hpp>
|
2022-10-06 13:46:07 -04:00
|
|
|
|
|
|
|
USE_GEODE_NAMESPACE();
|
|
|
|
using namespace geode::modifier;
|
|
|
|
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable: 4273)
|
|
|
|
|
|
|
|
constexpr auto METADATA_TAG = 0xB324ABC;
|
|
|
|
|
|
|
|
struct ProxyCCNode;
|
|
|
|
|
|
|
|
class GeodeNodeMetadata final : public cocos2d::CCObject {
|
|
|
|
private:
|
|
|
|
FieldContainer* m_fieldContainer;
|
|
|
|
Ref<cocos2d::CCObject> m_userObject;
|
|
|
|
std::string m_id = "";
|
|
|
|
|
|
|
|
friend class ProxyCCNode;
|
|
|
|
friend class cocos2d::CCNode;
|
|
|
|
|
|
|
|
GeodeNodeMetadata() : m_fieldContainer(new FieldContainer()) {}
|
|
|
|
virtual ~GeodeNodeMetadata() {
|
|
|
|
delete m_fieldContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static GeodeNodeMetadata* set(CCNode* target) {
|
2022-10-06 15:33:56 -04:00
|
|
|
if (!target) return nullptr;
|
|
|
|
|
2022-10-06 13:46:07 -04:00
|
|
|
auto old = target->m_pUserObject;
|
|
|
|
// faster than dynamic_cast, technically can
|
|
|
|
// but extremely unlikely to fail
|
|
|
|
if (old && old->getTag() == METADATA_TAG) {
|
|
|
|
return static_cast<GeodeNodeMetadata*>(old);
|
|
|
|
}
|
|
|
|
auto meta = new GeodeNodeMetadata();
|
|
|
|
meta->autorelease();
|
|
|
|
meta->setTag(METADATA_TAG);
|
|
|
|
|
|
|
|
// set user object
|
|
|
|
target->m_pUserObject = meta;
|
|
|
|
meta->retain();
|
|
|
|
|
|
|
|
if (old) {
|
|
|
|
meta->m_userObject = old;
|
|
|
|
// the old user object has been retained by CCNode
|
|
|
|
old->release();
|
|
|
|
}
|
|
|
|
return meta;
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldContainer* getFieldContainer() {
|
|
|
|
return m_fieldContainer;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// proxy forwards
|
2022-10-13 04:31:23 -04:00
|
|
|
#include <codegenned/modify/CCNode.hpp>
|
2022-10-06 13:46:07 -04:00
|
|
|
class $modify(ProxyCCNode, CCNode) {
|
|
|
|
virtual CCObject* getUserObject() {
|
|
|
|
return GeodeNodeMetadata::set(this)->m_userObject;
|
|
|
|
}
|
|
|
|
virtual void setUserObject(CCObject* obj) {
|
|
|
|
GeodeNodeMetadata::set(this)->m_userObject = obj;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// not const because might modify contents
|
|
|
|
FieldContainer* CCNode::getFieldContainer() {
|
|
|
|
return GeodeNodeMetadata::set(this)->getFieldContainer();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string CCNode::getID() {
|
|
|
|
return GeodeNodeMetadata::set(this)->m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNode::setID(std::string const& id) {
|
|
|
|
GeodeNodeMetadata::set(this)->m_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCNode* CCNode::getChildByID(std::string const& id) {
|
|
|
|
CCARRAY_FOREACH_B_TYPE(m_pChildren, child, CCNode) {
|
|
|
|
if (child->getID() == id) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCNode* CCNode::getChildByIDRecursive(std::string const& id) {
|
|
|
|
if (auto child = this->getChildByID(id)) {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
CCARRAY_FOREACH_B_TYPE(m_pChildren, child, CCNode) {
|
2022-10-08 05:41:36 -04:00
|
|
|
if ((child = child->getChildByIDRecursive(id))) {
|
2022-10-06 13:46:07 -04:00
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma warning(pop)
|