Skip to content

Commit

Permalink
i think this could fix the crash
Browse files Browse the repository at this point in the history
  • Loading branch information
pundang committed Jul 12, 2024
1 parent 228e89e commit 8bba9fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ void SongManager::clearSongs() {

void SongManager::pickRandomSong() {
if (m_songs.size() >= 1) {
m_isMenuLoop = false;
m_currentSong = m_songs[Utils::randomIndex(m_songs.size())];
} else {
m_isMenuLoop = true;
m_currentSong = "menuLoop.mp3";
}
}

std::string SongManager::getCurrentSong() {
return m_currentSong;
}

bool SongManager::isOriginalMenuLoop() {
return m_isMenuLoop;
}
2 changes: 2 additions & 0 deletions src/SongManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ class SongManager {
void addSong(std::string);
void clearSongs();
void pickRandomSong();
bool isOriginalMenuLoop();
std::string getCurrentSong();

private:
SongManager();
SongManager(const SongManager &) = delete;
std::vector<std::string> m_songs;
std::string m_currentSong;
bool m_isMenuLoop;
};
22 changes: 15 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,29 @@ struct MenuLayerHook : Modify<MenuLayerHook, MenuLayer> {

auto songFileName = std::filesystem::path(songManager.getCurrentSong()).filename();

PlayingCard *card;
std::string notifString;

if (Mod::get()->getSettingValue<bool>("useCustomSongs")) {
card = PlayingCard::create(fmt::format("Now playing: {}", songFileName));
notifString = fmt::format("Now playing: {}", songFileName);
} else {
size_t dotPos = songFileName.string().find_last_of(".");
// in case that the current file selected is the original menuloop, don't gather any info
if (songManager.isOriginalMenuLoop()) {
notifString = fmt::format("Now playing: Original Menu Loop");
} else {
// if its not menuLoop.mp3 then get info
size_t dotPos = songFileName.string().find_last_of(".");

if (dotPos != std::string::npos)
songFileName = songFileName.string().substr(0, dotPos);
if (dotPos != std::string::npos)
songFileName = songFileName.string().substr(0, dotPos);

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

card = PlayingCard::create(fmt::format("Now playing: {} ({})", songInfo->m_songName, songInfo->m_songID));
notifString = fmt::format("Now playing: {} ({})", songInfo->m_songName, songInfo->m_songID);
}
}

auto card = PlayingCard::create(notifString);

card->position.x = screenSize.width / 2.0f;
card->position.y = screenSize.height;

Expand Down

0 comments on commit 8bba9fc

Please sign in to comment.