Skip to content

Commit 6049f86

Browse files
parry
1 parent 4f4bce1 commit 6049f86

3 files changed

Lines changed: 261 additions & 119 deletions

File tree

src/main.cpp

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,55 @@ using namespace matjson;
1616

1717
auto horribleMod = getMod();
1818

19-
class $modify(HorribleCCLayer, CCLayer) {
20-
bool init() {
21-
if (!CCLayer::init()) return false;
19+
class $modify(HorribleCCLayer, CCLayer)
20+
{
21+
bool init()
22+
{
23+
if (!CCLayer::init())
24+
return false;
2225

23-
log::debug("Hooked Cocos layer {}", this->getID());
26+
// log::debug("Hooked Cocos layer {}", this->getID());
2427

25-
queueInMainThread([this]() {
28+
queueInMainThread([this]()
29+
{
2630
auto del = CCDelayTime::create(0.25f); // use another cc class
2731

2832
if (horribleMod && horribleMod->getSavedValue<bool>("upside-down", false)) {
2933
if ((rand() % 50) == 0) setRotation(-180.f);
30-
};
31-
});
34+
}; });
3235

3336
return true;
3437
};
3538
};
3639

3740
// modify CCMenuItem so it plays the sound whenever a button is clicked regardless of the layer
38-
class $modify(HorribleCCMenuItem, CCMenuItem) {
39-
void activate() override {
40-
if (horribleMod && horribleMod->getSavedValue<bool>("achieve", true)) {
41-
if (auto fmod = FMODAudioEngine::sharedEngine()) {
41+
class $modify(HorribleCCMenuItem, CCMenuItem)
42+
{
43+
void activate() override
44+
{
45+
if (horribleMod && horribleMod->getSavedValue<bool>("achieve", true))
46+
{
47+
if (auto fmod = FMODAudioEngine::sharedEngine())
48+
{
4249
// @geode-ignore(unknown-resource)
43-
if ((rand() % 75) == 0) fmod->playEffect("achievement_01.ogg"); // 75% chance of playing
50+
if ((rand() % 75) == 0)
51+
fmod->playEffect("achievement_01.ogg"); // 75% chance of playing
4452
};
4553
};
4654

4755
CCMenuItem::activate();
4856
};
4957
};
5058

51-
class $modify(HorribleMenuLayer, MenuLayer) {
52-
bool init() {
53-
if (!MenuLayer::init()) return false;
59+
class $modify(HorribleMenuLayer, MenuLayer)
60+
{
61+
bool init()
62+
{
63+
if (!MenuLayer::init())
64+
return false;
5465

55-
if (auto bottomMenu = this->getChildByID("bottom-menu")) {
66+
if (auto bottomMenu = this->getChildByID("bottom-menu"))
67+
{
5668
auto btnSprite = CircleButtonSprite::createWithSpriteFrameName(
5769
"GJ_moonsIcon_001.png",
5870
0.875f,
@@ -65,25 +77,29 @@ class $modify(HorribleMenuLayer, MenuLayer) {
6577
menu_selector(HorribleMenuLayer::onHorribleButton));
6678
btn->setID("horribleBtn");
6779

68-
if (auto menu = typeinfo_cast<CCMenu*>(bottomMenu)) {
80+
if (auto menu = typeinfo_cast<CCMenu *>(bottomMenu))
81+
{
6982
menu->addChild(btn);
7083
menu->updateLayout(true);
7184
};
7285
};
7386

7487
// Show a LazySprite for the first PNG found in the save directory
75-
if (horribleMod && horribleMod->getSavedValue<bool>("mock", false)) {
88+
if (horribleMod && horribleMod->getSavedValue<bool>("mock", false))
89+
{
7690
log::debug("mock feature enabled in MainMenu layer");
7791

7892
namespace fs = std::filesystem;
7993

80-
if ((rand() % 75) == 0) {
94+
if ((rand() % 75) == 0)
95+
{
8196
auto mockConfigPath = fmt::format("{}\\mock.json", horribleMod->getSaveDir());
8297
auto mockConfig = file::readJson(fs::path(mockConfigPath));
8398

8499
log::debug("Reading path {}...", mockConfigPath);
85100

86-
if (mockConfig.isOk()) {
101+
if (mockConfig.isOk())
102+
{
87103
log::debug("Read mocking config file");
88104

89105
auto mockConfigUnwr = mockConfig.unwrapOr(Value());
@@ -94,21 +110,24 @@ class $modify(HorribleMenuLayer, MenuLayer) {
94110
auto id = lvlUnwr->getKey().value_or("");
95111
auto percent = lvlUnwr->asInt().unwrapOr(99);
96112

97-
if (!id.empty()) {
113+
if (!id.empty())
114+
{
98115
log::debug("ID {} with percentage {} is valid", id, percent);
99116

100-
std::string pngPath = fmt::format("{}\\{}.png", horribleMod->getSaveDir(), id);;
117+
std::string pngPath = fmt::format("{}\\{}.png", horribleMod->getSaveDir(), id);
118+
;
101119

102120
log::info("Displaying {}", pngPath);
103121

104-
auto ss = LazySprite::create({ 192.f, 108.f });
122+
auto ss = LazySprite::create({192.f, 108.f});
105123
ss->setID("mock"_spr);
106124
ss->setScale(0.25);
107-
ss->setAnchorPoint({ 0.5, 0.5 });
125+
ss->setAnchorPoint({0.5, 0.5});
108126
ss->setZOrder(1000);
109-
ss->setPosition({ -192.f, -108.f });
127+
ss->setPosition({-192.f, -108.f});
110128

111-
ss->setLoadCallback([this, ss, percent](Result<> res) {
129+
ss->setLoadCallback([this, ss, percent](Result<> res)
130+
{
112131
if (res.isOk()) {
113132
log::info("Sprite loaded successfully from save dir PNG");
114133

@@ -140,15 +159,18 @@ class $modify(HorribleMenuLayer, MenuLayer) {
140159
} else {
141160
log::error("Sprite failed to load: {}", res.unwrapErr());
142161
ss->removeMeAndCleanup();
143-
};
144-
});
162+
}; });
145163

146164
ss->loadFromFile(fs::path(pngPath));
147165
addChild(ss);
148-
} else {
166+
}
167+
else
168+
{
149169
log::error("ID is invalid");
150170
};
151-
} else {
171+
}
172+
else
173+
{
152174
log::error("Mocking data file not found");
153175
};
154176
};
@@ -157,7 +179,9 @@ class $modify(HorribleMenuLayer, MenuLayer) {
157179
return true;
158180
};
159181

160-
void onHorribleButton(CCObject*) {
161-
if (auto popup = HorribleMenuPopup::create()) popup->show();
182+
void onHorribleButton(CCObject *)
183+
{
184+
if (auto popup = HorribleMenuPopup::create())
185+
popup->show();
162186
};
163187
};

0 commit comments

Comments
 (0)