Skip to content

Commit 1d69529

Browse files
committed
fix fetched vars
1 parent c7a29f0 commit 1d69529

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

incl/Avalanche.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
#include <Geode/utils/terminate.hpp>
1515

1616
using namespace geode::prelude;
17+
using namespace matjson;
1718

1819
namespace avalanche { // Avalanche Index mod namespace
1920
extern Mod* AVAL_MOD; // Get the mod instance
2021

22+
extern Value fetchedBadges; // Cached profile data
23+
extern Value fetchedLevels; // Cached project data
24+
2125
extern int ACC_PUBLISHER; // Account ID of Avalanche's level publisher account
2226

2327
constexpr const char* URL_CUBIC = "https://www.cubicstudios.xyz/"; // URL to Cubic Studios's official website

incl/src/Avalanche.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ using namespace matjson;
2121
namespace avalanche {
2222
Mod* AVAL_MOD = getMod(); // Get the mod instance
2323

24+
Value fetchedBadges = Value();
25+
Value fetchedLevels = Value();
26+
2427
int ACC_PUBLISHER = 31079132;
2528
std::string URL_MOD_ISSUES = AVAL_MOD->getMetadataRef().getIssues().value().url.value_or(URL_AVALANCHE); // URL to the mod's issues page on its GitHub repository
2629

27-
Value fetchedBadges = Value(); // Cached profile data
28-
Value fetchedLevels = Value(); // Cached project data
29-
3030
EventListener<web::WebTask> badgeListReq; // Web request listener for team profile data
3131
EventListener<web::WebTask> levelListReq; // Web request listener for team project data
3232

@@ -173,7 +173,7 @@ namespace avalanche {
173173
for (auto& [key, value] : jsonRes) {
174174
auto cacheKey = fmt::format("cache-level-p{}", (std::string)key);
175175

176-
if (AVAL_MOD->getSettingValue<bool>("web-once")) fetchedBadges.set(key, value);
176+
if (AVAL_MOD->getSettingValue<bool>("web-once")) fetchedLevels.set(key, value);
177177
AVAL_MOD->setSavedValue(cacheKey, value);
178178
};
179179
};
@@ -211,7 +211,7 @@ namespace avalanche {
211211
log::warn("Session web cache for badge data is unaccessible");
212212
} else if (fetchedBadges.isObject()) {
213213
auto key = std::to_string(id);
214-
fetchedBadges.contains(key) ? cacheStd = fetchedBadges[key.c_str()] : cacheStd = Value::object();
214+
fetchedBadges.contains(key) ? cacheStd = fetchedBadges.get(key).unwrapOr(cacheStd) : cacheStd = Value::object();
215215
};
216216
} else {
217217
log::warn("Fetching badge data directly from saved cache");
@@ -245,7 +245,7 @@ namespace avalanche {
245245
log::warn("Session web cache for level data is unaccessible");
246246
} else if (fetchedLevels.isObject()) {
247247
auto key = std::to_string(id);
248-
fetchedLevels.contains(key) ? cacheStd = fetchedLevels[key.c_str()] : cacheStd = Value::object();
248+
fetchedLevels.contains(key) ? cacheStd = fetchedLevels.get(key).unwrapOr(cacheStd) : cacheStd = Value::object();
249249
};
250250
} else {
251251
log::warn("Fetching badge data directly from saved cache");
@@ -258,7 +258,7 @@ namespace avalanche {
258258
auto c_name = cacheStd["name"].asString().unwrapOr(und);
259259
auto c_host = cacheStd["host"].asString().unwrapOr(und);
260260
auto c_showcase = cacheStd["showcase"].asString().unwrapOr(und);
261-
auto c_thumbnail = cacheStd["thumbnail"].asString().unwrapOr("");
261+
auto c_thumbnail = cacheStd["thumbnail"].asString().unwrapOr(und);
262262
auto c_type = Handler::Levels::fromString(cacheStd["type"].asString().unwrapOr(und));
263263
auto c_fame = cacheStd["fame"].asBool().unwrapOr(false);
264264

0 commit comments

Comments
 (0)