diff --git a/mod.json b/mod.json index 0c405ee..89f7f89 100644 --- a/mod.json +++ b/mod.json @@ -1,10 +1,10 @@ { - "geode": "3.8.1", + "geode": "4.0.0", "version": "v1.6.2", "gd": { - "win": "2.206", - "android": "2.206", - "mac": "2.206" + "win": "2.2073", + "android": "2.2073", + "mac": "2.2073" }, "id": "geode.texture-loader", "name": "Texture Loader", diff --git a/src/Pack.cpp b/src/Pack.cpp index fecf01e..119e3b3 100644 --- a/src/Pack.cpp +++ b/src/Pack.cpp @@ -8,14 +8,12 @@ Result PackInfo::from(matjson::Value const& json) { auto info = PackInfo(); auto copyJson = json; - auto checker = JsonChecker(copyJson); - auto root = checker.root("[pack.json]").obj(); + auto root = checkJson(copyJson, "[pack.json]"); auto target = root.needs("textureldr").get(); - if (checker.isError()) { - return Err(checker.getError()); - } + GEODE_UNWRAP(root.ok()); + auto current = Mod::get()->getVersion(); if (target > VersionInfo(current.getMajor(), current.getMinor(), 99999999)) { return Err("Pack targets newer version of TextureLdr"); @@ -26,7 +24,7 @@ Result PackInfo::from(matjson::Value const& json) { root.needs("version").into(info.m_version); // has single "author" key? - if (auto author = root.has("author").as()) { + if (auto& author = root.has("author").assertIsString()) { info.m_authors = { author.get() }; } // otherwise use "authors" key @@ -34,9 +32,7 @@ Result PackInfo::from(matjson::Value const& json) { root.needs("authors").into(info.m_authors); } - if (checker.isError()) { - return Err(checker.getError()); - } + GEODE_UNWRAP(root.ok()); return Ok(info); } @@ -76,15 +72,8 @@ Result<> Pack::unapply() const { Result<> Pack::parsePackJson() { try { - auto data = file::readString(m_resourcesPath / "pack.json"); - if (!data) { - return Err(data.error()); - } - auto res = PackInfo::from(matjson::Value::from_str(data.value())); - if (!res) { - return Err(res.unwrapErr()); - } - m_info = res.unwrap(); + GEODE_UNWRAP_INTO(auto json, file::readJson(m_resourcesPath / "pack.json")); + GEODE_UNWRAP_INTO(m_info, PackInfo::from(json)); return Ok(); } catch(std::exception& e) { return Err("Unable to parse pack.json: {}", e.what()); @@ -241,12 +230,12 @@ Result> Pack::from(std::filesystem::path const& dir) { return Ok(pack); } -matjson::Value matjson::Serialize>::to_json(std::shared_ptr const& pack) { - return matjson::Object({ +matjson::Value matjson::Serialize>::toJson(std::shared_ptr const& pack) { + return matjson::makeObject({ { "path", pack->getOriginPath() } }); } -std::shared_ptr matjson::Serialize>::from_json(matjson::Value const& value) { - return Pack::from(value["path"].as()).unwrap(); +Result> matjson::Serialize>::fromJson(matjson::Value const& value) { + return Ok(Pack::from(value["path"].as().unwrap()).unwrap()); } diff --git a/src/Pack.hpp b/src/Pack.hpp index c33c4a3..21f2675 100644 --- a/src/Pack.hpp +++ b/src/Pack.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -52,9 +52,6 @@ class Pack { template <> struct matjson::Serialize> { - static matjson::Value to_json(std::shared_ptr const& pack); - static std::shared_ptr from_json(matjson::Value const& value); - static bool is_json(matjson::Value const& value) { - return value.is_object(); - } + static matjson::Value toJson(std::shared_ptr const& pack); + static Result> fromJson(matjson::Value const& value); }; diff --git a/src/PackInfoPopup.cpp b/src/PackInfoPopup.cpp index 9eebce8..b779e84 100644 --- a/src/PackInfoPopup.cpp +++ b/src/PackInfoPopup.cpp @@ -147,7 +147,7 @@ bool PackInfoPopup::setup(std::shared_ptr pack) { PackInfoPopup* PackInfoPopup::create(const std::shared_ptr& pack) { auto ret = new PackInfoPopup; ret->m_pack = pack; - if (ret->init( + if (ret->initAnchored( 320.f, 200.f, pack, ret->getPathInPack("GJ_square01.png").string().c_str() )) { diff --git a/src/PackManager.cpp b/src/PackManager.cpp index 092a9f4..332f1bd 100644 --- a/src/PackManager.cpp +++ b/src/PackManager.cpp @@ -39,7 +39,7 @@ void PackManager::movePackToIdx(const std::shared_ptr& pack, PackListType } void PackManager::savePacks() { - Mod::get()->getSaveContainer()["applied"] = m_applied; + Mod::get()->setSavedValue("applied", m_applied); } std::filesystem::path PackManager::getPackDir() { @@ -75,11 +75,13 @@ size_t PackManager::loadPacks() { std::vector> savedApplied; // manually do this so we can skip packs that fail - for (auto const& obj : Mod::get()->getSavedValue("applied")) { - if (obj.is_object() && obj.contains("path") && obj["path"].is_string()) { - auto res = Pack::from(obj["path"].as()); - if (res) { - savedApplied.push_back(res.unwrap()); + for (auto const& obj : Mod::get()->getSavedValue>("applied")) { + if (obj.isObject() && obj.contains("path") && obj["path"].isString()) { + if(auto pathRes = obj["path"].as()) { + auto res = Pack::from(pathRes.unwrap()); + if (res) { + savedApplied.push_back(res.unwrap()); + } } } }