Skip to content
This repository was archived by the owner on Aug 2, 2026. It is now read-only.

Commit e613089

Browse files
committed
Fix
1 parent 1d2b678 commit e613089

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 2.1.3
2+
- Fix bug where getting by index required the full namespace of the type
3+
14
# 2.1.2
25
- Add onGeode callback to MenuLayer
36

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"mac": "2.2081",
77
"ios": "2.2081"
88
},
9-
"version": "v2.1.2",
9+
"version": "v2.1.3",
1010
"id": "alphalaneous.happy_textures",
1111
"name": "Happy Textures :3",
1212
"developer": "Alphalaneous",

src/UIModding.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ void UIModding::modifyChildByIndex(CCNode* node, const matjson::Value& value) {
12241224
}
12251225
}
12261226

1227-
UIModding::get()->handleModifications(alpha::utils::cocos::getChildByClassName(node, type, index).value_or(nullptr), value);
1227+
UIModding::get()->handleModifications(Utils::getChildByClassName(node, type, index).value_or(nullptr), value);
12281228
}
12291229

12301230
void UIModding::createAndModifyNewChild(CCNode* node, const matjson::Value& newChildVal) {

src/Utils.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,35 @@ namespace Utils {
236236
return extract(std::string(name));
237237
}
238238

239+
static std::optional<cocos2d::CCNode*> getChildByClassName(cocos2d::CCNode* node, geode::ZStringView name, int index = 0) {
240+
if (!node || node->getChildrenCount() == 0) return nullptr;
241+
242+
size_t indexCounter = 0;
243+
const size_t childrenCount = node->getChildrenCount();
244+
245+
bool isNegativeIndex = (index < 0);
246+
if (isNegativeIndex) {
247+
index = -index - 1;
248+
}
249+
250+
for (size_t i = (isNegativeIndex ? childrenCount - 1 : 0);
251+
isNegativeIndex ? i >= 0 : i < childrenCount;
252+
isNegativeIndex ? --i : ++i) {
253+
254+
auto idxNode = node->getChildrenExt()[i];
255+
if (getObjectName(idxNode) == name) {
256+
if (indexCounter == index) {
257+
return idxNode;
258+
}
259+
++indexCounter;
260+
}
261+
262+
if (isNegativeIndex && i == 0) break;
263+
}
264+
265+
return std::nullopt;
266+
}
267+
239268
static CCNode* nodeForQuery(CCNode* node, const std::string& queryStr) {
240269
auto res = NodeQuery::parse(queryStr);
241270
if (!res) return nullptr;

0 commit comments

Comments
 (0)