Skip to content

Commit

Permalink
set user object on fallback sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
matcool committed Jun 15, 2024
1 parent e94aa6f commit 5684a41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
21 changes: 14 additions & 7 deletions src/Fallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,32 @@

using namespace geode::prelude;

void assignFallbackObj(CCNode* node) {
if (!node) return;
node->setUserObject("fallback"_spr, CCBool::create(true));
}

class $modify(CCSprite) {
static CCSprite* create(const char* name) {
auto* sprite = CCSprite::create(name);
if (sprite == nullptr) {
sprite = CCSprite::create("fallback.png"_spr);
}
// in dire cases, since no one is stupid enough to delete this texture
if (sprite == nullptr) {
sprite = CCSprite::create("bigFont.png");
// in dire cases, since no one is stupid enough to delete this texture
if (sprite == nullptr) {
sprite = CCSprite::create("bigFont.png");
}
assignFallbackObj(sprite);
}
return sprite;
}
static CCSprite* createWithSpriteFrameName(const char* name) {
auto* sprite = CCSprite::createWithSpriteFrameName(name);
if (sprite == nullptr) {
sprite = CCSprite::create("fallback.png"_spr);
}
if (sprite == nullptr) {
sprite = CCSprite::create("bigFont.png");
if (sprite == nullptr) {
sprite = CCSprite::create("bigFont.png");
}
assignFallbackObj(sprite);
}
return sprite;
}
Expand Down
4 changes: 3 additions & 1 deletion src/PackNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ bool PackNode::init(

auto logo = CCSprite::create((pack->getResourcesPath() / "pack.png").string().c_str());

if (!logo) {
if (!logo || logo->getUserObject("fallback"_spr)) {
logo = CCSprite::create("noLogo.png"_spr);
if (logo)
logo->setOpacity(100);
}
if (logo) {
logo->setPosition({ SPACE_FOR_LOGO / 2 + PADDING, HEIGHT / 2 });
Expand Down

0 comments on commit 5684a41

Please sign in to comment.