Skip to content

Commit

Permalink
yeah let's not
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjustin000 committed Nov 24, 2024
1 parent 744a2a6 commit f272ff1
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 10 additions & 3 deletions src/DemonsInBetween.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/DemonsInBetween.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
44 changes: 29 additions & 15 deletions src/hooks/LevelCell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,46 @@ class $modify(DIBLevelCell, LevelCell) {
void loadFromLevel(GJGameLevel* level) {
LevelCell::loadFromLevel(level);

if (!Mod::get()->getSettingValue<bool>("enable-difficulties")) return;
if (level->m_stars.value() < 10 || !Mod::get()->getSettingValue<bool>("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<GJDifficultySprite*>(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<bool>("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<CCSprite*>(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);
}
}
};
39 changes: 29 additions & 10 deletions src/hooks/LevelInfoLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>("enable-difficulties")) createDemon = false;

auto gddpDifficulty = getChildByID("gddp-difficulty");
if (gddpDifficulty && !Mod::get()->getSettingValue<bool>("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;
}
Expand Down Expand Up @@ -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)
Expand All @@ -91,13 +107,16 @@ class $modify(DIBLevelInfoLayer, LevelInfoLayer) {
leftSideMenu->addChild(demonInfoButton);
leftSideMenu->updateLayout();

if (getChildByID("grd-difficulty") || !Mod::get()->getSettingValue<bool>("enable-difficulties")) return;
if (!createDemon) return;

auto gddpDifficulty = getChildByID("gddp-difficulty");
if (gddpDifficulty && !Mod::get()->getSettingValue<bool>("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<CCSprite*>(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);
}
}
};

0 comments on commit f272ff1

Please sign in to comment.