Skip to content

Commit

Permalink
Add nullptr checks for nodes in LevelPage (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMario211 authored Oct 28, 2024
1 parent d0851b0 commit 94a8d68
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/LevelPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,13 @@ struct LevelPageIDs : Modify<LevelPageIDs, LevelPage> {
}

if (GameStatsManager::sharedState()->getStat("8") < level->m_requiredCoins) {
setIDs(
this->getChildByID("level-menu")
->getChildByID("level-button")
->getChildByID("white-sprite")
->getChildByID("scale-9-sprite"),
8,
"lock-sprite",
"secret-coin-icon",
"secret-coin-label"
);
if (auto scale9Sprite = this->getChildByIDRecursive("scale-9-sprite")) {
setIDs(scale9Sprite, 8, "lock-sprite", "secret-coin-icon", "secret-coin-label");
}
} else {
setIDs(
this->getChildByID("level-menu")
->getChildByID("level-button")
->getChildByID("white-sprite")
->getChildByID("scale-9-sprite"),
8,
"orbs-icon",
"orbs-label"
);
if (auto scale9Sprite = this->getChildByIDRecursive("scale-9-sprite")) {
setIDs(scale9Sprite, 8, "orbs-icon", "orbs-label");
}
}

// this is how updateDynamicPage itself does it
Expand All @@ -122,15 +109,19 @@ struct LevelPageIDs : Modify<LevelPageIDs, LevelPage> {
}
}
} else {
getChildOfType<CCLabelBMFont>(this, 4)->setID("coming-soon-label");
if (auto label = getChildOfType<CCLabelBMFont>(this, 4)) {
label->setID("coming-soon-label");
}

if (auto buttonMenu = getChildOfType<CCMenu>(this, 1)) {
buttonMenu->setID("button-menu");

if (auto secretDoorButton = getChildOfType<CCMenuItemSpriteExtra>(buttonMenu, 0)) {
secretDoorButton->setID("secret-door-button");

getChildOfType<CCSprite>(secretDoorButton, 0)->setID("secret-door-sprite");
if (auto secretDoorSprite = getChildOfType<CCSprite>(secretDoorButton, 0)) {
secretDoorSprite->setID("secret-door-sprite");
}
}
}
}
Expand Down

0 comments on commit 94a8d68

Please sign in to comment.