From f272ff1ff5e9a278bc1707d9db2896dc88b379ac Mon Sep 17 00:00:00 2001 From: Justin Pridgen Date: Sun, 24 Nov 2024 00:44:12 -0500 Subject: [PATCH] yeah let's not --- CMakeLists.txt | 2 +- changelog.md | 3 +++ mod.json | 2 +- src/DemonsInBetween.cpp | 13 ++++++++--- src/DemonsInBetween.hpp | 1 + src/hooks/LevelCell.cpp | 44 ++++++++++++++++++++++++------------ src/hooks/LevelInfoLayer.cpp | 39 ++++++++++++++++++++++++-------- 7 files changed, 74 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3397d17..e37d0aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64") set(CMAKE_CXX_VISIBILITY_PRESET hidden) -project(DemonsInBetween VERSION 1.4.2) +project(DemonsInBetween VERSION 1.4.3) add_library(${PROJECT_NAME} SHARED src/classes/DIBInfoPopup.cpp diff --git a/changelog.md b/changelog.md index 2b49056..0d9f459 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,7 @@ # Demons In Between Changelog +## v1.4.3 (2024-11-24) +- Altered dynamic loading as to not break compatibility with other mods + ## v1.4.2 (2024-11-22) - Fixed level browsers not working diff --git a/mod.json b/mod.json index 638dd6e..890271f 100644 --- a/mod.json +++ b/mod.json @@ -5,7 +5,7 @@ "win": "2.2074", "mac": "2.2074" }, - "version": "v1.4.2", + "version": "v1.4.3", "id": "hiimjustin000.demons_in_between", "name": "Demons In Between", "developer": "hiimjustin000", diff --git a/src/DemonsInBetween.cpp b/src/DemonsInBetween.cpp index 5024167..c4e09ea 100644 --- a/src/DemonsInBetween.cpp +++ b/src/DemonsInBetween.cpp @@ -11,10 +11,17 @@ LadderDemon& DemonsInBetween::demonForLevel(int levelID, bool main) { return demon == gddl.end() ? empty : *demon; } +CCSpriteFrame* DemonsInBetween::spriteFrameForDifficulty(int difficulty, GJDifficultyName name, GJFeatureState state) { + return CCSpriteFrameCache::get()->spriteFrameByName(fmt::format( + "DIB_{:02d}{}_btn{}_001.png"_spr, + difficulty, + state == GJFeatureState::Legendary ? "_4" : state == GJFeatureState::Mythic ? "_5" : "", + name == GJDifficultyName::Long ? "2" : "" + ).c_str()); +} + CCSprite* DemonsInBetween::spriteForDifficulty(GJDifficultySprite* difficultySprite, int difficulty, GJDifficultyName name, GJFeatureState state) { - auto glow = state == GJFeatureState::Legendary ? "_4" : state == GJFeatureState::Mythic ? "_5" : ""; - auto sprite = CCSprite::createWithSpriteFrameName((name == GJDifficultyName::Long ? - fmt::format("DIB_{:02d}{}_btn2_001.png"_spr, difficulty, glow) : fmt::format("DIB_{:02d}{}_btn_001.png"_spr, difficulty, glow)).c_str()); + auto sprite = CCSprite::createWithSpriteFrame(spriteFrameForDifficulty(difficulty, name, state)); sprite->setPosition(difficultySprite->getPosition() + (name == GJDifficultyName::Long ? LONG_OFFSETS[(size_t)difficulty - 1] : SHORT_OFFSETS[(size_t)difficulty - 1])); sprite->setID("between-difficulty-sprite"_spr); diff --git a/src/DemonsInBetween.hpp b/src/DemonsInBetween.hpp index 0585d74..c0e600f 100644 --- a/src/DemonsInBetween.hpp +++ b/src/DemonsInBetween.hpp @@ -40,6 +40,7 @@ class DemonsInBetween { inline static bool SEARCHING = false; static LadderDemon& demonForLevel(int, bool); + static cocos2d::CCSpriteFrame* spriteFrameForDifficulty(int, GJDifficultyName, GJFeatureState); static cocos2d::CCSprite* spriteForDifficulty(GJDifficultySprite*, int, GJDifficultyName, GJFeatureState); static int difficultyForDemonDifficulty(int); static GJFeatureState stateForLevel(GJGameLevel*); diff --git a/src/hooks/LevelCell.cpp b/src/hooks/LevelCell.cpp index ff12d0d..4fd2690 100644 --- a/src/hooks/LevelCell.cpp +++ b/src/hooks/LevelCell.cpp @@ -15,32 +15,46 @@ class $modify(DIBLevelCell, LevelCell) { void loadFromLevel(GJGameLevel* level) { LevelCell::loadFromLevel(level); - if (!Mod::get()->getSettingValue("enable-difficulties")) return; + if (level->m_stars.value() < 10 || !Mod::get()->getSettingValue("enable-difficulties")) return; - auto levelID = level->m_levelID.value(); - auto demon = DemonsInBetween::demonForLevel(levelID, false); - if (demon.id != 0 && demon.difficulty != 0) { - createUI(demon); - return; - } - - DemonsInBetween::loadDemonForLevel(std::move(m_fields->m_listener), levelID, false, [this](LadderDemon& demon) { createUI(demon); }); - } - - void createUI(LadderDemon const& demon) { auto difficultyContainer = m_mainLayer->getChildByID("difficulty-container"); if (!difficultyContainer) difficultyContainer = m_mainLayer->getChildByID("grd-demon-icon-layer"); if (!difficultyContainer) return; auto difficultySprite = static_cast(difficultyContainer->getChildByID("difficulty-sprite")); - if (!difficultySprite->isVisible()) return; // We're just going to assume it's Grandpa Demon + if (!difficultySprite || !difficultySprite->isVisible()) return; // If invisible, we're just going to assume it's Grandpa Demon auto gddpDifficulty = difficultyContainer->getChildByID("gddp-difficulty"); if (gddpDifficulty && !Mod::get()->getSettingValue("gddp-integration-override")) return; else if (gddpDifficulty) gddpDifficulty->setVisible(false); - difficultyContainer->addChild(DemonsInBetween::spriteForDifficulty(difficultySprite, - demon.difficulty, GJDifficultyName::Short, DemonsInBetween::stateForLevel(m_level)), 3); + auto levelID = level->m_levelID.value(); + auto demon = DemonsInBetween::demonForLevel(levelID, false); + if (demon.id != 0 && demon.difficulty != 0) { + createUI(demon, difficultyContainer, difficultySprite); + return; + } + + difficultyContainer->addChild(DemonsInBetween::spriteForDifficulty( + difficultySprite, DemonsInBetween::difficultyForDemonDifficulty(level->m_demonDifficulty), + GJDifficultyName::Short, DemonsInBetween::stateForLevel(level) + ), 3); difficultySprite->setOpacity(0); + + DemonsInBetween::loadDemonForLevel(std::move(m_fields->m_listener), levelID, false, [this, difficultyContainer, difficultySprite](LadderDemon& demon) { + createUI(demon, difficultyContainer, difficultySprite); + }); + } + + void createUI(LadderDemon const& demon, CCNode* difficultyContainer, GJDifficultySprite* difficultySprite) { + if (auto betweenDifficultySprite = static_cast(difficultyContainer->getChildByID("between-difficulty-sprite"_spr))) { + betweenDifficultySprite->setDisplayFrame( + DemonsInBetween::spriteFrameForDifficulty(demon.difficulty, GJDifficultyName::Short, DemonsInBetween::stateForLevel(m_level))); + betweenDifficultySprite->setPosition(difficultySprite->getPosition() + DemonsInBetween::SHORT_OFFSETS[(size_t)demon.difficulty - 1]); + } else { + difficultyContainer->addChild(DemonsInBetween::spriteForDifficulty(difficultySprite, + demon.difficulty, GJDifficultyName::Short, DemonsInBetween::stateForLevel(m_level)), 3); + difficultySprite->setOpacity(0); + } } }; diff --git a/src/hooks/LevelInfoLayer.cpp b/src/hooks/LevelInfoLayer.cpp index c328cfa..1649d25 100644 --- a/src/hooks/LevelInfoLayer.cpp +++ b/src/hooks/LevelInfoLayer.cpp @@ -17,14 +17,30 @@ class $modify(DIBLevelInfoLayer, LevelInfoLayer) { if (level->m_stars.value() < 10) return true; + auto createDemon = true; + + if (getChildByID("grd-difficulty") || !Mod::get()->getSettingValue("enable-difficulties")) createDemon = false; + + auto gddpDifficulty = getChildByID("gddp-difficulty"); + if (gddpDifficulty && !Mod::get()->getSettingValue("gddp-integration-override")) createDemon = false; + else if (gddpDifficulty) gddpDifficulty->setVisible(false); + auto levelID = level->m_levelID.value(); auto demon = DemonsInBetween::demonForLevel(levelID, false); if (demon.id != 0 && demon.difficulty != 0) { - createUI(demon); + createUI(demon, createDemon); return true; } - DemonsInBetween::loadDemonForLevel(std::move(m_fields->m_listener), levelID, false, [this](LadderDemon& demon) { createUI(demon); }); + addChild(DemonsInBetween::spriteForDifficulty( + m_difficultySprite, DemonsInBetween::difficultyForDemonDifficulty(level->m_demonDifficulty), + GJDifficultyName::Long, DemonsInBetween::stateForLevel(level) + ), 3); + m_difficultySprite->setOpacity(0); + + DemonsInBetween::loadDemonForLevel(std::move(m_fields->m_listener), levelID, false, [this, createDemon](LadderDemon& demon) { + createUI(demon, createDemon); + }); return true; } @@ -80,7 +96,7 @@ class $modify(DIBLevelInfoLayer, LevelInfoLayer) { ), "OK")->show(); } - void createUI(LadderDemon const& demon) { + void createUI(LadderDemon const& demon, bool createDemon) { auto demonInfoButton = CCMenuItemSpriteExtra::create( CircleButtonSprite::createWithSpriteFrameName(fmt::format("DIB_{:02d}_001.png"_spr, demon.difficulty).c_str()), this, menu_selector(DIBLevelInfoLayer::onDemonInfo) @@ -91,13 +107,16 @@ class $modify(DIBLevelInfoLayer, LevelInfoLayer) { leftSideMenu->addChild(demonInfoButton); leftSideMenu->updateLayout(); - if (getChildByID("grd-difficulty") || !Mod::get()->getSettingValue("enable-difficulties")) return; + if (!createDemon) return; - auto gddpDifficulty = getChildByID("gddp-difficulty"); - if (gddpDifficulty && !Mod::get()->getSettingValue("gddp-integration-override")) return; - else if (gddpDifficulty) gddpDifficulty->setVisible(false); - - addChild(DemonsInBetween::spriteForDifficulty(m_difficultySprite, demon.difficulty, GJDifficultyName::Long, DemonsInBetween::stateForLevel(m_level)), 3); - m_difficultySprite->setOpacity(0); + if (auto betweenDifficultySprite = static_cast(getChildByID("between-difficulty-sprite"_spr))) { + betweenDifficultySprite->setDisplayFrame( + DemonsInBetween::spriteFrameForDifficulty(demon.difficulty, GJDifficultyName::Long, DemonsInBetween::stateForLevel(m_level))); + betweenDifficultySprite->setPosition(m_difficultySprite->getPosition() + DemonsInBetween::LONG_OFFSETS[(size_t)demon.difficulty - 1]); + } + else { + addChild(DemonsInBetween::spriteForDifficulty(m_difficultySprite, demon.difficulty, GJDifficultyName::Long, DemonsInBetween::stateForLevel(m_level)), 3); + m_difficultySprite->setOpacity(0); + } } };