Skip to content

Commit

Permalink
update for even newer matjson
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Nov 11, 2024
1 parent c545a62 commit 04f7ab0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
14 changes: 2 additions & 12 deletions src/managers/BaseJsonManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@ Result<> BaseJsonManager::load() {

auto savedPath = Mod::get()->getSaveDir() / m_filename;
if (std::filesystem::exists(savedPath)) {
auto result = utils::file::readString(savedPath);
if (!result) {
return Err(result.unwrapErr());
}

std::string error;
auto parsed = matjson::parse(result.unwrap());
if (!parsed) {
return Err("Unable to parse: {}", parsed.err());
}
m_json = parsed.unwrap();
GEODE_UNWRAP_INTO(m_json, utils::file::readJson(savedPath));

if (!m_json.isObject()) {
m_json = matjson::Value();
Expand All @@ -53,7 +43,7 @@ Result<> BaseJsonManager::save() {
//std::cout << ("Locking shared_lock save") << std::endl;
std::shared_lock guard(m_jsonMutex);
//TODO: v4 this func will change
std::string savedStr = m_json.dump(matjson::NO_INDENTATION).unwrap();
std::string savedStr = m_json.dump(matjson::NO_INDENTATION);

auto res2 = utils::file::writeString(Mod::get()->getSaveDir() / m_filename, savedStr);
if (!res2) {
Expand Down
5 changes: 4 additions & 1 deletion src/managers/BetterInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,10 @@ void BetterInfoCache::checkClaimableLists() {
if(value["diamonds"].asInt().unwrapOr(0) <= 0) continue;

auto listID = BetterInfo::stoi(key);
auto levels = value["levels"].asArray().unwrapOr(std::vector<matjson::Value>());
auto levelsRes = value["levels"].asArray();
if(!levelsRes) continue;

auto levels = levelsRes.unwrap();
auto levelsToClaim = value["levels-to-claim"].asInt().unwrapOr(0);

if(levelsToClaim <= 0) continue;
Expand Down
5 changes: 4 additions & 1 deletion src/managers/BetterInfoStatsV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ void BetterInfoStatsV2::logDeath(GJGameLevel* level, bool practice, LevelDeath d
std::pair<int, int> BetterInfoStatsV2::getCommonFail(GJGameLevel* gjLevel) {
std::unordered_map<int, int> fails;

auto attempts = levelObject(gjLevel)["attempts"].asArray().unwrapOr(std::vector<matjson::Value>());
auto attemptsRes = levelObject(gjLevel)["attempts"].asArray();
if(!attemptsRes) return {0,0};

auto attempts = attemptsRes.unwrap();
if(attempts.size() == 0) return {0,0};

for(auto& attempt : attempts) {
Expand Down

0 comments on commit 04f7ab0

Please sign in to comment.