diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-02 18:01:31 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-02 18:01:31 -0500 |
| commit | bbe334b6c9249fea57dee53a0804693dab46f03c (patch) | |
| tree | 292bd467f2f3bdee4d85106ec8ba08757705c05b /database.cpp | |
| parent | c1cc06fa5b3ae49b7cdadf0af439f5858d8483eb (diff) | |
| download | lunatic-bbe334b6c9249fea57dee53a0804693dab46f03c.tar.gz lunatic-bbe334b6c9249fea57dee53a0804693dab46f03c.tar.bz2 lunatic-bbe334b6c9249fea57dee53a0804693dab46f03c.zip | |
Added overlay shadow, achievement title wrapping, and date
The canonical title font is Roboto Bold and the date font is Roboto Medium.
Diffstat (limited to 'database.cpp')
| -rw-r--r-- | database.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
| diff --git a/database.cpp b/database.cpp index 2885d1f..953c217 100644 --- a/database.cpp +++ b/database.cpp | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | #include "database.h" | 1 | #include "database.h" |
| 2 | #include <sqlite3.h> | 2 | #include <sqlite3.h> |
| 3 | #include <stdexcept> | 3 | #include <stdexcept> |
| 4 | #include <sstream> | ||
| 5 | #include <iomanip> | ||
| 4 | 6 | ||
| 5 | database::database(std::string path) | 7 | database::database(std::string path) |
| 6 | { | 8 | { |
| @@ -120,3 +122,55 @@ std::string database::getRandomImageForGame(int gameId) const | |||
| 120 | 122 | ||
| 121 | return result; | 123 | return result; |
| 122 | } | 124 | } |
| 125 | |||
| 126 | did database::getRandomDidForAchievement(int achievementId) const | ||
| 127 | { | ||
| 128 | std::string queryString = "SELECT profile_id, DATETIME(achieved_at) FROM dids WHERE achievement_id = ? ORDER BY RANDOM() LIMIT 1"; | ||
| 129 | |||
| 130 | sqlite3_stmt* ppstmt; | ||
| 131 | if (sqlite3_prepare_v2( | ||
| 132 | ppdb_, | ||
| 133 | queryString.c_str(), | ||
| 134 | queryString.length(), | ||
| 135 | &ppstmt, | ||
| 136 | NULL) != SQLITE_OK) | ||
| 137 | { | ||
| 138 | std::string errorMsg = sqlite3_errmsg(ppdb_); | ||
| 139 | sqlite3_finalize(ppstmt); | ||
| 140 | |||
| 141 | throw std::logic_error(errorMsg); | ||
| 142 | } | ||
| 143 | |||
| 144 | if (sqlite3_bind_int(ppstmt, 1, achievementId) != SQLITE_OK) | ||
| 145 | { | ||
| 146 | std::string errorMsg = sqlite3_errmsg(ppdb_); | ||
| 147 | sqlite3_finalize(ppstmt); | ||
| 148 | |||
| 149 | throw std::logic_error(errorMsg); | ||
| 150 | } | ||
| 151 | |||
| 152 | if (sqlite3_step(ppstmt) != SQLITE_ROW) | ||
| 153 | { | ||
| 154 | std::string errorMsg = sqlite3_errmsg(ppdb_); | ||
| 155 | sqlite3_finalize(ppstmt); | ||
| 156 | |||
| 157 | throw std::logic_error(errorMsg); | ||
| 158 | } | ||
| 159 | |||
| 160 | did result; | ||
| 161 | result.profileId = sqlite3_column_int(ppstmt, 0); | ||
| 162 | |||
| 163 | std::tm achievedAt = {}; | ||
| 164 | |||
| 165 | std::stringstream dateParser; | ||
| 166 | dateParser << reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1)); | ||
| 167 | dateParser >> std::get_time(&achievedAt, "%Y-%m-%d %H:%M:%S"); | ||
| 168 | |||
| 169 | std::stringstream dateFormatter; | ||
| 170 | dateFormatter << std::put_time(&achievedAt, "%m/%d/%Y"); | ||
| 171 | result.date = dateFormatter.str(); | ||
| 172 | |||
| 173 | sqlite3_finalize(ppstmt); | ||
| 174 | |||
| 175 | return result; | ||
| 176 | } | ||
