Skip to content

Commit

Permalink
feat: add setting for metadata autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
Fleeym committed Jun 25, 2024
1 parent 0340633 commit 9b88648
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
6 changes: 6 additions & 0 deletions mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
"type": "bool",
"description": "Fixes multi asset levels showing 0.0B size (experimental, might cause lag when downloading assets)",
"default": false
},
"autocomplete-metadata": {
"name": "Autocomplete metadata",
"type": "bool",
"description": "Try to autocomplete song info from metadata when adding. Causes a tiny big of lag after picking a song file.",
"default": true
}
},
"api": {
Expand Down
78 changes: 41 additions & 37 deletions src/ui/nong_add_popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <Geode/cocos/base_nodes/CCNode.h>
#include <Geode/cocos/base_nodes/Layout.hpp>
#include <Geode/loader/Log.hpp>
#include <Geode/loader/Mod.hpp>
#include <Geode/ui/Popup.hpp>
#include <Geode/utils/file.hpp>
#include <Geode/utils/MiniFunction.hpp>
Expand Down Expand Up @@ -37,6 +38,7 @@ std::optional<std::string> parseFromFMODTag(const FMOD_TAG& tag) {
reinterpret_cast<const wchar_t*>(tag.data)
);
} else if (tag.datatype == FMOD_TAGDATATYPE_STRING_UTF16BE) {
// I'm a big endian hater, whachu gonna do?
return std::nullopt;
}
#endif
Expand Down Expand Up @@ -217,48 +219,50 @@ void NongAddPopup::onFileOpen(Task<Result<std::filesystem::path>>::Event* event)
return;
}

auto meta = this->tryParseMetadata(path);
if (meta && (meta->artist.has_value() || meta->name.has_value())) {
auto artistName = m_artistNameInput->getString();
auto songName = m_songNameInput->getString();
if (Mod::get()->getSettingValue<bool>("autocomplete-metadata")) {
auto meta = this->tryParseMetadata(path);
if (meta && (meta->artist.has_value() || meta->name.has_value())) {
auto artistName = m_artistNameInput->getString();
auto songName = m_songNameInput->getString();

if (artistName.size() > 0 || songName.size() > 0) {
// We should ask before replacing stuff
std::stringstream ss;
if (artistName.size() > 0 || songName.size() > 0) {
// We should ask before replacing stuff
std::stringstream ss;

ss << "Found metadata for the imported song: ";
if (meta->name.has_value()) {
ss << fmt::format("Name: \"{}\". ", meta->name.value());
}
if (meta->artist.has_value()) {
ss << fmt::format("Artist: \"{}\". ", meta->artist.value());
}

ss << "Do you want to set those values for the song?";
ss << "Found metadata for the imported song: ";
if (meta->name.has_value()) {
ss << fmt::format("Name: \"{}\". ", meta->name.value());
}
if (meta->artist.has_value()) {
ss << fmt::format("Artist: \"{}\". ", meta->artist.value());
}

createQuickPopup(
"Metadata found",
ss.str(),
"No",
"Yes",
[this, meta](auto, bool btn2) {
if (!btn2) {
return;
}
if (meta->artist.has_value()) {
m_artistNameInput->setString(meta->artist.value());
}
if (meta->name.has_value()) {
m_songNameInput->setString(meta->name.value());
ss << "Do you want to set those values for the song?";

createQuickPopup(
"Metadata found",
ss.str(),
"No",
"Yes",
[this, meta](auto, bool btn2) {
if (!btn2) {
return;
}
if (meta->artist.has_value()) {
m_artistNameInput->setString(meta->artist.value());
}
if (meta->name.has_value()) {
m_songNameInput->setString(meta->name.value());
}
}
);
} else {
if (meta->artist.has_value()) {
m_artistNameInput->setString(meta->artist.value());
}
if (meta->name.has_value()) {
m_songNameInput->setString(meta->name.value());
}
);
} else {
if (meta->artist.has_value()) {
m_artistNameInput->setString(meta->artist.value());
}
if (meta->name.has_value()) {
m_songNameInput->setString(meta->name.value());
}
}
}
Expand Down

0 comments on commit 9b88648

Please sign in to comment.