Skip to content

Commit 7615e30

Browse files
committed
clean dat code!
1 parent 76fe059 commit 7615e30

8 files changed

Lines changed: 283 additions & 438 deletions

File tree

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"developer": "ArcticWoof",
1313
"description": "Horrible Geode Mod Ideas",
1414
"settings": {
15-
"safe_mode": {
15+
"safe-mode": {
1616
"type": "bool",
1717
"name": "Safe Mode",
1818
"description": "Prevent any progression made in the level. <cr>Highly recommended that this is kept enabled!</cr>",

src/RandomSeeder.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <ctime>
2+
#include <cstdlib>
3+
4+
struct RandomSeeder {
5+
RandomSeeder() { srand(time(0)); }
6+
};

src/main.cpp

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
#include <Geode/binding/FMODAudioEngine.hpp>
1515

16-
struct RandomSeeder
17-
{
16+
struct RandomSeeder {
1817
RandomSeeder() { srand(time(0)); }
1918
};
2019
static RandomSeeder _randomSeeder;
@@ -27,15 +26,12 @@ auto horribleMod = getMod();
2726

2827
bool isFlipped = false;
2928

30-
class $modify(HorribleCCScene, CCScene)
31-
{
32-
bool init() override
33-
{
29+
class $modify(HorribleCCScene, CCScene) {
30+
bool init() override {
3431
if (!CCScene::init())
3532
return false;
3633

37-
if (typeinfo_cast<CCTransitionFade *>(this))
38-
{
34+
if (typeinfo_cast<CCTransitionFade*>(this)) {
3935
log::debug("scene is a CCTransitionFade");
4036
return true;
4137
}
@@ -47,17 +43,13 @@ class $modify(HorribleCCScene, CCScene)
4743
};
4844

4945
// modify CCMenuItem so it plays the sound whenever a button is clicked regardless of the layer
50-
class $modify(HorribleCCMenuItem, CCMenuItem)
51-
{
52-
void activate() override
53-
{
46+
class $modify(HorribleCCMenuItem, CCMenuItem) {
47+
void activate() override {
5448
auto rnd = rand() % 101;
5549
log::debug("button menu chance {}", rnd);
5650

57-
if (horribleMod && horribleMod->getSavedValue<bool>("achieve", true))
58-
{
59-
if (auto fmod = FMODAudioEngine::sharedEngine())
60-
{
51+
if (horribleMod && horribleMod->getSavedValue<bool>("achieve", true)) {
52+
if (auto fmod = FMODAudioEngine::sharedEngine()) {
6153

6254
if (rnd <= 75)
6355
// @geode-ignore(unknown-resource)
@@ -69,10 +61,8 @@ class $modify(HorribleCCMenuItem, CCMenuItem)
6961
};
7062
};
7163

72-
class $modify(HorribleMenuLayer, MenuLayer)
73-
{
74-
bool init()
75-
{
64+
class $modify(HorribleMenuLayer, MenuLayer) {
65+
bool init() {
7666
if (!MenuLayer::init())
7767
return false;
7868

@@ -86,8 +76,7 @@ class $modify(HorribleMenuLayer, MenuLayer)
8676
auto rnd = rand() % 101;
8777
log::debug("chance {}", rnd);
8878

89-
if (auto bottomMenu = this->getChildByID("bottom-menu"))
90-
{
79+
if (auto bottomMenu = getChildByID("bottom-menu")) {
9180
auto btnSprite = CircleButtonSprite::createWithSpriteFrameName(
9281
"GJ_moonsIcon_001.png",
9382
0.875f,
@@ -100,29 +89,25 @@ class $modify(HorribleMenuLayer, MenuLayer)
10089
menu_selector(HorribleMenuLayer::onHorribleButton));
10190
btn->setID("horribleBtn");
10291

103-
if (auto menu = typeinfo_cast<CCMenu *>(bottomMenu))
104-
{
92+
if (auto menu = typeinfo_cast<CCMenu*>(bottomMenu)) {
10593
menu->addChild(btn);
10694
menu->updateLayout(true);
10795
};
10896
};
10997

11098
// Show a LazySprite for the first PNG found in the save directory
111-
if (horribleMod && horribleMod->getSavedValue<bool>("mock", false))
112-
{
99+
if (horribleMod && horribleMod->getSavedValue<bool>("mock", false)) {
113100
log::debug("mock feature enabled in MainMenu layer");
114101

115102
namespace fs = std::filesystem;
116103

117-
if (rnd <= 75)
118-
{
104+
if (rnd <= 75) {
119105
auto mockConfigPath = fmt::format("{}\\mock.json", horribleMod->getSaveDir());
120106
auto mockConfig = file::readJson(fs::path(mockConfigPath));
121107

122108
log::debug("Reading path {}...", mockConfigPath);
123109

124-
if (mockConfig.isOk())
125-
{
110+
if (mockConfig.isOk()) {
126111
log::debug("Read mocking config file");
127112

128113
auto mockConfigUnwr = mockConfig.unwrapOr(Value());
@@ -133,24 +118,22 @@ class $modify(HorribleMenuLayer, MenuLayer)
133118
auto id = lvlUnwr->getKey().value_or("");
134119
auto percent = lvlUnwr->asInt().unwrapOr(99);
135120

136-
if (!id.empty())
137-
{
121+
if (!id.empty()) {
138122
log::debug("ID {} with percentage {} is valid", id, percent);
139123

140124
std::string pngPath = fmt::format("{}\\{}.png", horribleMod->getSaveDir(), id);
141125
;
142126

143127
log::info("Displaying {}", pngPath);
144128

145-
auto ss = LazySprite::create({192.f, 108.f});
129+
auto ss = LazySprite::create({ 192.f, 108.f });
146130
ss->setID("mock"_spr);
147131
ss->setScale(0.25);
148-
ss->setAnchorPoint({0.5, 0.5});
132+
ss->setAnchorPoint({ 0.5, 0.5 });
149133
ss->setZOrder(1000);
150-
ss->setPosition({-192.f, -108.f});
134+
ss->setPosition({ -192.f, -108.f });
151135

152-
ss->setLoadCallback([this, ss, percent, rnd](Result<> res)
153-
{
136+
ss->setLoadCallback([this, ss, percent, rnd](Result<> res) {
154137
if (res.isOk()) {
155138
log::info("Sprite loaded successfully from save dir PNG");
156139

@@ -184,16 +167,12 @@ class $modify(HorribleMenuLayer, MenuLayer)
184167
ss->removeMeAndCleanup();
185168
}; });
186169

187-
ss->loadFromFile(fs::path(pngPath));
188-
addChild(ss);
189-
}
190-
else
191-
{
170+
ss->loadFromFile(fs::path(pngPath));
171+
addChild(ss);
172+
} else {
192173
log::error("ID is invalid");
193174
};
194-
}
195-
else
196-
{
175+
} else {
197176
log::error("Mocking data file not found");
198177
};
199178
};
@@ -202,9 +181,7 @@ class $modify(HorribleMenuLayer, MenuLayer)
202181
return true;
203182
};
204183

205-
void onHorribleButton(CCObject *)
206-
{
207-
if (auto popup = HorribleMenuPopup::create())
208-
popup->show();
184+
void onHorribleButton(CCObject*) {
185+
if (auto popup = HorribleMenuPopup::create()) popup->show();
209186
};
210187
};

src/modified/GJBaseGameLayer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "../RandomSeeder.hpp"
2+
13
#include <Geode/Geode.hpp>
24

35
#include <Geode/utils/terminate.hpp>
@@ -6,13 +8,15 @@
68

79
using namespace geode::prelude;
810

11+
static RandomSeeder _randomSeeder;
12+
913
class $modify(HorribleGJBaseGameLayer, GJBaseGameLayer) {
1014
void handleButton(bool down, int button, bool isPlayer1) {
1115
auto horribleMod = getMod();
1216

1317
if (horribleMod->getSavedValue<bool>("no-jump", false) && !m_isPlatformer) {
1418
if (button == 1) {
15-
if ((rand() % 11) == 0) {
19+
if ((rand() % 101) <= 11) {
1620
log::error("skipped dat jump");
1721
GJBaseGameLayer::handleButton(false, button, isPlayer1);
1822
} else {

src/modified/GJGameLevel.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,15 @@
66

77
using namespace geode::prelude;
88

9-
class $modify(HorribleGJGameLevel, GJGameLevel)
10-
{
11-
void savePercentage(int percent, bool isPracticeMode, int clicks, int attempts, bool isChkValid)
12-
{
9+
class $modify(HorribleGJGameLevel, GJGameLevel) {
10+
void savePercentage(int percent, bool isPracticeMode, int clicks, int attempts, bool isChkValid) {
11+
auto safeMode = Mod::get()->getSettingValue<bool>("safe-mode");
1312

14-
auto safeMode = Mod::get()->getSettingValue<bool>("safe_mode");
15-
16-
if (!safeMode)
17-
{
13+
if (!safeMode) {
1814
GJGameLevel::savePercentage(percent, isPracticeMode, clicks, attempts, isChkValid);
1915
return;
20-
}
21-
else
22-
{
23-
log::info("Safe mode is enabled. dont save");
24-
}
25-
}
16+
} else {
17+
log::warn("Safe mode is enabled");
18+
};
19+
};
2620
};

0 commit comments

Comments
 (0)