Skip to content

Commit

Permalink
use format library
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed May 5, 2020
1 parent c79e291 commit b5874b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions fmt/format.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#error {fmt} where
19 changes: 14 additions & 5 deletions richPresenceUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions richPresenceUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <sstream>
#include "DRPWrap.h"
#include "gdapi.h"

#define FMT_HEADER_ONLY
#include "fmt/format.h"
#ifndef RICHPRESENCEUTIL_H
#define RICHPRESENCEUTIL_H
enum class playerState
Expand Down

0 comments on commit b5874b8

Please sign in to comment.