Skip to content

Commit

Permalink
mass refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Erymanthus[#5074] | (u/)RayDeeUx <[email protected]>
  • Loading branch information
RayDeeUx committed Aug 14, 2024
1 parent 8a186b5 commit 16cf8c2
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 311 deletions.
20 changes: 2 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
<h2 align="center">This mod is not being maintained by [RayDeeUx](https://github.com/RayDeeUx).</h2>
# This mod is not being maintained by [RayDeeUx](https://github.com/RayDeeUx).

# MenuLoopRandomizer
This is where she makes a mod.

<img src="logo.png" width="150" alt="the mod's logo" />

*Update logo.png to change your mod's icon (please)*

## Getting started
We recommend heading over to [the getting started section on our docs](https://docs.geode-sdk.org/getting-started/) for useful info on what to do next.

## Build instructions
For more info, see [our docs](https://docs.geode-sdk.org/getting-started/create-mod#build)
```sh
# Assuming you have the CLI set up already
geode build
```

# Resources
* [Geode SDK Documentation](https://docs.geode-sdk.org/)
* [Geode SDK Source Code](https://github.com/geode-sdk/geode/)
* [Bindings](https://github.com/geode-sdk/bindings/)
* [Dev Tools](https://github.com/geode-sdk/DevTools)
Read [about.md](./about.md) to learn more.
28 changes: 4 additions & 24 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# v1.4.0
- Added setting to choose font for "Now Playing" notifications
- Added an extra child folder in the mod's config directory for enabling/disabling menuloops easily
# v1.3.0

- Added macOS support (thx [ninxout](https://github.com/ninXout), [raydeeux](https://github.com/RayDeeUx), and [hiimjustin000](https://github.com/hiimjustin000))
- Added support for `.wav`, `.ogg`/`.oga`, and `.flac` files for custom songs
- Included artist name for all "Now Playing" notifications
Expand All @@ -9,17 +11,11 @@
- Add better slider control for adjusting notification duration
- Added Node IDs to nodes added by this mod
- Squash a few bugs, optimize a few things, minimize likelihood of potential crashes

# v1.2.2

- Added an option to enable the shuffle button (thx [reinmar](https://github.com/Reinmmar))

# v1.2.1

- Fixed crash caused by Newgrounds manager trying to gather info of default menuLoop.mp3

# v1.2.0

- Added `Randomize on editor exit` setting.
- Added `Notification time` setting.
- Added `Use custom songs path` setting.
Expand All @@ -33,45 +29,29 @@
- Fixed crash caused by switching the songs location.
- Modified `PlayingCard` to fit the new system.
- Now the song randomizes every time you change `Use custom songs path`

# v1.1.0

- Fixed crash when opening the game (missing textures crash)
- Fixed random song picker being on a loop for every song downloaded.
- Moved song class to its own file.
- The mod should now check for the songs path when loaded, not when executed.
- Added setting to randomize song on level exit.
- Fixed Android crash caused by not able to access the memory (f*** pointers)
- Added `Utils.hpp`

# v1.1.0-alpha.5

- Updated Geode target version to `v3.0.0-beta.1`

# v1.1.0-alpha.4

- Updated notification card & position.
- Added the property `name` to the `Song` class.

# v1.1.0-alpha.3

- Added a notification animation for the card.
- The position is now added in `MainLayer` instead of the layer itself.

# v1.1.0-alpha.2

- Fixed crash on startup caused by a missing dependency.

# v1.1.0-alpha.1

- Added a card showing which song is playing (you can disable it in settings)
- Changed a little bit how songs are stored in the vector.
- Removed MacOS support (sorry, i don't wanna deal with MacOS bindings.)

### Notes

- This version is for `Geode v3.0.0-alpha.2` only.

# v1.0.0

- Initial release
- Initial release
65 changes: 42 additions & 23 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,43 @@
"mac": "2.206",
"android": "2.206"
},
"version": "v1.3.0",
"version": "v1.4.0",
"id": "elnexreal.menuloop_randomizer",
"name": "Menu Loop Randomizer",
"developer": "elnexreal",
"developers": ["elnexreal", "RayDeeUx"],
"description": "Menu Loop randomizer for GD.",
"tags": [
"music",
"interface",
"enhancement"
],
"tags": ["music", "interface", "enhancement"],
"links": {
"community": "https://discord.gg/vfFazvmKKb",
"source": "https://github.com/elnexreal/menuloop_randomizer",
"homepage": "https://github.com/elnexreal"
},
"settings": {
"enableShuffleButton": {
"name": "Shuffle Button",
"description": "Enables the <cj>shuffle button</c> in the main menu.",
"type": "bool",
"default": true,
"description": "Enables the <cj>shuffle button</c> in the main menu",
"name": "Shuffle Button"
"default": true
},
"enableNotification": {
"type": "bool",
"default": true,
"name": "Show Notification",
"description": "Shows a notification with the name of the currently playing song.",
"name": "Show Notification"
"type": "bool",
"default": true
},
"removeSuffix": {
"name": "Hide File Extension",
"description": "Hides the file extension of the song being played.\n<cy>Only applies when using custom songs as the menu loop.</c>",
"type": "bool",
"default": true
},
"notificationTime": {
"name": "Notification Time",
"type": "float",
"default": 0.5,
"min": 0.1,
"max": 5,
"description": "Adjust the time that the notification is on screen.",
"name": "Notification Time",
"control": {
"input": true,
"slider": true,
Expand All @@ -50,23 +52,40 @@
"slider-step": 0.1
}
},
"notificationFont": {
"name": "Notification Font",
"description": "Choose the font the notification will use. Default is 17 for legacy purposes.\n\n<cj>0 for Pusab, -1 for Golden Pusab, and -2 for the font you see when viewing level comments.</c>\n<cy>To use font numbers greater than 0: refer to the level editor for the font each number corresponds to, subtract that number by 1, and then put it here.</c>",
"type": "int",
"default": 17,
"min": -2,
"max": 59,
"control": {
"input": true,
"slider": true,
"arrows": true,
"big-arrows": true,
"arrow-step": 1,
"big-arrow-step": 5,
"slider-step": 1
}
},
"randomizeWhenExitingLevel": {
"type": "bool",
"default": true,
"name": "Randomize on Level Exit",
"description": "Randomize the song when you exit a level.",
"name": "Randomize on Level Exit"
"type": "bool",
"default": true
},
"randomizeWhenExitingEditor": {
"type": "bool",
"default": true,
"name": "Randomize on Editor Exit",
"description": "Randomize the song when you exit the editor.",
"name": "Randomize on Editor Exit"
"type": "bool",
"default": true
},
"useCustomSongs": {
"type": "bool",
"default": false,
"name": "Use Custom Songs Instead",
"description": "Use your own songs instead of those you have downloaded from Newgrounds or RobTop's Music Library.\n\n<cy>Find instructions in the mod info popup.</c>",
"name": "Use Custom Songs Instead"
"type": "bool",
"default": false
}
},
"resources": {
Expand Down
83 changes: 83 additions & 0 deletions src/EditorPauseLayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "SongManager.hpp"
#include "Utils.hpp"
#include <Geode/modify/EditorPauseLayer.hpp>

using namespace geode::prelude;

class $modify(MenuLoopEPLHook, EditorPauseLayer) {
struct Fields {
SongManager &songManager = SongManager::get();
};
#ifndef __APPLE__
void onExitEditor(CCObject *sender) {
if (Utils::getBool("randomizeWhenExitingEditor"))
m_fields->songManager.pickRandomSong();

EditorPauseLayer::onExitEditor(sender);
}
#else
/*
this section is for macOS (both intel and ARM). remarks:
- don't hook onSaveAndPlay; that goes to playlayer
- don't hook onSave or the FLAlertLayer from it; that does not exit the editor
- can't hook onExitEditor for macOS, due to aggressive inlining from robtop/appleclang
(yes, nin. i know the address exists; justin found those addresses for me.
but i keep getting the same song five times in a row if i hook onExitEditor
for macos, and i don't think any of us have the same RNG seed as Dream.)
[for the record, i had 29 possible audio files total while doing this.
1/29 = 0.0344827586207. (1/29)^5 = 4.87539727785E-8 = 1/20511149.
let that sink in for a moment.]
-- raydeeux
*/
void onSaveAndExit(CCObject *sender) {
if (Utils::getBool("randomizeWhenExitingEditor"))
m_fields->songManager.pickRandomSong();

EditorPauseLayer::onSaveAndExit(sender);
}
void FLAlert_Clicked(FLAlertLayer* p0, bool btnTwo) {
bool isQualifedAlert = false;
// determine if the FLAlertLayer being clicked on is the one from onExitNoSave
/*
hooking FLAlertLayer::init() and then storing its desc param is also an option,
but i'm not sure what this mod's stance is with global variables.
consider this overkill, but it gets the job done.
i wanted to use getChildOfType to reduce the line count but ran into one of those
C-Tidy/Clang red squiggly lines about typeinfo_cast or whatever and got worried,
so all you get is this.
yep, nested forloops and typeinfo_cast calls for days.
if anyone has a shorter solution that still hooks this function, go ahead.
for reference, unformatted FLAlertLayer main text is:
R"(Exit without saving? All unsaved changes will be lost!)"
-- raydeeux
*/
auto tArea = p0->m_mainLayer->getChildByIDRecursive("content-text-area");
if (auto textArea = typeinfo_cast<TextArea*>(tArea)) {
for (auto node : CCArrayExt<CCNode*>(textArea->getChildren())) {
if (typeinfo_cast<MultilineBitmapFont*>(node)) {
for (auto nodeTwo : CCArrayExt<CCNode*>(node->getChildren())) {
if (auto label = typeinfo_cast<CCLabelBMFont*>(nodeTwo)) {
auto labelString = std::string(label->getString());
isQualifedAlert = labelString == R"(Exit without saving? All unsaved changes will be lost!)";
log::debug("labelString: {}", labelString); // log::debug calls since that's kinda this mod's thing
break;
}
}
}
}
}

log::debug("isQualifedAlert: {}", isQualifedAlert); // log::debug calls since that's kinda this mod's thing
log::debug("btnTwo: {}", btnTwo); // log::debug calls since that's kinda this mod's thing

if (Utils::getBool("randomizeWhenExitingEditor") && isQualifedAlert && btnTwo)
m_fields->songManager.pickRandomSong();

EditorPauseLayer::FLAlert_Clicked(p0, btnTwo);
}
#endif
};
13 changes: 13 additions & 0 deletions src/GameManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "SongManager.hpp"
#include <Geode/modify/GameManager.hpp>

using namespace geode::prelude;

class $modify(MenuLoopGMHook, GameManager) {
struct Fields {
SongManager &songManager = SongManager::get();
};
gd::string getMenuMusicFile() {
return m_fields->songManager.getCurrentSong();
}
};
Loading

0 comments on commit 16cf8c2

Please sign in to comment.