11#include " popup/HorribleMenuPopup.hpp"
22
3+ #include < fmt/core.h>
4+
35#include < Geode/Geode.hpp>
46
5- #include < Geode/modify/CCMenuItem.hpp>
67#include < Geode/modify/MenuLayer.hpp>
8+ #include < Geode/modify/CCLayer.hpp>
9+ #include < Geode/modify/CCMenuItem.hpp>
710
811#include < Geode/binding/FMODAudioEngine.hpp>
912
1013using namespace geode ::prelude;
14+ using namespace geode ::utils;
15+ using namespace matjson ;
1116
1217auto horribleMod = getMod();
1318
19+ class $modify(HorribleCCLayer, CCLayer) {
20+ bool init () {
21+ if (!CCLayer::init ()) return false ;
22+
23+ log::debug (" Hooked Cocos layer {}" , getID ());
24+
25+ if (horribleMod && horribleMod->getSavedValue <bool >(" mock" , false )) {
26+ if (auto b = true ) { // change to random chance
27+ auto mockConfigPath = fmt::format (" {}\\ mock.json" , horribleMod->getSaveDir ());
28+ auto mockConfig = file::readJson (std::filesystem::path (mockConfigPath));
29+
30+ if (mockConfig.isOk ()) {
31+ auto mockConfigUnwr = mockConfig.unwrapOr (Value ());
32+
33+ std::srand (static_cast <unsigned int >(std::time (nullptr )));
34+ int randInd = std::rand () % mockConfigUnwr.size (); // random index of the matjson
35+
36+ auto lvl = mockConfigUnwr.get (as<size_t >(randInd));
37+
38+ if (lvl.isOk ()) {
39+ auto lvlUnwr = lvl.unwrap ();
40+
41+ auto id = lvlUnwr.getKey ().value_or (" " );
42+ auto percent = lvlUnwr.asInt ().unwrapOr (99 );
43+
44+ if (!id.empty ()) {
45+ std::string path = fmt::format (" {}\\ {}.png" , horribleMod->getSaveDir (), id);
46+
47+ // screenshot sprite
48+ auto ss = LazySprite::create ({ 192 .f , 108 .f });
49+ ss->setID (" mock" _spr);
50+ ss->setAnchorPoint ({ 0.5 , 0.5 });
51+ ss->setPosition ({ -192 .f , -108 .f });
52+
53+ ss->setLoadCallback ([this , ss, percent](Result<> res) {
54+ if (res.isOk ()) {
55+ // Success: scale and position the sprite
56+ log::info (" Sprite loaded successfully" );
57+
58+ float yA = as<float >(std::rand ()) / RAND_MAX ; // first y pos %
59+ float yB = as<float >(std::rand ()) / RAND_MAX ; // last y pos %
60+
61+ auto percLabelText = fmt::format (" {}%" , std::to_string (percent));
62+
63+ auto percLabel = CCLabelBMFont::create (percLabelText.c_str (), " bigFont.fnt" );
64+ percLabel->setPosition ({ ss->getScaledContentWidth () / 2 .f , ss->getScaledContentHeight () / 2 .f });
65+
66+ ss->setPositionY (getScaledContentHeight () * yA);
67+ ss->setRotation (360 .f * (yA * yB));
68+
69+ auto move = CCEaseIn::create (CCMoveTo::create (7 .5f , { getScaledContentWidth () + 192 .f , getScaledContentHeight () * yB }), 1 .f );
70+ auto rotate = CCEaseOut::create (CCRotateBy::create (12 .5f , 45 .f ), 1 .f );
71+
72+ auto action = CCSpawn::createWithTwoActions (move, rotate);
73+ ss->runAction (action);
74+
75+ log::info (" Animated sprite successfully" );
76+ } else {
77+ log::error (" Sprite failed to load: {}" , res.unwrapErr ());
78+ ss->removeMeAndCleanup ();
79+ };
80+ });
81+
82+ ss->loadFromFile (std::filesystem::path (path));
83+ addChild (ss);
84+ };
85+ };
86+ };
87+ };
88+ };
89+
90+ return true ;
91+ };
92+ };
93+
1494// modify CCMenuItem so it plays the sound whenever a button is clicked regardless of the layer
15- class $modify(HorribleMenuItem , CCMenuItem) {
95+ class $modify(HorribleCCMenuItem , CCMenuItem) {
1696 void activate () override {
1797 if (horribleMod && horribleMod->getSavedValue <bool >(" achieve" , true )) {
1898 if (auto fmod = FMODAudioEngine::sharedEngine ()) {
1999 // @geode-ignore(unknown-resource)
20- if ((rand () % 50 ) == 0 ) fmod->playEffect (" achievement_01.ogg" ); // 50/50 chance of playing
100+ if ((rand () % 75 ) == 0 ) fmod->playEffect (" achievement_01.ogg" ); // 75% chance of playing
21101 };
22102 };
23103
@@ -35,12 +115,14 @@ class $modify(MyMenuLayer, MenuLayer) {
35115 " GJ_moonsIcon_001.png" ,
36116 0 .875f ,
37117 CircleBaseColor::Green,
38- CircleBaseSize::MediumAlt);
118+ CircleBaseSize::MediumAlt
119+ );
39120
40121 auto btn = CCMenuItemSpriteExtra::create (
41122 btnSprite,
42123 this ,
43- menu_selector (MyMenuLayer::onHorribleButton));
124+ menu_selector (MyMenuLayer::onHorribleButton)
125+ );
44126 btn->setID (" horribleBtn" );
45127
46128 if (auto menu = typeinfo_cast<CCMenu*>(bottomMenu)) {
@@ -49,6 +131,34 @@ class $modify(MyMenuLayer, MenuLayer) {
49131 };
50132 };
51133
134+ // TESTING
135+
136+ // DELETE LATER
137+
138+ auto ss = CCSprite::createWithSpriteFrameName (" GJLargeLock_001.png" );
139+ ss->setPosition ({ -192 .f , 108 .f });
140+ ss->setZOrder (501 );
141+
142+ addChild (ss);
143+
144+ float yA = as<float >(std::rand ()) / RAND_MAX ; // first y pos %
145+ float yB = as<float >(std::rand ()) / RAND_MAX ; // last y pos %
146+
147+ ss->setPositionY (getScaledContentHeight () * yA);
148+ ss->setRotation (360 .f * (yA * yB));
149+
150+ auto move = CCEaseIn::create (CCMoveTo::create (7 .5f , { getScaledContentWidth () + 192 .f , getScaledContentHeight () * yB }), 1 .f );
151+ auto rotate = CCEaseOut::create (CCRotateBy::create (12 .5f , 45 .f ), 1 .f );
152+
153+ auto action = CCSpawn::createWithTwoActions (move, rotate);
154+ ss->runAction (action);
155+
156+ log::info (" Animated sprite successfully" );
157+
158+ // DELETE LATER
159+
160+ // TESTING
161+
52162 return true ;
53163 };
54164
0 commit comments