Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Apr 27, 2024
1 parent 0d337a8 commit 1f4e2af
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ jobs:
- name: Build the mod
uses: geode-sdk/build-geode-mod@main
with:
bindings: hiimjustin000/bindings
bindings-ref: patch-1
build-config: RelWithDebInfo
export-pdb: true
combine: true
target: ${{ matrix.config.target }}

Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ project(FakeRate VERSION 1.0.0)
add_library(${PROJECT_NAME} SHARED
src/main.cpp
src/FREditPopup.cpp
src/FRUtilities.cpp
)

if (NOT DEFINED ENV{GEODE_SDK})
Expand Down
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Fake Rate Changelog
## v1.1.0 (2024-04-26)
- Fixed incompatibility with the mod "More Difficulties" by uproxide

## v1.0.0 (2024-04-24)
- Initial release
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.204",
"mac": "2.200"
},
"version": "v1.0.0",
"version": "v1.1.0",
"id": "hiimjustin000.fake_rate",
"name": "Fake Rate",
"developer": "hiimjustin000",
Expand Down
146 changes: 90 additions & 56 deletions src/FREditPopup.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,10 @@
#include "FREditPopup.hpp"

int FRLevelInfoLayer::getBaseCurrency(int stars) {
switch (stars) {
case 2:
return 40;
case 3:
return 60;
case 4:
return 100;
case 5:
return 140;
case 6:
return 180;
case 7:
return 220;
case 8:
return 280;
case 9:
return 340;
case 10:
return 400;
default:
return 0;
}
}

