Skip to content

Commit

Permalink
get level edit button by sprite name instead, thanks megahack
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Feb 5, 2024
1 parent 188f410 commit 986ed7e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"win": "2.204",
"android": "2.205"
},
"version": "v1.2.2",
"version": "v1.2.3",
"id": "geode.node-ids",
"name": "Node IDs",
"developer": "Geode Team",
Expand Down
2 changes: 2 additions & 0 deletions src/IDCheck.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#define verifyIDSafe(Member_, ID_) \
if(Member_ && Member_->getID() != ID_) { \
log::warn("{} has an invalid ID - {} (expected {})", #Member_, Member_->getID(), ID_); \
Expand Down
35 changes: 31 additions & 4 deletions src/PauseLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@
using namespace geode::prelude;
using namespace geode::node_ids;

// this code sux but oh well
// maybe it should be in geode utils
CCNode* 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;
}

$register_ids(PauseLayer) {
int idx = 0;
setIDs(
Expand Down Expand Up @@ -134,13 +161,13 @@ using namespace geode::node_ids;
if (auto menu = this->getChildByID("center-button-menu")) {

int idx = 0;
if (level->m_levelType == GJLevelType::Editor) {
setIDSafe(menu, idx, "edit-button");
if (auto* node = getChildBySpriteFrameName(menu, "GJ_editBtn_001.png")) {
node->setID("edit-button");
++idx;
}

if (level->isPlatformer()) {
setIDSafe(menu, idx, "full-restart-button");
if (auto* node = getChildBySpriteFrameName(menu, "GJ_replayFullBtn_001.png")) {
node->setID("full-restart-button");
++idx;
}

Expand Down

0 comments on commit 986ed7e

Please sign in to comment.