From 737e0da2fba889f3708ae843f75387dda0518cae Mon Sep 17 00:00:00 2001 From: elnexreal <40328573+elnexreal@users.noreply.github.com> Date: Sun, 7 Jul 2024 03:39:44 -0300 Subject: [PATCH] stuff, i don't know what the hell i made, please fix yourself --- about.md | 1 - changelog.md | 2 +- mod.json | 10 ++++++++-- src/Utils.cpp | 12 ++++++++++++ src/Utils.hpp | 6 ++++++ src/main.cpp | 46 ++++++++++++++++++++++++++-------------------- 6 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 src/Utils.cpp create mode 100644 src/Utils.hpp diff --git a/about.md b/about.md index 5bcaaf7..3b81d61 100644 --- a/about.md +++ b/about.md @@ -6,7 +6,6 @@ This mod allows you to change the menu song every time you open the game, pickin # Notes -- The song changes every time you restart the game, so you will not get another song every time you go back to the menu. - In the future i'll add a setting to toggle between using NG songs or your own songs. # Thanks to! diff --git a/changelog.md b/changelog.md index c05d3c8..f1ce60d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,7 +1,7 @@ # v1.1.0 - Updated Geode target version to `v3.1.1` -- Fixed crash when installing the mod (missing textures crash) +- 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. diff --git a/mod.json b/mod.json index d9efc8d..24ae88f 100644 --- a/mod.json +++ b/mod.json @@ -1,5 +1,5 @@ { - "geode": "3.1.1", + "geode": "3.2.0", "gd": { "win": "2.206", "android": "2.206" @@ -8,7 +8,7 @@ "id": "elnexreal.menuloop_randomizer", "name": "Menu Loop Randomizer", "developer": "elnexreal", - "description": "Randomize your menu loop when opening the game.", + "description": "Menu Loop randomizer for GD.", "tags": [ "music", "interface", @@ -25,6 +25,12 @@ "default": true, "description": "Shows a notification with the name of the currently playing song.", "name": "Show notification" + }, + "randomizeWhenExiting": { + "type": "bool", + "default": true, + "description": "Randomize the song when you exit a level (for example when exiting the editor)", + "name": "Randomize on level exit" } }, "resources": { diff --git a/src/Utils.cpp b/src/Utils.cpp new file mode 100644 index 0000000..302ebcf --- /dev/null +++ b/src/Utils.cpp @@ -0,0 +1,12 @@ +#include "Utils.hpp" +#include + +int Utils::randomIndex(int size) { + // select a random item from the vector and return the path + std::random_device rd; + std::mt19937 gen(rd()); + std::uniform_int_distribution<> dist(0, size - 1); + int randomIndex = dist(gen); + + return randomIndex; +} \ No newline at end of file diff --git a/src/Utils.hpp b/src/Utils.hpp new file mode 100644 index 0000000..80fa4fe --- /dev/null +++ b/src/Utils.hpp @@ -0,0 +1,6 @@ +#pragma once + +class Utils { + public: + static int randomIndex(int size); +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index ea677ef..5a326d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,16 +1,17 @@ #include "PlayingCard.hpp" #include "Song.hpp" +#include "Utils.hpp" #include #include #include -#include +#include #include using namespace geode::prelude; // global variables std::vector songs; -Song *selectedSong; +Song selectedSong; $on_mod(Loaded) { // get the path for the songs @@ -29,17 +30,22 @@ Song *selectedSong; } } - // select a random item from the vector and return the path - std::random_device rd; - std::mt19937 gen(rd()); - std::uniform_int_distribution<> dist(0, songs.size() - 1); - int randomIndex = dist(gen); - selectedSong = std::move(&songs[randomIndex]); + selectedSong = std::move(songs[Utils::randomIndex(songs.size())]); } struct GameManagerHook : Modify { gd::string getMenuMusicFile() { - return selectedSong->path; + return selectedSong.path; + } +}; + +struct PauseLayerHook : Modify { + void onQuit(CCObject *sender) { + if (Mod::get()->getSettingValue("randomizeWhenExiting")) { + selectedSong = std::move(songs[Utils::randomIndex(songs.size())]); + } + + PauseLayer::onQuit(sender); } }; @@ -54,13 +60,13 @@ struct MenuLayerHook : Modify { auto cardSettingValue = Mod::get()->getSettingValue("nowPlayingCard"); if (cardSettingValue) { - if (auto songObject = downloadManager->getSongInfoObject(stoi(selectedSong->id))) { - selectedSong->name = songObject->m_songName; + if (auto songObject = downloadManager->getSongInfoObject(stoi(selectedSong.id))) { + selectedSong.name = songObject->m_songName; } else { - selectedSong->name = "Unknown"; + selectedSong.name = "Unknown"; } - auto card = PlayingCard::create(selectedSong->name, selectedSong->id); + auto card = PlayingCard::create(selectedSong.name, selectedSong.id); card->position.x = screenSize.width / 2.0f; card->position.y = screenSize.height; @@ -71,13 +77,13 @@ struct MenuLayerHook : Modify { card->setPosition(defaultPos); this->addChild(card); - // auto sequence = CCSequence::create( - // CCEaseInOut::create(CCMoveTo::create(1.5f, {posx, posy - 25.0f}), 2.0f), - // CCDelayTime::create(0.5f), - // CCEaseInOut::create(CCMoveTo::create(1.5f, {posx, posy}), 2.0f), - // nullptr - // ); - // card->runAction(sequence); + auto sequence = CCSequence::create( + CCEaseInOut::create(CCMoveTo::create(1.5f, {posx, posy - 25.0f}), 2.0f), + CCDelayTime::create(0.5f), + CCEaseInOut::create(CCMoveTo::create(1.5f, {posx, posy}), 2.0f), + nullptr + ); + card->runAction(sequence); } return true;