Skip to content

Commit

Permalink
update for geode v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Nov 10, 2024
1 parent 722f7d1 commit 6e6c5f2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
8 changes: 4 additions & 4 deletions mod.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
33 changes: 11 additions & 22 deletions src/Pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ Result<PackInfo> 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<VersionInfo>();

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");
Expand All @@ -26,17 +24,15 @@ Result<PackInfo> PackInfo::from(matjson::Value const& json) {
root.needs("version").into(info.m_version);

// has single "author" key?
if (auto author = root.has("author").as<matjson::Type::String>()) {
if (auto& author = root.has("author").assertIsString()) {
info.m_authors = { author.get<std::string>() };
}
// otherwise use "authors" key
else {
root.needs("authors").into(info.m_authors);
}

if (checker.isError()) {
return Err(checker.getError());
}
GEODE_UNWRAP(root.ok());

return Ok(info);
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -241,12 +230,12 @@ Result<std::shared_ptr<Pack>> Pack::from(std::filesystem::path const& dir) {
return Ok(pack);
}

matjson::Value matjson::Serialize<std::shared_ptr<Pack>>::to_json(std::shared_ptr<Pack> const& pack) {
return matjson::Object({
matjson::Value matjson::Serialize<std::shared_ptr<Pack>>::toJson(std::shared_ptr<Pack> const& pack) {
return matjson::makeObject({
{ "path", pack->getOriginPath() }
});
}

std::shared_ptr<Pack> matjson::Serialize<std::shared_ptr<Pack>>::from_json(matjson::Value const& value) {
return Pack::from(value["path"].as<std::filesystem::path>()).unwrap();
Result<std::shared_ptr<Pack>> matjson::Serialize<std::shared_ptr<Pack>>::fromJson(matjson::Value const& value) {
return Ok(Pack::from(value["path"].as<std::filesystem::path>().unwrap()).unwrap());
}
9 changes: 3 additions & 6 deletions src/Pack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>
#include <optional>
#include <memory>
#include <Geode/utils/Result.hpp>
#include <Geode/Result.hpp>
#include <Geode/utils/VersionInfo.hpp>
#include <Geode/ui/EnterLayerEvent.hpp>
#include <matjson/stl_serialize.hpp>
Expand Down Expand Up @@ -52,9 +52,6 @@ class Pack {

template <>
struct matjson::Serialize<std::shared_ptr<Pack>> {
static matjson::Value to_json(std::shared_ptr<Pack> const& pack);
static std::shared_ptr<Pack> 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<Pack> const& pack);
static Result<std::shared_ptr<Pack>> fromJson(matjson::Value const& value);
};
2 changes: 1 addition & 1 deletion src/PackInfoPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ bool PackInfoPopup::setup(std::shared_ptr<Pack> pack) {
PackInfoPopup* PackInfoPopup::create(const std::shared_ptr<Pack>& 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()
)) {
Expand Down
14 changes: 8 additions & 6 deletions src/PackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void PackManager::movePackToIdx(const std::shared_ptr<Pack>& pack, PackListType
}

void PackManager::savePacks() {
Mod::get()->getSaveContainer()["applied"] = m_applied;
Mod::get()->setSavedValue("applied", m_applied);
}

std::filesystem::path PackManager::getPackDir() {
Expand Down Expand Up @@ -75,11 +75,13 @@ size_t PackManager::loadPacks() {

std::vector<std::shared_ptr<Pack>> savedApplied;
// manually do this so we can skip packs that fail
for (auto const& obj : Mod::get()->getSavedValue<matjson::Array>("applied")) {
if (obj.is_object() && obj.contains("path") && obj["path"].is_string()) {
auto res = Pack::from(obj["path"].as<std::filesystem::path>());
if (res) {
savedApplied.push_back(res.unwrap());
for (auto const& obj : Mod::get()->getSavedValue<std::vector<matjson::Value>>("applied")) {
if (obj.isObject() && obj.contains("path") && obj["path"].isString()) {
if(auto pathRes = obj["path"].as<std::filesystem::path>()) {
auto res = Pack::from(pathRes.unwrap());
if (res) {
savedApplied.push_back(res.unwrap());
}
}
}
}
Expand Down

0 comments on commit 6e6c5f2

Please sign in to comment.