mirror of
https://github.com/geode-sdk/geode.git
synced 2025-03-26 04:39:51 -04:00
i forgot about the json primitives
This commit is contained in:
parent
899a1a5d86
commit
89548f282c
1 changed files with 19 additions and 6 deletions
|
@ -51,10 +51,23 @@ namespace geode {
|
|||
return action == ModRequestedAction::Uninstall || action == ModRequestedAction::UninstallWithSaveData;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
concept TypeImplementsIsJSON = requires(matjson::Value v) {
|
||||
{ matjson::Serialize<std::decay_t<T>>::is_json(v) } -> std::same_as<bool>;
|
||||
};
|
||||
namespace internal {
|
||||
template <class T>
|
||||
static consteval bool typeImplementsIsJSON() {
|
||||
using namespace matjson;
|
||||
if constexpr (requires(const Value& json) { Serialize<std::decay_t<T>>::is_json(json); })
|
||||
return true;
|
||||
if constexpr (std::is_same_v<T, Value>) return true;
|
||||
if constexpr (std::is_same_v<T, Array>) return true;
|
||||
if constexpr (std::is_same_v<T, Object>) return true;
|
||||
if constexpr (std::is_constructible_v<std::string, T>) return true;
|
||||
if constexpr (std::is_integral_v<T> || std::is_floating_point_v<T>) return true;
|
||||
if constexpr (std::is_same_v<T, bool>) return true;
|
||||
if constexpr (std::is_same_v<T, std::nullptr_t>) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
GEODE_HIDDEN Mod* takeNextLoaderMod();
|
||||
|
||||
|
@ -243,7 +256,7 @@ namespace geode {
|
|||
|
||||
template <class T>
|
||||
T getSavedValue(std::string_view const key) {
|
||||
static_assert(TypeImplementsIsJSON<T>, "T must implement is_json in matjson::Serialize<T>, otherwise this always returns default value.");
|
||||
static_assert(internal::typeImplementsIsJSON<T>(), "T must implement is_json in matjson::Serialize<T>, otherwise this always returns default value.");
|
||||
auto& saved = this->getSaveContainer();
|
||||
if (saved.contains(key)) {
|
||||
if (auto value = saved.try_get<T>(key)) {
|
||||
|
@ -255,7 +268,7 @@ namespace geode {
|
|||
|
||||
template <class T>
|
||||
T getSavedValue(std::string_view const key, T const& defaultValue) {
|
||||
static_assert(TypeImplementsIsJSON<T>, "T must implement is_json in matjson::Serialize<T>, otherwise this always returns default value.");
|
||||
static_assert(internal::typeImplementsIsJSON<T>(), "T must implement is_json in matjson::Serialize<T>, otherwise this always returns default value.");
|
||||
auto& saved = this->getSaveContainer();
|
||||
if (saved.contains(key)) {
|
||||
if (auto value = saved.try_get<T>(key)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue