Skip to content

Commit

Permalink
fix weird daily bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Apr 11, 2024
1 parent 22a7329 commit 5caddb5
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
44 changes: 29 additions & 15 deletions src/hooks/custom_song_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class $modify(JBSongWidget, CustomSongWidget) {
bool unk,
bool isMusicLibrary
) {
log::info("Calling init...");
if (!CustomSongWidget::init(songInfo, songDelegate, showSongSelect, showPlayMusic, showDownload, isRobtopSong, unk, isMusicLibrary)) {
return false;
}
log::info("Init called");
if (isRobtopSong) {
return true;
}
Expand Down Expand Up @@ -123,33 +125,41 @@ class $modify(JBSongWidget, CustomSongWidget) {
NongManager::get()->createUnknownDefault(obj->m_songID);
}
}
std::optional<NongData> result = NongManager::get()->getNongs(obj->m_songID);
int id = obj->m_songID;
std::optional<NongData> result = NongManager::get()->getNongs(id);
if (!result.has_value()) {
NongManager::get()->createDefault(obj->m_songID);
result = NongManager::get()->getNongs(obj->m_songID);
NongManager::get()->createDefault(id);
result = NongManager::get()->getNongs(id);
if (!result.has_value()) {
return;
}
}

NongData nongData = result.value();

SongInfo active = NongManager::get()->getActiveNong(obj->m_songID).value();
if (!nongData.defaultValid && active.path == nongData.defaultPath) {
NongManager::get()->fixDefault(obj);
m_sliderGroove->setVisible(false);
nongData = NongManager::get()->getNongs(obj->m_songID).value();
}
if (!nongData.defaultValid && active.path == nongData.defaultPath) {
NongManager::get()->prepareCorrectDefault(obj->m_songID);
SongInfo active = NongManager::get()->getActiveNong(id).value();
if (
!nongData.defaultValid
&& active.path == nongData.defaultPath
&& !NongManager::get()->isFixingDefault(id)
) {
NongManager::get()->prepareCorrectDefault(id);
this->template addEventListener<GetSongInfoEventFilter>(
[this](SongInfoObject* obj) {
[this, id](SongInfoObject* obj) {
log::info("update song object");
log::info("{}, {}, {}, {}, {}", obj->m_songName, obj->m_artistName, obj->m_songUrl, obj->m_isUnkownSong, obj->m_songID);
NongManager::get()->fixDefault(obj);
m_sliderGroove->setVisible(false);
m_fields->nongs = NongManager::get()->getNongs(id).value();
this->createSongLabels();
return ListenerResult::Propagate;
},
obj->m_songID
id
);
nongData = NongManager::get()->getNongs(obj->m_songID).value();
auto result = NongManager::get()->getNongs(id);
if (result) {
nongData = result.value();
}
}
m_fields->nongs = nongData;
this->createSongLabels();
Expand Down Expand Up @@ -192,7 +202,11 @@ class $modify(JBSongWidget, CustomSongWidget) {

void createSongLabels() {
int songID = m_songInfoObject->m_songID;
auto active = NongManager::get()->getActiveNong(songID).value();
auto res = NongManager::get()->getActiveNong(songID);
if (!res) {
return;
}
SongInfo active = res.value();
if (m_fields->menu != nullptr) {
m_fields->menu->removeFromParent();
}
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/music_download_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class $modify(MusicDownloadManager) {
if (og == nullptr) {
return og;
}
if (NongManager::get()->hasActions(id)) {
return og;
}
auto active = NongManager::get()->getActiveNong(id);
if (active.has_value()) {
auto value = active.value();
Expand Down
23 changes: 18 additions & 5 deletions src/managers/nong_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ std::optional<NongData> NongManager::getNongs(int songID) {
return std::nullopt;
}

auto actions = this->getSongIDActions(songID);
if (actions.has_value()) {
return std::nullopt;
}

return m_state.m_nongs[songID];
}

Expand Down Expand Up @@ -53,6 +48,24 @@ std::optional<SongInfo> NongManager::getActiveNong(int songID) {
return std::nullopt;
}

bool NongManager::hasActions(int songID) {
return m_getSongInfoActions.contains(songID);
}

bool NongManager::isFixingDefault(int songID) {
if (!m_getSongInfoActions.contains(songID)) {
return false;
}

for (auto action : m_getSongInfoActions[songID]) {
if (action == SongInfoGetAction::FixDefault) {
return true;
}
}

return false;
}

std::optional<SongInfo> NongManager::getDefaultNong(int songID) {
auto nongs_res = this->getNongs(songID);
if (!nongs_res.has_value()) {
Expand Down
14 changes: 14 additions & 0 deletions src/managers/nong_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ class NongManager : public CCObject {
*/
void createUnknownDefault(int songID);

/**
* Checks if a song ID has actions associated to it
*
* @param songID the id of the song
*/
bool hasActions(int songID);

/**
* Checks if the default song is being fixed for a song ID
*
* @param songID the id of the song
*/
bool isFixingDefault(int songID);

/**
* Returns the savefile path
*
Expand Down

0 comments on commit 5caddb5

Please sign in to comment.