Skip to content

Commit ac41583

Browse files
committed
tweaks
1 parent 2b6aab5 commit ac41583

1 file changed

Lines changed: 36 additions & 54 deletions

File tree

src/headers/src/ProjectInfoPopup.cpp

Lines changed: 36 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -394,20 +394,6 @@ ProjectInfoPopup* ProjectInfoPopup::setProject(GJGameLevel* level) {
394394
projThumb->ignoreAnchorPointForPosition(false);
395395
projThumb->setPosition({ m_clippingNode->getScaledContentWidth() / 2, m_clippingNode->getScaledContentHeight() / 2 });
396396

397-
bool isCustomThumbnail = false; // whether the thumbnail is custom
398-
399-
if (m_avalProject.thumbnail.empty()) {
400-
AVAL_LOG_INFO("Using default thumbnail for project '{}'", m_avalProject.name);
401-
isCustomThumbnail = false;
402-
} else {
403-
AVAL_LOG_INFO("Using custom thumbnail URL {}", m_avalProject.thumbnail);
404-
isCustomThumbnail = true;
405-
};
406-
407-
std::string projThumbURL = isCustomThumbnail ? m_avalProject.thumbnail : fmt::format("https://api.cubicstudios.xyz/avalanche/v1/fetch/thumbnails?id={}", (int)m_level->m_levelID.value()); // custom thumbnail or default
408-
409-
AVAL_LOG_DEBUG("Getting thumbnail at {}...", projThumbURL);
410-
411397
projThumb->setLoadCallback([this, projThumb, bgSize](Result<> res) {
412398
if (res.isOk()) {
413399
AVAL_LOG_INFO("Sprite loaded successfully");
@@ -432,6 +418,9 @@ ProjectInfoPopup* ProjectInfoPopup::setProject(GJGameLevel* level) {
432418
};
433419
});
434420

421+
std::string projThumbURL = fmt::format("https://api.cubicstudios.xyz/avalanche/v1/fetch/thumbnails?id={}", (int)m_level->m_levelID.value()); // custom thumbnail
422+
423+
AVAL_LOG_DEBUG("Getting thumbnail at {}...", (std::string)projThumbURL);
435424
projThumb->loadFromUrl(projThumbURL, LazySprite::Format::kFmtUnKnown, false);
436425
if (projThumb) m_clippingNode->addChild(projThumb);
437426
} else {
@@ -542,49 +531,42 @@ ProjectInfoPopup* ProjectInfoPopup::setProject(GJGameLevel* level) {
542531
linkedProjClippingNode->addChild(art_topRight_linkedProj);
543532

544533
// create thumbnail lazy sprite for linked project
545-
AVAL_LOG_DEBUG("Creating thumbnail lazy sprite for linked project '{}'", linkedProj.name);
546-
LazySprite* linkedProjThumb = LazySprite::create(linkedProjMenu->getScaledContentSize(), true);
547-
linkedProjThumb->setID("thumbnail");
548-
linkedProjThumb->setAnchorPoint({ 0.5, 0.5 });
549-
linkedProjThumb->ignoreAnchorPointForPosition(false);
550-
linkedProjThumb->setPosition({ linkedProjMenu->getScaledContentWidth() / 2.f, linkedProjMenu->getScaledContentHeight() / 2.f });
551-
linkedProjThumb->setScale(0.5f);
552-
553-
linkedProjThumb->setLoadCallback([linkedProjThumb, linkedProjClippingNode](Result<> res) {
554-
if (res.isOk()) {
555-
AVAL_LOG_INFO("Linked project thumbnail loaded successfully");
556-
557-
linkedProjThumb->setScale(1.f);
558-
linkedProjThumb->setScale(linkedProjClippingNode->getScaledContentHeight() / linkedProjThumb->getScaledContentHeight());
559-
560-
linkedProjThumb->setPosition(linkedProjClippingNode->getPosition());
561-
linkedProjThumb->ignoreAnchorPointForPosition(false);
562-
linkedProjThumb->setColor({ 250, 250, 250 });
563-
linkedProjThumb->setOpacity(250);
564-
} else {
565-
AVAL_LOG_ERROR("Failed to load linked project thumbnail: {}", res.unwrapErr());
566-
linkedProjThumb->removeMeAndCleanup();
567-
};
568-
});
569-
570-
bool isCustomThumbnail = false; // whether the thumbnail is custom
571-
572-
// check if linked project has a custom thumbnail
573-
if (linkedProj.thumbnail.empty()) {
574-
AVAL_LOG_INFO("Using default thumbnail for project '{}'", linkedProj.name);
575-
isCustomThumbnail = false;
534+
if (AVAL_GEODE_MOD->getSettingValue<bool>("show-proj-thumb")) {
535+
AVAL_LOG_DEBUG("Creating thumbnail lazy sprite for linked project '{}'", linkedProj.name);
536+
LazySprite* linkedProjThumb = LazySprite::create(linkedProjMenu->getScaledContentSize(), true);
537+
linkedProjThumb->setID("thumbnail");
538+
linkedProjThumb->setAnchorPoint({ 0.5, 0.5 });
539+
linkedProjThumb->ignoreAnchorPointForPosition(false);
540+
linkedProjThumb->setPosition({ linkedProjMenu->getScaledContentWidth() / 2.f, linkedProjMenu->getScaledContentHeight() / 2.f });
541+
linkedProjThumb->setScale(0.5f);
542+
543+
linkedProjThumb->setLoadCallback([linkedProjThumb, linkedProjClippingNode](Result<> res) {
544+
if (res.isOk()) {
545+
AVAL_LOG_INFO("Linked project thumbnail loaded successfully");
546+
547+
linkedProjThumb->setScale(1.f);
548+
linkedProjThumb->setScale(linkedProjClippingNode->getScaledContentHeight() / linkedProjThumb->getScaledContentHeight());
549+
550+
linkedProjThumb->setPosition(linkedProjClippingNode->getPosition());
551+
linkedProjThumb->ignoreAnchorPointForPosition(false);
552+
linkedProjThumb->setColor({ 250, 250, 250 });
553+
linkedProjThumb->setOpacity(250);
554+
} else {
555+
AVAL_LOG_ERROR("Failed to load linked project thumbnail: {}", res.unwrapErr());
556+
linkedProjThumb->removeMeAndCleanup();
557+
};
558+
});
559+
560+
std::string encodedShowcaseUrl = url_encode(linkedProj.showcase); // encode the showcase url for use in the thumbnail url
561+
std::string linkedProjThumbURL = fmt::format("https://api.cubicstudios.xyz/avalanche/v1/fetch/yt-thumbnails?url={}", (std::string)encodedShowcaseUrl); // custom thumbnail
562+
563+
AVAL_LOG_DEBUG("Getting linked project thumbnail at {}...", (std::string)linkedProjThumbURL);
564+
linkedProjThumb->loadFromUrl(linkedProjThumbURL, LazySprite::Format::kFmtUnKnown, false);
565+
if (linkedProjThumb) linkedProjClippingNode->addChild(linkedProjThumb);
576566
} else {
577-
AVAL_LOG_INFO("Using custom thumbnail URL {}", linkedProj.thumbnail);
578-
isCustomThumbnail = true;
567+
AVAL_LOG_DEBUG("Linked project thumbnail setting is disabled, not adding thumbnail to linked project container");
579568
};
580569

581-
std::string encodedShowcaseUrl = url_encode(linkedProj.showcase); // encode the showcase url for use in the thumbnail url
582-
std::string linkedProjThumbURL = isCustomThumbnail ? m_avalProject.thumbnail : fmt::format("https://api.cubicstudios.xyz/avalanche/v1/fetch/thumbnails?id={}", (int)m_avalProject.link_to_main.level_id); // custom thumbnail or default
583-
584-
AVAL_LOG_DEBUG("Getting linked project thumbnail at {}...", linkedProjThumbURL);
585-
linkedProjThumb->loadFromUrl(linkedProjThumbURL, LazySprite::Format::kFmtUnKnown, false);
586-
if (linkedProjThumb) linkedProjClippingNode->addChild(linkedProjThumb);
587-
588570
// set border
589571
auto linkedProjBorder = CCScale9Sprite::create("GJ_square07.png");
590572
linkedProjBorder->setID("border");

0 commit comments

Comments
 (0)