From 641ba671c46910c2ce908906e447b20a9fb4c32b Mon Sep 17 00:00:00 2001 From: b1rtek <53182944+B1rtek@users.noreply.github.com> Date: Fri, 28 Jun 2024 23:34:03 +0200 Subject: [PATCH 1/6] New API update --- src/RatingsManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RatingsManager.cpp b/src/RatingsManager.cpp index 4078f63..403515a 100644 --- a/src/RatingsManager.cpp +++ b/src/RatingsManager.cpp @@ -143,7 +143,7 @@ std::optional 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; } From 7a7fa924c573a33d43e4ae5e7b3940bef2ba9130 Mon Sep 17 00:00:00 2001 From: b1rtek <53182944+B1rtek@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:01:34 +0200 Subject: [PATCH 2/6] Geode version bump --- mod.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.json b/mod.json index d92d209..bee23cc 100644 --- a/mod.json +++ b/mod.json @@ -1,5 +1,5 @@ { - "geode": "3.0.0", + "geode": "3.1.1", "version": "v1.1.9", "gd": { "android": "2.206", From cf61d66fc9e734c18200edd9fcdfadf90be8de5f Mon Sep 17 00:00:00 2001 From: b1rtek <53182944+B1rtek@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:02:18 +0200 Subject: [PATCH 3/6] Update changelog.md --- changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.md b/changelog.md index 2122477..e611d91 100644 --- a/changelog.md +++ b/changelog.md @@ -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 :( From 2549810ba044f16d5f8ed582b08b1bc58fc2e2b5 Mon Sep 17 00:00:00 2001 From: b1rtek <53182944+B1rtek@users.noreply.github.com> Date: Sat, 29 Jun 2024 00:02:29 +0200 Subject: [PATCH 4/6] Version bump --- mod.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod.json b/mod.json index bee23cc..39769c8 100644 --- a/mod.json +++ b/mod.json @@ -1,6 +1,6 @@ { "geode": "3.1.1", - "version": "v1.1.9", + "version": "v1.1.10", "gd": { "android": "2.206", "win": "2.206" From bee334a2e9304d02dd70995efc3cf935732d30ba Mon Sep 17 00:00:00 2001 From: b1rtek <53182944+B1rtek@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:27:59 +0200 Subject: [PATCH 5/6] Switch from theList to Google Sheets API --- src/RatingsManager.cpp | 50 +++++++++++++++++++++++++++++++++++------- src/main.cpp | 6 ++++- 2 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/RatingsManager.cpp b/src/RatingsManager.cpp index 403515a..f12f189 100644 --- a/src/RatingsManager.cpp +++ b/src/RatingsManager.cpp @@ -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 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(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(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 RatingsManager::getTierStats() { diff --git a/src/main.cpp b/src/main.cpp index d83864d..227149b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; } From 0935f81d157b152b307505e7d8e4e2530d7280da Mon Sep 17 00:00:00 2001 From: b1rtek <53182944+B1rtek@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:48:22 +0200 Subject: [PATCH 6/6] Fix a wrong key being accessed while parsing search response JSON --- src/GDDLSearchLayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GDDLSearchLayer.cpp b/src/GDDLSearchLayer.cpp index 7c70837..9d7b7e8 100644 --- a/src/GDDLSearchLayer.cpp +++ b/src/GDDLSearchLayer.cpp @@ -517,9 +517,9 @@ std::vector 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);