Skip to content

Commit

Permalink
update json library, changes namespace to matjson
Browse files Browse the repository at this point in the history
very breaking change! though not annoying to upgrade. this change was
done because matjson is not really meant to be a "do everything" json
library, so taking up the very common `json` identifier was troublesome.
  • Loading branch information
matcool committed Jan 3, 2024
1 parent a8deaef commit b9a09f7
Show file tree
Hide file tree
Showing 37 changed files with 167 additions and 167 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ include(cmake/CPM.cmake)
if (PROJECT_IS_TOP_LEVEL AND NOT GEODE_BUILDING_DOCS)
set(MAT_JSON_AS_INTERFACE ON)
endif()
CPMAddPackage("gh:geode-sdk/json#a47f570")
CPMAddPackage("gh:geode-sdk/json#9f54cca")
CPMAddPackage("gh:fmtlib/fmt#10.1.1")
CPMAddPackage("gh:gulrak/filesystem#3e5b930")

Expand Down
2 changes: 1 addition & 1 deletion loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ if (NOT GEODE_BUILDING_DOCS)
target_link_libraries(${PROJECT_NAME} md4c re2 minizip)
endif()

target_link_libraries(${PROJECT_NAME} z TulipHook geode-sdk mat-json)
target_link_libraries(${PROJECT_NAME} z TulipHook geode-sdk mat-json-impl)

if (MSVC)
# Disable outputting .exp file
Expand Down
10 changes: 5 additions & 5 deletions loader/include/Geode/cocos/base_nodes/CCNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include "../include/CCProtocols.h"
#include "Layout.hpp"
#include "../../loader/Event.hpp"
#include <json.hpp>
#include <matjson.hpp>

NS_CC_BEGIN

Expand Down Expand Up @@ -845,7 +845,7 @@ class CC_DLL CCNode : public CCObject
friend class geode::modifier::FieldContainer;

