From eb07118535555d459c8e50124115471494dbbc19 Mon Sep 17 00:00:00 2001 From: elnexreal <40328573+elnexreal@users.noreply.github.com> Date: Tue, 9 Jul 2024 17:40:55 -0300 Subject: [PATCH] moved vector logic stuff into its own function --- src/main.cpp | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3f01f26..a3b717f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -146,58 +146,54 @@ struct OptionsLayerHook : Modify { } }; -$on_mod(Loaded) { +void populateVector(bool customSongs) { /* if custom songs are enabled search for files in the config dir if not, just use the newgrounds songs */ - if (Mod::get()->getSettingValue("useCustomSongs")) { + if (customSongs) { auto configPath = geode::Mod::get()->getConfigDir(); for (auto file : std::filesystem::directory_iterator(configPath)) { - geode::log::debug("Adding song path: {}", file.path().string()); - songManager.addSong(file.path().string()); + if (file.path().string().ends_with(".mp3")) { + log::debug("Adding custom song: {}", file.path().filename().string()); + songManager.addSong(file.path().string()); + } } } else { auto downloadManager = MusicDownloadManager::sharedState(); + // for every downloaded song push it to the m_songs vector CCArrayExt songs = downloadManager->getDownloadedSongs(); for (auto song : songs) { - songManager.addSong(downloadManager->pathForSong(song->m_songID)); + std::string songPath = downloadManager->pathForSong(song->m_songID); + + if (songPath.ends_with(".mp3")) { + log::debug("Adding NG song: {}", songPath); + songManager.addSong(songPath); + } } } +} + +$on_mod(Loaded) { + populateVector(Mod::get()->getSettingValue("useCustomSongs")); songManager.pickRandomSong(); } $execute { listenForSettingChanges("useCustomSongs", [](bool value) { + // make sure m_songs its empty, we don't want to make a mess here songManager.clearSongs(); - if (value) { - auto configPath = geode::Mod::get()->getConfigDir(); - - for (auto file : std::filesystem::directory_iterator(configPath)) { - if (file.path().string().ends_with(".mp3")) { - log::debug("Adding custom song: {}", file.path().filename().string()); - songManager.addSong(file.path().string()); - } - } - } else { - auto downloadManager = MusicDownloadManager::sharedState(); - - CCArrayExt songs = downloadManager->getDownloadedSongs(); - for (auto song : songs) { - std::string songPath = downloadManager->pathForSong(song->m_songID); - - if (songPath.ends_with(".mp3")) { - log::debug("Adding NG song: {}", songPath); - songManager.addSong(songPath); - } - } - } + /* + for every custom song file, push its path to m_songs + if they're ng songs also push the path bc we're going to use getPathForSong + */ + populateVector(value); - // change the song when you click apply. + // change the song when you click apply, stoi will not like custom names. auto gameManager = GameManager::sharedState(); auto audioEngine = FMODAudioEngine::sharedEngine();