diff --git a/fmt/format.h b/fmt/format.h new file mode 100644 index 0000000..94ec8bb --- /dev/null +++ b/fmt/format.h @@ -0,0 +1 @@ +#error {fmt} where diff --git a/richPresenceUtil.cpp b/richPresenceUtil.cpp index b3c81d1..99f1878 100644 --- a/richPresenceUtil.cpp +++ b/richPresenceUtil.cpp @@ -61,6 +61,15 @@ std::string getTextFromKey(std::string key) return key; } +std::string formatWithLevel(std::string s, GDlevel &level, int currentBest) { + return fmt::format(s, + fmt::arg("name", level.name), + fmt::arg("best", currentBest), + fmt::arg("diff", getTextFromKey(getDifficultyName(level))), + fmt::arg("author", level.author), + fmt::arg("stars", level.stars)); +} + DWORD WINAPI mainThread(LPVOID lpParam) { DRP::InitDiscord(); @@ -92,7 +101,7 @@ DWORD WINAPI mainThread(LPVOID lpParam) largeText = user.name + " [Leaderboard Banned]"; } - int levelLocation, levelID, currentBest; + int levelLocation, currentBest; GDlevel currentLevel; updatePresence = true; @@ -113,14 +122,14 @@ DWORD WINAPI mainThread(LPVOID lpParam) } else { if (!parseGJGameLevel(currentGameLevel, currentLevel)) { details = "Playing a level"; - state = "(" + std::to_string(currentBest) + "%)"; + state = fmt::format("{best}%", fmt::arg("best", currentBest)); smallImage = ""; smallText = ""; } else { - details = "Playing " + currentLevel.name; - state = "By " + currentLevel.author + " (" + std::to_string(currentBest) + "%)"; + details = formatWithLevel("Playing {name}", currentLevel, currentBest); + state = formatWithLevel("by {author} ({best}%)", currentLevel, currentBest); + smallText = formatWithLevel("{stars}* {diff}", currentLevel, currentBest); smallImage = getDifficultyName(currentLevel); - smallText = std::to_string(currentLevel.stars) + "* " + getTextFromKey(getDifficultyName(currentLevel)); } } break; diff --git a/richPresenceUtil.h b/richPresenceUtil.h index 0d3f5f6..e6a76e8 100644 --- a/richPresenceUtil.h +++ b/richPresenceUtil.h @@ -7,6 +7,9 @@ #include #include "DRPWrap.h" #include "gdapi.h" + +#define FMT_HEADER_ONLY +#include "fmt/format.h" #ifndef RICHPRESENCEUTIL_H #define RICHPRESENCEUTIL_H enum class playerState