GEODE_DLL geode::modifier::FieldContainer* getFieldContainer();
GEODE_DLL std::optional<json::Value> getAttributeInternal(std::string const& attribute);
GEODE_DLL std::optional<matjson::Value> getAttributeInternal(std::string const& attribute);
GEODE_DLL void addEventListenerInternal(
std::string const& id,
geode::EventListenerProtocol* protocol
Expand Down Expand Up @@ -935,7 +935,7 @@ class CC_DLL CCNode : public CCObject
* @param value The value of the attribute
* @note Geode addition
*/
GEODE_DLL void setAttribute(std::string const& attribute, json::Value const& value);
GEODE_DLL void setAttribute(std::string const& attribute, matjson::Value const& value);
/**
* Get an attribute from the node. Attributes may be anything
* @param attribute The attribute key
Expand Down Expand Up @@ -1772,9 +1772,9 @@ namespace geode {
struct GEODE_DLL AttributeSetEvent : public Event {
cocos2d::CCNode* node;
const std::string id;
json::Value& value;
matjson::Value& value;

AttributeSetEvent(cocos2d::CCNode* node, std::string const& id, json::Value& value);
AttributeSetEvent(cocos2d::CCNode* node, std::string const& id, matjson::Value& value);
};

class GEODE_DLL AttributeSetFilter : public EventFilter<AttributeSetEvent> {
Expand Down
6 changes: 3 additions & 3 deletions loader/include/Geode/loader/Hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../DefaultInclude.hpp"
#include "../utils/general.hpp"
#include <json.hpp>
#include <matjson.hpp>
#include "Tulip.hpp"
#include <inttypes.h>
#include <string_view>
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace geode {
* Get info about the hook as JSON
* @note For IPC
*/
json::Value getRuntimeInfo() const;
matjson::Value getRuntimeInfo() const;

/**
* Get the metadata of the hook.
Expand Down Expand Up @@ -194,7 +194,7 @@ namespace geode {
* Get info about the patch as JSON
* @note For IPC
*/
json::Value getRuntimeInfo() const;
matjson::Value getRuntimeInfo() const;

/**
* Get whether the patch should be auto enabled or not.
Expand Down
14 changes: 7 additions & 7 deletions loader/include/Geode/loader/IPC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "Event.hpp"
#include "Loader.hpp"
#include <json.hpp>
#include <matjson.hpp>

namespace geode {
#ifdef GEODE_IS_WINDOWS
Expand Down Expand Up @@ -32,24 +32,24 @@ namespace geode {
public:
std::string targetModID;
std::string messageID;
std::unique_ptr<json::Value> messageData;
json::Value& replyData;
std::unique_ptr<matjson::Value> messageData;
matjson::Value& replyData;

friend class IPCFilter;

IPCEvent(
void* rawPipeHandle,
std::string const& targetModID,
std::string const& messageID,
json::Value const& messageData,
json::Value& replyData
matjson::Value const& messageData,
matjson::Value& replyData
);
virtual ~IPCEvent();
};

class GEODE_DLL IPCFilter : public EventFilter<IPCEvent> {
public:
using Callback = json::Value(IPCEvent*);
using Callback = matjson::Value(IPCEvent*);

protected:
std::string m_modID;
Expand All @@ -64,5 +64,5 @@ namespace geode {
IPCFilter(IPCFilter const&) = default;
};

std::monostate listenForIPC(std::string const& messageID, json::Value(*callback)(IPCEvent*));
std::monostate listenForIPC(std::string const& messageID, matjson::Value(*callback)(IPCEvent*));
}
4 changes: 2 additions & 2 deletions loader/include/Geode/loader/Mod.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "Setting.hpp"
#include "Types.hpp"

#include <json.hpp>
#include <matjson.hpp>
#include <optional>
#include <string_view>
#include <tulip/TulipHook.hpp>
Expand Down Expand Up @@ -151,7 +151,7 @@ namespace geode {
this->registerCustomSetting(key, std::make_unique<T>(key, this->getID(), value));
}

json::Value& getSaveContainer();
matjson::Value& getSaveContainer();

template <class T>
T getSettingValue(std::string const& key) const {
Expand Down
2 changes: 1 addition & 1 deletion loader/include/Geode/loader/ModJsonTest.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Mod.hpp"

#include <json.hpp>
#include <matjson.hpp>

namespace geode {}
6 changes: 3 additions & 3 deletions loader/include/Geode/loader/ModMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Setting.hpp"
#include "Types.hpp"

#include <json.hpp>
#include <matjson.hpp>
#include <memory>

namespace geode {
Expand Down Expand Up @@ -228,8 +228,8 @@ namespace geode {
}

template <>
struct json::Serialize<geode::ModMetadata> {
static json::Value to_json(geode::ModMetadata const& info) {
struct matjson::Serialize<geode::ModMetadata> {
static matjson::Value to_json(geode::ModMetadata const& info) {
return info.toJSON();
}
};
10 changes: 5 additions & 5 deletions loader/include/Geode/loader/Setting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "../DefaultInclude.hpp"
#include "../utils/Result.hpp"
#include "../utils/file.hpp"
#include <json.hpp>
#include <matjson.hpp>
#include <optional>
#include <unordered_set>
#include <cocos2d.h>
Expand Down Expand Up @@ -230,8 +230,8 @@ namespace geode {

public:
virtual ~SettingValue() = default;
virtual bool load(json::Value const& json) = 0;
virtual bool save(json::Value& json) const = 0;
virtual bool load(matjson::Value const& json) = 0;
virtual bool save(matjson::Value& json) const = 0;
virtual SettingNode* createNode(float width) = 0;

std::string getKey() const;
Expand All @@ -257,8 +257,8 @@ namespace geode {
m_definition(definition),
m_value(definition.defaultValue) {}

bool load(json::Value const& json) override;
bool save(json::Value& json) const;
bool load(matjson::Value const& json) override;
bool save(matjson::Value& json) const;

GEODE_DLL SettingNode* createNode(float width) override;
T castDefinition() const {
Expand Down
6 changes: 3 additions & 3 deletions loader/include/Geode/loader/SettingJsonTest.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "Setting.hpp"
#include <json.hpp>
#include <matjson.hpp>

namespace geode {
template<class T>
bool GeodeSettingValue<T>::load(json::Value const& json) {
bool GeodeSettingValue<T>::load(matjson::Value const& json) {
try {
m_value = json.as<ValueType>();
return true;
Expand All @@ -14,7 +14,7 @@ namespace geode {
}

template<class T>
bool GeodeSettingValue<T>::save(json::Value& json) const {
bool GeodeSettingValue<T>::save(matjson::Value& json) const {
json = m_value;
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions loader/include/Geode/loader/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../DefaultInclude.hpp"
#include "../platform/cplatform.h"
#include <json.hpp>
#include <matjson.hpp>

#include <string>

Expand Down Expand Up @@ -146,7 +146,7 @@ namespace geode {
}

// TODO: make ordered
using ModJson = json::Value;
using ModJson = matjson::Value;
}

/**
Expand Down
26 changes: 13 additions & 13 deletions loader/include/Geode/utils/JsonValidation.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <json.hpp>
#include <matjson.hpp>
#include "../loader/Log.hpp"

#include <set>
Expand All @@ -21,7 +21,7 @@ namespace geode {
constexpr bool is_iterable_v = is_iterable<T>::value;

namespace {
using value_t = json::Type;
using value_t = matjson::Type;

constexpr char const* jsonValueTypeToString(value_t type) {
switch (type) {
Expand Down Expand Up @@ -80,7 +80,7 @@ namespace geode {
struct GEODE_DLL JsonMaybeSomething {
protected:
JsonChecker& m_checker;
json::Value& m_json;
matjson::Value& m_json;
std::string m_hierarchy;
bool m_hasValue;

Expand All @@ -90,10 +90,10 @@ namespace geode {
void setError(std::string const& error);

public:
json::Value& json();
matjson::Value& json();

JsonMaybeSomething(
JsonChecker& checker, json::Value& json, std::string const& hierarchy, bool hasValue
JsonChecker& checker, matjson::Value& json, std::string const& hierarchy, bool hasValue
);

bool isError() const;
Expand All @@ -106,12 +106,12 @@ namespace geode {
bool m_inferType = true;

JsonMaybeValue(
JsonChecker& checker, json::Value& json, std::string const& hierarchy, bool hasValue
JsonChecker& checker, matjson::Value& json, std::string const& hierarchy, bool hasValue
);

JsonMaybeSomething& self();

template <json::Type T>
template <matjson::Type T>
JsonMaybeValue& as() {
if (this->isError()) return *this;
if (!jsonConvertibleTo(self().m_json.type(), T)) {
Expand All @@ -126,7 +126,7 @@ namespace geode {

JsonMaybeValue& array();

template <json::Type... T>
template <matjson::Type... T>
JsonMaybeValue& asOneOf() {
if (this->isError()) return *this;
bool isOneOf = (... || jsonConvertibleTo(self().m_json.type(), T));
Expand All @@ -140,7 +140,7 @@ namespace geode {
return *this;
}

template <json::Type T>
template <matjson::Type T>
JsonMaybeValue& is() {
if (this->isError()) return *this;
self().m_hasValue = jsonConvertibleTo(self().m_json.type(), T);
Expand Down Expand Up @@ -268,14 +268,14 @@ namespace geode {
std::set<std::string> m_knownKeys;

JsonMaybeObject(
JsonChecker& checker, json::Value& json, std::string const& hierarchy, bool hasValue
JsonChecker& checker, matjson::Value& json, std::string const& hierarchy, bool hasValue
);

JsonMaybeSomething& self();

void addKnownKey(std::string const& key);

json::Value& json();
matjson::Value& json();

JsonMaybeValue emptyValue();

Expand All @@ -288,9 +288,9 @@ namespace geode {

struct GEODE_DLL JsonChecker {
std::variant<std::monostate, std::string> m_result;
json::Value& m_json;
matjson::Value& m_json;

JsonChecker(json::Value& json);
JsonChecker(matjson::Value& json);

bool isError() const;

Expand Down
10 changes: 5 additions & 5 deletions loader/include/Geode/utils/VersionInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "../DefaultInclude.hpp"
#include <string_view>
#include <json.hpp>
#include <matjson.hpp>
#include <tuple>
#include "../utils/Result.hpp"

Expand Down Expand Up @@ -232,15 +232,15 @@ namespace geode {

template <class V>
requires std::is_same_v<V, geode::VersionInfo> || std::is_same_v<V, geode::ComparableVersionInfo>
struct json::Serialize<V> {
static json::Value to_json(V const& info) {
struct matjson::Serialize<V> {
static matjson::Value to_json(V const& info) {
return info.toString();
}

static V from_json(json::Value const& json) {
static V from_json(matjson::Value const& json) {
auto ver = V::parse(json.as_string());
if (!ver) {
throw json::JsonException(
throw matjson::JsonException(
"Invalid version format: " + ver.unwrapErr()
);
}
Expand Down
Loading

0 comments on commit b9a09f7

Please sign in to comment.