Skip to content

Commit

Permalink
Merge #56 v1.1.10
Browse files Browse the repository at this point in the history
v1.1.10
  • Loading branch information
B1rtek authored Jul 1, 2024
2 parents d0ec113 + 0935f81 commit bbee2f6
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 14 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v1.1.10
- Switch to GDDL API 2.0

# v1.1.9
- Fixed a very silly oversight (I accidentally removed a null check), I'm sorry for this :(

Expand Down
4 changes: 2 additions & 2 deletions mod.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"geode": "3.0.0",
"version": "v1.1.9",
"geode": "3.1.1",
"version": "v1.1.10",
"gd": {
"android": "2.206",
"win": "2.206"
Expand Down
4 changes: 2 additions & 2 deletions src/GDDLSearchLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,9 +517,9 @@ std::vector<int> GDDLSearchLayer::parseResponse(const std::string& response) {
totalOnlineResults = std::max(totalOnlineResults, total); // so it never grabs 0 if a bad request is made
matjson::Value levelList = responseJson["levels"];
for (auto element: levelList.as_array()) {
const int levelID = element["LevelID"].as_int();
const int levelID = element["ID"].as_int();
if (levelID > 3) { // to avoid official demons
results.push_back(element["LevelID"].as_int());
results.push_back(element["ID"].as_int());
if(!element["Rating"].is_null()) {
const float rating = element["Rating"].as_double();
RatingsManager::updateCacheFromSearch(levelID, rating);
Expand Down
52 changes: 43 additions & 9 deletions src/RatingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ std::optional<GDDLRating> RatingsManager::getRating(const int id) {
}

std::string RatingsManager::getRequestUrl(const int id) {
std::string requestURL = "https://gdladder.com/api/level?levelID=" + std::to_string(id);
std::string requestURL = "https://gdladder.com/api/level/" + std::to_string(id);
return requestURL;
}

Expand All @@ -160,18 +160,52 @@ bool RatingsManager::addRatingFromResponse(const int id, const std::string &resp

void RatingsManager::cacheRatings(const std::string &response) {
// ReSharper disable once CppTooWideScopeInitStatement
try {
matjson::Value ratingsData = matjson::parse(response);
for (auto element: ratingsData.as_array()) {
const int id = element["ID"].as_int();
const float rating = element["Rating"].is_null() ? -1.0f : element["Rating"].as_double();
// try {
// now we need to parse csv
std::stringstream ss;
std::string value, line;
ss << response;
// skip the headers
std::getline(ss, value);
// get the data
while(std::getline(ss, line)) {
line += ',';
int linePos = 0, currentQuoteCount = 0;
std::vector<std::string> values;
value = "";
while (linePos < line.size()) {
if (line[linePos] == '"') {
++currentQuoteCount;
value.push_back(line[linePos]);
} else if (line[linePos] == ',' && currentQuoteCount % 2 == 0) {
values.push_back(value);
value = "";
currentQuoteCount = 0;
} else {
value.push_back(line[linePos]);
}
++linePos;
}
// values are in the vector now, we're only interested in the ID and the Rating
const int id = std::stoi(values[4].substr(1, values[4].size() - 2));
std::string strRating = values[5].substr(1, values[5].size() - 2);
if (strRating.empty()) strRating = "-1.0";
const float rating = std::stof(strRating);
const int roundedRating = static_cast<int>(round(rating));
ratingsCache[id] = roundedRating;
}
// old code in case /theList comes back
// matjson::Value ratingsData = matjson::parse(response);
// for (auto element: ratingsData.as_array()) {
// const int id = element["ID"].as_int();
// const float rating = element["Rating"].is_null() ? -1.0f : element["Rating"].as_double();
// const int roundedRating = static_cast<int>(round(rating));
// ratingsCache[id] = roundedRating;
// }
cacheList(false);
} catch (std::runtime_error &error) {
// just do nothing, the user will be notified that stuff happened
}
// } catch (std::runtime_error &error) {
// // just do nothing, the user will be notified that stuff happened
// }
}

std::map<int, int> RatingsManager::getTierStats() {
Expand Down
6 changes: 5 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ class $modify(MenuLayer) {
}
});
auto req = web::WebRequest();
m_fields->cacheEventListener.setFilter(req.get("https://gdladder.com/api/theList"));
// if you're reading this because you treat this as an example of how to use the gddl api
// cache
// for the love of god
// please
m_fields->cacheEventListener.setFilter(req.get("https://docs.google.com/spreadsheets/d/1qKlWKpDkOpU1ZF6V6xGfutDY2NvcA8MNPnsv6GBkKPQ/gviz/tq?tqx=out:csv&sheet=GDDL"));
}
return true;
}
Expand Down

0 comments on commit bbee2f6

Please sign in to comment.