Skip to content

Commit

Permalink
v1.4.1?
Browse files Browse the repository at this point in the history
  • Loading branch information
RayDeeUx committed Aug 24, 2024
1 parent 07795f5 commit 893d1c3
Show file tree
Hide file tree
Showing 15 changed files with 581 additions and 34 deletions.
504 changes: 504 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ This is where she makes a mod.

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

Read [about.md](./about.md) to learn more.
Read [about.md](./about.md) to learn more.

This [Geode mod](https://geode-sdk.org) is licensed under LGPLv2.
4 changes: 3 additions & 1 deletion about.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ If you want to add your own songs to the mod you should go to the settings tab,

# Discord servers
- [Join elnexreal's Discord server](https://discord.gg/vfFazvmKKb).
- [Join RayDeeUx's Discord server](https://discord.gg/WqZBYdBWZW) to report issues with using the mod, or [open a GitHub issue](https://github.com/elnexreal/menuloop_randomizer/issues/new).
- [Join RayDeeUx's Discord server](https://discord.gg/WqZBYdBWZW) to report issues with using the mod, or [open a GitHub issue](https://github.com/elnexreal/menuloop_randomizer/issues/new).

This [Geode mod](https://geode-sdk.org) is licensed under LGPLv2.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v1.4.1
- Attempted to fix a weird `stoi` crash. Not sure why it happens, but it did for the one person who reported it, and they didn't really provide further context beyond a crashlog file reading `C++ Exception: class std::out_of_range("stoi argument out of range")`.
- License the mod under LGPLv2.
# 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. The mod itself doesn't do anything to it beyond creating the child folder.
Expand Down
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mac": "2.206",
"android": "2.206"
},
"version": "v1.4.0",
"version": "v1.4.1",
"id": "elnexreal.menuloop_randomizer",
"name": "Menu Loop Randomizer",
"developers": ["RayDeeUx", "elnexreal"],
Expand Down
3 changes: 3 additions & 0 deletions src/EditorPauseLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "SongManager.hpp"
#include "Utils.hpp"
#include <Geode/modify/EditorPauseLayer.hpp>
#include <Geode/binding/FLAlertLayer.hpp>
#include <Geode/binding/TextArea.hpp>
#include <Geode/utils/Cocos.hpp>

using namespace geode::prelude;

Expand Down
58 changes: 36 additions & 22 deletions src/MenuLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
#include "Utils.hpp"
#include "ui/PlayingCard.hpp"
#include <Geode/modify/MenuLayer.hpp>
#include <Geode/binding/MusicDownloadManager.hpp>
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
#include <Geode/binding/SongInfoObject.hpp>
#include <Geode/ui/BasedButtonSprite.hpp>
#include <filesystem>

using namespace geode::prelude;

Expand Down Expand Up @@ -45,31 +50,40 @@ class $modify(MenuLoopMLHook, MenuLayer) {
size_t dotPos = songFileName.string().find_last_of('.');

if (dotPos == std::string::npos) {
log::error("{} was not a valid file name..? [NG/Music Library]", songFileName.string());
notifString = notifString.append("Unknown");
} else {
songFileName = songFileName.string().substr(0, dotPos);

auto songInfo = MusicDownloadManager::sharedState()->getSongInfoObject(Utils::stoi(songFileName.string()));

// sometimes songInfo is nullptr, so improvise
if (songInfo) {
// default: "Song Name, Artist, Song ID"
// fmt::format("{} by {} ({})", songInfo->m_songName, songInfo->m_artistName, songInfo->m_songID);
std::string resultString = "";
auto formatSetting = Mod::get()->getSettingValue<std::string>("songFormatNGML");
if (formatSetting == "Song Name, Artist, Song ID") {
resultString = fmt::format("{} by {} ({})", songInfo->m_songName, songInfo->m_artistName, songInfo->m_songID);
} else if (formatSetting == "Song Name + Artist") {
resultString = fmt::format("{} by {}", songInfo->m_songName, songInfo->m_artistName);
} else if (formatSetting == "Song Name + Song ID") {
resultString = fmt::format("{} ({})", songInfo->m_songName, songInfo->m_songID);
} else {
resultString = fmt::format("{}", songInfo->m_songName);
}
notifString = notifString.append(resultString);
return;
}
std::string songFileNameAsAtring = songFileName.string().substr(0, dotPos);

Result<int> songFileNameAsID = geode::utils::numFromString<int>(songFileNameAsAtring);

if (songFileNameAsID.isErr()) {
log::error("{} had an invalid Song ID! [NG/Music Library]", songFileNameAsAtring);
notifString = notifString.append("Unknown (Invalid Song ID)");
return;
}

auto songInfo = MusicDownloadManager::sharedState()->getSongInfoObject(songFileNameAsID.unwrap());

// sometimes songInfo is nullptr, so improvise
if (songInfo) {
// default: "Song Name, Artist, Song ID"
// fmt::format("{} by {} ({})", songInfo->m_songName, songInfo->m_artistName, songInfo->m_songID);
std::string resultString = "";
auto formatSetting = Mod::get()->getSettingValue<std::string>("songFormatNGML");
if (formatSetting == "Song Name, Artist, Song ID") {
resultString = fmt::format("{} by {} ({})", songInfo->m_songName, songInfo->m_artistName, songInfo->m_songID);
} else if (formatSetting == "Song Name + Artist") {
resultString = fmt::format("{} by {}", songInfo->m_songName, songInfo->m_artistName);
} else if (formatSetting == "Song Name + Song ID") {
resultString = fmt::format("{} ({})", songInfo->m_songName, songInfo->m_songID);
} else {
notifString = notifString.append(songFileName.string());
resultString = fmt::format("{}", songInfo->m_songName);
}
notifString = notifString.append(resultString);
} else {
notifString = notifString.append(songFileName.string());
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/OptionsLayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <Geode/modify/OptionsLayer.hpp>
#include <Geode/binding/CCMenuItemSpriteExtra.hpp>
#include <Geode/ui/BasedButtonSprite.hpp>

using namespace geode::prelude;

Expand Down
1 change: 1 addition & 0 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "SongManager.hpp"
#include "Utils.hpp"
#include <Geode/loader/Log.hpp>

SongManager::SongManager() {}

Expand Down
4 changes: 3 additions & 1 deletion src/SongManager.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#include <string>
#include <vector>

class SongManager {
public:
Expand All @@ -20,4 +22,4 @@ class SongManager {
std::vector<std::string> m_songs;
std::string m_currentSong;
bool m_isMenuLoop;
};
};
14 changes: 10 additions & 4 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include "SongManager.hpp"
#include "Utils.hpp"
#include <random>
#include <Geode/binding/FMODAudioEngine.hpp>
#include <Geode/binding/GameManager.hpp>
#include <Geode/binding/MenuLayer.hpp>
#include <Geode/loader/Mod.hpp>

int Utils::randomIndex(int size) {
// select a random item from the vector and return the path
Expand All @@ -11,13 +16,16 @@ int Utils::randomIndex(int size) {
return randomIndex;
}

int Utils::stoi(std::string text) {
uint64_t Utils::stoi(std::string text) {
// create a new string containing only digits
std::string digits;
std::copy_if(text.begin(), text.end(), std::back_inserter(digits), ::isdigit);

uint64_t result = std::stoi(digits);
if (!result) return 0;

// convert the digits string to an integer (or 0 if empty)
return digits.empty() ? 0 : std::stoi(digits);
return digits.empty() ? 0 : result;
}

bool Utils::isSupportedExtension(std::string path) {
Expand Down Expand Up @@ -48,8 +56,6 @@ void Utils::removeCard() {
card->removeMeAndCleanup();
}

#include "SongManager.hpp"

void Utils::setNewSong() {
FMODAudioEngine::sharedEngine()->m_backgroundMusicChannel->stop();
SongManager::get().pickRandomSong();
Expand Down
6 changes: 4 additions & 2 deletions src/Utils.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#pragma once
#include <string>
#include <Geode/cocos/base_nodes/CCNode.h>

class Utils {
public:
static int randomIndex(int size);
static int stoi(std::string);
static uint64_t stoi(std::string);
static bool isSupportedExtension(std::string);
static bool getBool(std::string);
static void removeCard();
static cocos2d::CCNode* findCard();
static cocos2d::CCNode* findCardRemotely();
static void setNewSong();
};
};
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#include "SongManager.hpp"
#include "Utils.hpp"
#include <Geode/loader/SettingEvent.hpp>
#include <Geode/binding/SongInfoObject.hpp>
#include <Geode/binding/MusicDownloadManager.hpp>
#include <Geode/utils/Cocos.hpp>

using namespace geode::prelude;

Expand Down Expand Up @@ -39,7 +42,7 @@ void populateVector(bool customSongs) {
- only reason it didn't work was because file support was limited to `.mp3`.
--raydeeux
*/
CCArrayExt<SongInfoObject *> songs = downloadManager->getDownloadedSongs();
CCArrayExt<SongInfoObject*> songs = downloadManager->getDownloadedSongs();
for (auto song : songs) {
if (!song) continue;

Expand Down
2 changes: 2 additions & 0 deletions src/ui/PlayingCard.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "PlayingCard.hpp"
#include "../Utils.hpp"
#include <regex>
#include <GUI/CCControlExtension/CCScale9Sprite.h>
#include <Geode/loader/Mod.hpp>

using namespace geode::prelude;

Expand Down
3 changes: 2 additions & 1 deletion src/ui/PlayingCard.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <Geode/cocos/base_nodes/CCNode.h>

class PlayingCard : public cocos2d::CCNode {
protected:
Expand All @@ -8,4 +9,4 @@ class PlayingCard : public cocos2d::CCNode {
static PlayingCard *create(std::string);
cocos2d::CCPoint position;
const cocos2d::CCPoint cardSize = {380.0f, 55.0f};
};
};

0 comments on commit 893d1c3

Please sign in to comment.