int FRLevelInfoLayer::getDifficultyFromLevel(GJGameLevel* level) {
auto difficulty = level->getAverageDifficulty();
if (level->m_demon > 0) switch (level->m_demonDifficulty) {
case 3: difficulty = 7; break;
case 4: difficulty = 8; break;
case 5: difficulty = 9; break;
case 6: difficulty = 10; break;
default: difficulty = 6; break;
}
return difficulty;
void FRLevelInfoLayer::onModify(auto& self) {
(void)self.setHookPriority("LevelInfoLayer::init", -100);
(void)self.setHookPriority("LevelInfoLayer::levelDownloadFinished", -100);
(void)self.setHookPriority("LevelInfoLayer::levelUpdateFinished", -100);
(void)self.setHookPriority("LevelInfoLayer::likedItem", -100);
}

bool FRLevelInfoLayer::init(GJGameLevel* level, bool challenge) {
Expand All @@ -49,19 +19,35 @@ bool FRLevelInfoLayer::init(GJGameLevel* level, bool challenge) {
leftSideMenu->addChild(fakeRateButton);
leftSideMenu->updateLayout();

checkFakeRate();

return true;
}

void FRLevelInfoLayer::updateLabelValues() {
LevelInfoLayer::updateLabelValues();
void FRLevelInfoLayer::levelDownloadFinished(GJGameLevel* level) {
LevelInfoLayer::levelDownloadFinished(level);
checkFakeRate();
}

void FRLevelInfoLayer::levelUpdateFinished(GJGameLevel* level, UpdateResponse response) {
LevelInfoLayer::levelUpdateFinished(level, response);
checkFakeRate();
}

void FRLevelInfoLayer::likedItem(LikeItemType type, int id, bool liked) {
LevelInfoLayer::likedItem(type, id, liked);
checkFakeRate();
}

void FRLevelInfoLayer::checkFakeRate() {
auto vec = Mod::get()->getSavedValue<std::vector<FakeRateSaveData>>("fake-rate", {});
auto it = std::find_if(vec.begin(), vec.end(), [this](auto const& item) { return item.id == m_level->m_levelID; });
if (it != vec.end()) updateFakeRate(it->stars, it->feature, it->difficulty, false, true);
else m_fields->m_fakeRateData = {
.id = m_level->m_levelID,
.stars = m_level->m_stars,
.feature = m_level->m_featured > 1 ? m_level->m_isEpic + 1 : 0,
.difficulty = getDifficultyFromLevel(m_level)
.difficulty = FRUtilities::getDifficultyFromLevel(m_level)
};
}

Expand Down Expand Up @@ -121,16 +107,17 @@ void FRLevelInfoLayer::updateFakeRate(int stars, int feature, int difficulty, bo
if (showStars) {
m_orbsIcon->setPositionY(yPos - yOffset * 2.0f);
m_orbsLabel->setPositionY(m_orbsIcon->getPositionY());
auto orbs = FRLevelInfoLayer::getBaseCurrency(stars);
auto orbs = FRUtilities::getBaseCurrency(stars);
auto totalOrbs = (int)floorf(orbs * 1.25f);
m_orbsLabel->setString(fmt::format("{}/{}", (int)floorf(orbs * m_level->m_orbCompletion / 100.0f), totalOrbs).c_str());
m_orbsLabel->limitLabelWidth(60.0f, 0.5f, 0.0f);
}
auto exactTime = static_cast<CCLabelBMFont*>(getChildByID("cvolton.betterinfo/exact-time"));
if (exactTime) {
if (auto exactTime = static_cast<CCLabelBMFont*>(getChildByID("cvolton.betterinfo/exact-time"))) {
exactTime->setPositionY(m_lengthLabel->getPositionY() - 2.0f);
m_lengthLabel->setPositionY(m_lengthLabel->getPositionY() + 6.0f);
}

if (Loader::get()->isModLoaded("uproxide.more_difficulties")) fixMoreDifficultiesIncompatibility();
}

void FRLevelInfoLayer::onFakeRate(CCObject*) {
Expand All @@ -144,6 +131,41 @@ void FRLevelInfoLayer::onFakeRate(CCObject*) {
popup->show();
}

void FRLevelInfoLayer::fixMoreDifficultiesIncompatibility() {
if (auto existingCasualSprite = static_cast<CCSprite*>(FRUtilities::getChildBySpriteName(this, "uproxide.more_difficulties/MD_Difficulty04.png")))
existingCasualSprite->removeFromParent();
if (auto existingToughSprite = static_cast<CCSprite*>(FRUtilities::getChildBySpriteName(this, "uproxide.more_difficulties/MD_Difficulty07.png")))
existingToughSprite->removeFromParent();
if (auto existingCruelSprite = static_cast<CCSprite*>(FRUtilities::getChildBySpriteName(this, "uproxide.more_difficulties/MD_Difficulty09.png")))
existingCruelSprite->removeFromParent();

m_difficultySprite->setOpacity(255);
auto pos = CCPoint { m_difficultySprite->getPositionX() + 0.25f, m_difficultySprite->getPositionY() - 0.1f };
switch (m_fields->m_fakeRateData.stars) {
case 4: {
auto casualSprite = CCSprite::create("uproxide.more_difficulties/MD_Difficulty04.png");
casualSprite->setPosition(pos);
addChild(casualSprite, 3);
m_difficultySprite->setOpacity(0);
break;
}
case 7: {
auto toughSprite = CCSprite::create("uproxide.more_difficulties/MD_Difficulty07.png");
toughSprite->setPosition(pos);
addChild(toughSprite, 3);
m_difficultySprite->setOpacity(0);
break;
}
case 9: {
auto cruelSprite = CCSprite::create("uproxide.more_difficulties/MD_Difficulty09.png");
cruelSprite->setPosition(pos);
addChild(cruelSprite, 3);
m_difficultySprite->setOpacity(0);
break;
}
}
}

FREditPopup* FREditPopup::create(GJGameLevel* level, int stars, int feature, int difficulty) {
auto ret = new FREditPopup();
if (ret && ret->initAnchored(200.0f, 150.0f, level, stars, feature, difficulty)) {
Expand All @@ -154,20 +176,6 @@ FREditPopup* FREditPopup::create(GJGameLevel* level, int stars, int feature, int
return nullptr;
}

int FREditPopup::getDifficultyForStars(int stars) {
switch (stars) {
case 0: return 0;
case 1: return -1;
case 2: return 1;
case 3: return 2;
case 4: case 5: return 3;
case 6: case 7: return 4;
case 8: case 9: return 5;
case 10: return 6;
default: return 0;
}
}

bool FREditPopup::setup(GJGameLevel* level, int stars, int feature, int difficulty) {
setTitle("Fake Rate");
m_level = level;
Expand All @@ -179,6 +187,25 @@ bool FREditPopup::setup(GJGameLevel* level, int stars, int feature, int difficul
m_difficultySprite->setPositionX(100.0f);
m_mainLayer->addChild(m_difficultySprite);

if (Loader::get()->isModInstalled("uproxide.more_difficulties")) {
auto pos = CCPoint { 100.25f, 84.9f };

m_casualSprite = CCSprite::create("uproxide.more_difficulties/MD_Difficulty04.png");
m_casualSprite->setPosition(pos);
m_casualSprite->setVisible(false);
m_mainLayer->addChild(m_casualSprite);

m_toughSprite = CCSprite::create("uproxide.more_difficulties/MD_Difficulty07.png");
m_toughSprite->setPosition(pos);
m_toughSprite->setVisible(false);
m_mainLayer->addChild(m_toughSprite);

m_cruelSprite = CCSprite::create("uproxide.more_difficulties/MD_Difficulty09.png");
m_cruelSprite->setPosition(pos);
m_cruelSprite->setVisible(false);
m_mainLayer->addChild(m_cruelSprite);
}

m_starSprite = CCSprite::createWithSpriteFrameName(m_level->m_levelLength < 5 ? "star_small01_001.png" : "moon_small01_001.png");
m_mainLayer->addChild(m_starSprite);

Expand Down Expand Up @@ -286,7 +313,7 @@ void FREditPopup::onFeatureRight(CCObject*) {
}

void FREditPopup::updateLabels() {
m_difficulty = m_stars >= 10 ? m_difficulty > 5 ? m_difficulty : 7 : getDifficultyForStars(m_stars);
m_difficulty = m_stars >= 10 ? m_difficulty > 5 ? m_difficulty : 7 : FRUtilities::getDifficultyForStars(m_stars);
m_difficultySprite->updateDifficultyFrame(m_difficulty, (GJDifficultyName)1);
m_difficultySprite->updateFeatureState((GJFeatureState)m_feature);
m_difficultySprite->setPositionY(85.0f + (m_difficulty > 5 ? 5.0f : 0.0f));
Expand All @@ -301,6 +328,13 @@ void FREditPopup::updateLabels() {
m_difficultyRightArrow->setEnabled(m_difficulty > 5);
m_featureLeftArrow->setPositionY(m_difficultySprite->getPositionY() + 5.0f);
m_featureRightArrow->setPositionY(m_difficultySprite->getPositionY() + 5.0f);
if (Loader::get()->isModInstalled("uproxide.more_difficulties")) {
m_casualSprite->setVisible(m_stars == 4);
m_toughSprite->setVisible(m_stars == 7);
m_cruelSprite->setVisible(m_stars == 9);
if (m_stars == 4 || m_stars == 7 || m_stars == 9) m_difficultySprite->setOpacity(0);
else m_difficultySprite->setOpacity(255);
}
}

void FREditPopup::onAdd(CCObject*) {
Expand Down
19 changes: 11 additions & 8 deletions src/FREditPopup.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <vector>
#include <Geode/Geode.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>

using namespace geode::prelude;
#include "FRUtilities.hpp"

struct FakeRateSaveData {
int id;
Expand All @@ -11,16 +9,19 @@ struct FakeRateSaveData {
int difficulty;
};

class FRLevelInfoLayerDummy; struct FRLevelInfoLayer : geode::Modify<FRLevelInfoLayer, LevelInfoLayer> {
class FRLevelInfoLayerDummy; struct FRLevelInfoLayer : Modify<FRLevelInfoLayer, LevelInfoLayer> {
struct Fields {
FakeRateSaveData m_fakeRateData;
};
static int getDifficultyFromLevel(GJGameLevel*);
static int getBaseCurrency(int);
static void onModify(auto& self);
bool init(GJGameLevel*, bool);
void updateLabelValues();
void levelDownloadFinished(GJGameLevel*);
void levelUpdateFinished(GJGameLevel*, UpdateResponse);
void likedItem(LikeItemType, int, bool);
void checkFakeRate();
void updateFakeRate(int, int, int, bool, bool);
void onFakeRate(CCObject*);
void fixMoreDifficultiesIncompatibility();
};

class FREditPopup : public Popup<GJGameLevel*, int, int, int> {
Expand All @@ -30,6 +31,9 @@ class FREditPopup : public Popup<GJGameLevel*, int, int, int> {
int m_feature;
int m_difficulty;
GJDifficultySprite* m_difficultySprite;
CCSprite* m_casualSprite;
CCSprite* m_toughSprite;
CCSprite* m_cruelSprite;
CCSprite* m_starSprite;
CCLabelBMFont* m_starsLabel;
CCMenuItemSpriteExtra* m_starLeftArrow;
Expand All @@ -44,7 +48,6 @@ class FREditPopup : public Popup<GJGameLevel*, int, int, int> {
public:
FRLevelInfoLayer* m_delegate;
static FREditPopup* create(GJGameLevel*, int, int, int);
static int getDifficultyForStars(int);

void onStarLeft(CCObject*);
void onStarRight(CCObject*);
Expand Down
67 changes: 67 additions & 0 deletions src/FRUtilities.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "FRUtilities.hpp"

int FRUtilities::getBaseCurrency(int stars) {
switch (stars) {
case 2: return 40;
case 3: return 60;
case 4: return 100;
case 5: return 140;
case 6: return 180;
case 7: return 220;
case 8: return 280;
case 9: return 340;
case 10: return 400;
default: return 0;
}
}

CCNode* FRUtilities::getChildBySpriteName(CCNode* parent, const char* name) {
for (auto child : CCArrayExt<CCNode*>(parent->getChildren())) {
if (isSpriteName(static_cast<CCNode*>(child), name)) return child;
}
return nullptr;
}

int FRUtilities::getDifficultyForStars(int stars) {
switch (stars) {
case 0: return 0;
case 1: return -1;
case 2: return 1;
case 3: return 2;
case 4: case 5: return 3;
case 6: case 7: return 4;
case 8: case 9: return 5;
case 10: return 6;
default: return 0;
}
}

int FRUtilities::getDifficultyFromLevel(GJGameLevel* level) {
auto difficulty = level->getAverageDifficulty();
if (level->m_demon > 0) switch (level->m_demonDifficulty) {
case 3: difficulty = 7; break;
case 4: difficulty = 8; break;
case 5: difficulty = 9; break;
case 6: difficulty = 10; break;
default: difficulty = 6; break;
}
return difficulty;
}

bool FRUtilities::isSpriteName(CCNode* node, const char* name) {
if (!node) return false;

auto texture = CCTextureCache::sharedTextureCache()->textureForKey(name);
if (!texture) return false;

if (auto* spr = typeinfo_cast<CCSprite*>(node)) {
if (spr->getTexture() == texture) return true;
}
else if (auto* btn = typeinfo_cast<CCMenuItemSprite*>(node)) {
auto* img = btn->getNormalImage();
if (auto* spr = typeinfo_cast<CCSprite*>(img)) {
if (spr->getTexture() == texture) return true;
}
}
return false;
}
12 changes: 12 additions & 0 deletions src/FRUtilities.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <Geode/Geode.hpp>

using namespace geode::prelude;

class FRUtilities {
public:
static int getBaseCurrency(int);
static CCNode* getChildBySpriteName(CCNode*, const char*);
static int getDifficultyForStars(int);
static int getDifficultyFromLevel(GJGameLevel*);
static bool isSpriteName(CCNode*, const char*);
};
Loading

0 comments on commit 1f4e2af

Please sign in to comment.