From e10621d40d13fbf8fa209b336e210ccee68df949 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:37:10 +0300 Subject: [PATCH] actually move it to source --- loader/include/Geode/utils/cocos.hpp | 26 +------------------------- loader/src/utils/cocos.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/loader/include/Geode/utils/cocos.hpp b/loader/include/Geode/utils/cocos.hpp index 9f02a0e8..0d4cf0af 100644 --- a/loader/include/Geode/utils/cocos.hpp +++ b/loader/include/Geode/utils/cocos.hpp @@ -747,31 +747,7 @@ namespace geode::cocos { * @returns Child with the given sprite frame name, or * nullptr if there is none */ - template - Type getChildBySpriteFrameName(cocos2d::CCNode* parent, const char* name) { - auto cache = cocos2d::CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name); - if (!cache) return nullptr; - - auto* texture = cache->getTexture(); - auto rect = cache->getRect(); - - for (int i = 0; i < parent->getChildrenCount(); ++i) { - auto* child = parent->getChildren()->objectAtIndex(i); - if (auto* spr = typeinfo_cast(child)) { - if (spr->getTexture() == texture && spr->getTextureRect() == rect) { - return static_cast(spr); - } - } else if (auto* btn = typeinfo_cast(child)) { - auto* img = btn->getNormalImage(); - if (auto* spr = typeinfo_cast(img)) { - if (spr->getTexture() == texture && spr->getTextureRect() == rect) { - return static_cast(btn); - } - } - } - } - return nullptr; - } + cocos2d::CCNode* getChildBySpriteFrameName(cocos2d::CCNode* parent, const char* name); /** * Checks if a given file exists in CCFileUtils diff --git a/loader/src/utils/cocos.cpp b/loader/src/utils/cocos.cpp index 09f76cfa..3bc65dbe 100644 --- a/loader/src/utils/cocos.cpp +++ b/loader/src/utils/cocos.cpp @@ -339,6 +339,31 @@ std::shared_ptr WeakRefPool::manage(CCObject* obj) { return m_pool.at(obj); } +CCNode* geode::cocos::getChildBySpriteFrameName(CCNode* parent, const char* name) { + auto cache = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name); + if (!cache) return nullptr; + + auto* texture = cache->getTexture(); + auto rect = cache->getRect(); + + for (int i = 0; i < parent->getChildrenCount(); ++i) { + auto* child = parent->getChildren()->objectAtIndex(i); + if (auto* spr = typeinfo_cast(child)) { + if (spr->getTexture() == texture && spr->getTextureRect() == rect) { + return spr; + } + } else if (auto* btn = typeinfo_cast(child)) { + auto* img = btn->getNormalImage(); + if (auto* spr = typeinfo_cast(img)) { + if (spr->getTexture() == texture && spr->getTextureRect() == rect) { + return btn; + } + } + } + } + return nullptr; +} + CCRect geode::cocos::calculateNodeCoverage(std::vector const& nodes) { CCRect coverage; for (auto child : nodes) {