From b241c1ccda20b4352a472630a1319ec49dc7bad6 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 10 Feb 2024 13:36:11 +0200 Subject: [PATCH] add platform-specific settings + update changelog and bump version --- CHANGELOG.md | 10 +++++++++ VERSION | 2 +- loader/include/Geode/utils/cocos.hpp | 4 ++-- loader/src/loader/ModMetadataImpl.cpp | 14 +++++++++++++ loader/src/utils/cocos.cpp | 30 +++++++++++---------------- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cca3cd0..d1726ad0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Geode Changelog +## v2.0.0-beta.17 + * Add `$override` macro for syntactic sugar (e7a1913) + * Add support for platform-specific setting default values as well as platform-specific settings (9c8fcf1) + * Change `cc3bFromHexString` and `cc4bFromHexString` to be more strict with parsing by default (9c8fcf1) + * `JsonMaybeValue::is` is now a lot more reasonable (9c8fcf1) + * Make `LayoutOptions` also `CCObject` (3b7621c) + * Fix RobTop's socials in MenuLayer (cee8c74) + * Fix issues in CMake (d574248, 4ddd92d) + * Fix input nodes being clickable when invisible (bf32946) + ## v2.0.0-beta.16 * Bump minimum CMake version to 3.25 * Add support for platform-specific dependencies (30c7d3f) diff --git a/VERSION b/VERSION index 589a721c..6bcfde63 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0-beta.16 \ No newline at end of file +2.0.0-beta.17 \ No newline at end of file diff --git a/loader/include/Geode/utils/cocos.hpp b/loader/include/Geode/utils/cocos.hpp index 48e15999..99a21e69 100644 --- a/loader/include/Geode/utils/cocos.hpp +++ b/loader/include/Geode/utils/cocos.hpp @@ -817,7 +817,7 @@ namespace geode::cocos { } /** - * Parse a ccColor3B from a hexadecimal string. The string may not contain + * Parse a ccColor3B from a hexadecimal string. The string may contain * a leading '#' * @param hexValue The string to parse into a color * @param permissive If true, strings like "f" are considered valid @@ -828,7 +828,7 @@ namespace geode::cocos { */ GEODE_DLL Result cc3bFromHexString(std::string const& hexValue, bool permissive = false); /** - * Parse a ccColor4B from a hexadecimal string. The string may not contain + * Parse a ccColor4B from a hexadecimal string. The string may contain * a leading '#' * @param hexValue The string to parse into a color * @param requireAlpha Require the alpha component to be passed. If false, diff --git a/loader/src/loader/ModMetadataImpl.cpp b/loader/src/loader/ModMetadataImpl.cpp index 4e288912..0b855ef0 100644 --- a/loader/src/loader/ModMetadataImpl.cpp +++ b/loader/src/loader/ModMetadataImpl.cpp @@ -172,6 +172,20 @@ Result ModMetadata::Impl::createFromSchemaV010(ModJson const& rawJs } for (auto& [key, value] : root.has("settings").items()) { + // Skip settings not on this platform + if (value.template is()) { + auto obj = value.obj(); + bool onThisPlatform = !obj.has("platforms"); + for (auto& plat : obj.has("platforms").iterate()) { + if (PlatformID::from(plat.get()) == GEODE_PLATFORM_TARGET) { + onThisPlatform = true; + } + } + if (!onThisPlatform) { + continue; + } + } + GEODE_UNWRAP_INTO(auto sett, Setting::parse(key, impl->m_id, value)); impl->m_settings.emplace_back(key, sett); } diff --git a/loader/src/utils/cocos.cpp b/loader/src/utils/cocos.cpp index 0db65f29..7da9aad4 100644 --- a/loader/src/utils/cocos.cpp +++ b/loader/src/utils/cocos.cpp @@ -38,14 +38,7 @@ ccColor3B matjson::Serialize::from_json(matjson::Value const& json) { } // hex string else if (json.is_string()) { - std::string str = json.as_string(); - if (str[0] == '#') { - str.erase(str.begin()); - } - if (str.size() > 6) { - throw matjson::JsonException("Hex string for color too long"); - } - auto c = cc3bFromHexString(str); + auto c = cc3bFromHexString(json.as_string()); if (!c) { throw matjson::JsonException("Invalid color hex string"); } @@ -94,14 +87,7 @@ ccColor4B matjson::Serialize::from_json(matjson::Value const& json) { } // hex string else if (json.is_string()) { - std::string str = json.as_string(); - if (str[0] == '#') { - str.erase(str.begin()); - } - if (str.size() > 8) { - throw matjson::JsonException("Hex string for color too long"); - } - auto c = cc4bFromHexString(str); + auto c = cc4bFromHexString(json.as_string()); if (!c) { throw matjson::JsonException("Invalid color hex string: " + c.unwrapErr()); } @@ -114,7 +100,11 @@ ccColor4B matjson::Serialize::from_json(matjson::Value const& json) { return color; } -Result geode::cocos::cc3bFromHexString(std::string const& hexValue, bool permissive) { +Result geode::cocos::cc3bFromHexString(std::string const& rawHexValue, bool permissive) { + auto hexValue = rawHexValue; + if (hexValue[0] == '#') { + hexValue.erase(hexValue.begin()); + } if (permissive && hexValue.empty()) { return Ok(ccc3(255, 255, 255)); } @@ -168,7 +158,11 @@ Result geode::cocos::cc3bFromHexString(std::string const& hexValue, b } } -Result geode::cocos::cc4bFromHexString(std::string const& hexValue, bool requireAlpha, bool permissive) { +Result geode::cocos::cc4bFromHexString(std::string const& rawHexValue, bool requireAlpha, bool permissive) { + auto hexValue = rawHexValue; + if (hexValue[0] == '#') { + hexValue.erase(hexValue.begin()); + } if (permissive && hexValue.empty()) { return Ok(ccc4(255, 255, 255, 255)); }