actually move it to source

This commit is contained in:
altalk23 2024-02-16 21:37:10 +03:00
parent 85f8a206cd
commit e10621d40d
2 changed files with 26 additions and 25 deletions

View file

@ -747,31 +747,7 @@ namespace geode::cocos {
* @returns Child with the given sprite frame name, or
* nullptr if there is none
*/
template <class Type = cocos2d::CCNode*>
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<cocos2d::CCSprite*>(child)) {
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
return static_cast<Type>(spr);
}
} else if (auto* btn = typeinfo_cast<cocos2d::CCMenuItemSprite*>(child)) {
auto* img = btn->getNormalImage();
if (auto* spr = typeinfo_cast<cocos2d::CCSprite*>(img)) {
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
return static_cast<Type>(btn);
}
}
}
}
return nullptr;
}
cocos2d::CCNode* getChildBySpriteFrameName(cocos2d::CCNode* parent, const char* name);
/**
* Checks if a given file exists in CCFileUtils

View file

@ -339,6 +339,31 @@ std::shared_ptr<WeakRefController> 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<CCSprite*>(child)) {
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
return spr;
}
} else if (auto* btn = typeinfo_cast<CCMenuItemSprite*>(child)) {
auto* img = btn->getNormalImage();
if (auto* spr = typeinfo_cast<CCSprite*>(img)) {
if (spr->getTexture() == texture && spr->getTextureRect() == rect) {
return btn;
}
}
}
}
return nullptr;
}
CCRect geode::cocos::calculateNodeCoverage(std::vector<CCNode*> const& nodes) {
CCRect coverage;
for (auto child : nodes) {