Skip to content

Commit

Permalink
attempts to fix "default fix"
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Apr 11, 2024
1 parent 5caddb5 commit fc806b6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/events/get_song_info_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

ListenerResult GetSongInfoEventFilter::handle(MiniFunction<Callback> fn, GetSongInfoEvent* event) {
if (event->getObject() == nullptr) {
return ListenerResult::Stop;
return ListenerResult::Propagate;
}

if (event->getObject()->m_songID == m_songID) {
fn(event->getObject());
return ListenerResult::Stop;
return ListenerResult::Propagate;
}
return ListenerResult::Propagate;
}
5 changes: 3 additions & 2 deletions src/hooks/custom_song_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ 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 @@ -146,6 +144,9 @@ class $modify(JBSongWidget, CustomSongWidget) {
NongManager::get()->prepareCorrectDefault(id);
this->template addEventListener<GetSongInfoEventFilter>(
[this, id](SongInfoObject* obj) {
if (!NongManager::get()->isFixingDefault(id)) {
return ListenerResult::Propagate;
}
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);
Expand Down
37 changes: 14 additions & 23 deletions src/managers/nong_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,30 +465,23 @@ ListenerResult NongManager::onSongInfoFetched(GetSongInfoEvent* event) {
}

auto actions = res.value();
for (auto const& action : actions) {
switch (action) {
case SongInfoGetAction::CreateDefault: {
if (obj == nullptr) {
this->createUnknownDefault(id);
} else {
this->createDefaultCallback(obj);
}
break;
}
case SongInfoGetAction::FixDefault: {
if (obj == nullptr) {
break;
}
this->fixDefault(obj);
break;
}
if (actions.contains(SongInfoGetAction::CreateDefault)) {
if (obj == nullptr) {
this->createUnknownDefault(id);
} else {
this->createDefaultCallback(obj);
}
}
if (actions.contains(SongInfoGetAction::FixDefault)) {
if (obj != nullptr) {
this->fixDefault(obj);
}
}
m_getSongInfoActions.erase(id);
return ListenerResult::Propagate;
}

std::optional<std::vector<SongInfoGetAction>> NongManager::getSongIDActions(int songID) {
std::optional<std::unordered_set<SongInfoGetAction>> NongManager::getSongIDActions(int songID) {
if (!m_getSongInfoActions.contains(songID)) {
return std::nullopt;
}
Expand All @@ -507,13 +500,11 @@ void NongManager::addSongIDAction(int songID, SongInfoGetAction action) {
return;
}

for (auto const& existingAction : m_getSongInfoActions[songID]) {
if (action == existingAction) {
return;
}
if (m_getSongInfoActions[songID].contains(action)) {
return;
}

m_getSongInfoActions[songID].push_back(action);
m_getSongInfoActions[songID].insert(action);
}

}
6 changes: 3 additions & 3 deletions src/managers/nong_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <Geode/binding/SongInfoObject.hpp>
#include <Geode/loader/Event.hpp>
#include <optional>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include "../types/song_info.hpp"
Expand All @@ -26,10 +26,10 @@ class NongManager : public CCObject {
inline static NongManager* m_instance = nullptr;
NongState m_state;
std::unordered_map<int, std::function<void(int)>> m_getSongInfoCallbacks;
std::unordered_map<int, std::vector<SongInfoGetAction>> m_getSongInfoActions;
std::unordered_map<int, std::unordered_set<SongInfoGetAction>> m_getSongInfoActions;
EventListener<EventFilter<GetSongInfoEvent>> m_songInfoListener = { this, &NongManager::onSongInfoFetched };

std::optional<std::vector<SongInfoGetAction>> getSongIDActions(int songID);
std::optional<std::unordered_set<SongInfoGetAction>> getSongIDActions(int songID);
void addSongIDAction(int songID, SongInfoGetAction action);
void createDefaultCallback(SongInfoObject* obj);
void setDefaultState();
Expand Down
18 changes: 6 additions & 12 deletions src/ui/nong_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,18 @@ void NongCell::onFixDefault(CCObject* target) {
"No",
"Yes",
[this](FLAlertLayer* alert, bool btn2) {
if (btn2) {
NongManager::get()->markAsInvalidDefault(m_parentPopup->getSongID());

m_parentPopup->updateParentWidget(m_songInfo);
// TODO I swear to god I'll regret this some day
this->retain();
m_parentPopup->retain();
m_parentPopup->m_mainLayer->retain();
if (btn2 && !NongManager::get()->isFixingDefault(m_parentPopup->getSongID())) {
this->template addEventListener<GetSongInfoEventFilter>(
[this](auto song) {
m_parentPopup->refreshList();
if (m_parentPopup) {
m_parentPopup->refreshList();
}
FLAlertLayer::create("Success", "Default song data was refetched successfully!", "Ok")->show();
this->release();
m_parentPopup->release();
m_parentPopup->m_mainLayer->release();
return ListenerResult::Propagate;
}, m_parentPopup->getSongID()
);
NongManager::get()->markAsInvalidDefault(m_parentPopup->getSongID());
NongManager::get()->prepareCorrectDefault(m_parentPopup->getSongID());
}
}
);
Expand Down

0 comments on commit fc806b6

Please sign in to comment.