From 753fd4e1526faa5ee1ce688f43199204f56604f3 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Thu, 18 Jan 2024 09:51:40 -0300 Subject: [PATCH] add PlatformID::toShortString and other things --- loader/include/Geode/platform/platform.hpp | 14 ++++++++++++++ loader/src/loader/ModMetadataImpl.cpp | 13 +------------ loader/src/utils/PlatformID.cpp | 15 +++++++++++++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/loader/include/Geode/platform/platform.hpp b/loader/include/Geode/platform/platform.hpp index aa0f0cbc..d22bf6a5 100644 --- a/loader/include/Geode/platform/platform.hpp +++ b/loader/include/Geode/platform/platform.hpp @@ -158,6 +158,20 @@ namespace geode { return "Undefined"; } + static constexpr char const* toShortString(Type lp, bool ignoreArch = false) { + switch (lp) { + case Unknown: return "unknown"; + case Windows: return "win"; + case MacOS: return "mac"; + case iOS: return "ios"; + case Android32: return ignoreArch ? "android" : "android32"; + case Android64: return ignoreArch ? "android" : "android64"; + case Linux: return "linux"; + default: break; + } + return "undefined"; + } + template requires requires(T t) { static_cast(t); diff --git a/loader/src/loader/ModMetadataImpl.cpp b/loader/src/loader/ModMetadataImpl.cpp index c9eee2cd..0fa359f8 100644 --- a/loader/src/loader/ModMetadataImpl.cpp +++ b/loader/src/loader/ModMetadataImpl.cpp @@ -181,18 +181,7 @@ Result ModMetadata::Impl::create(ModJson const& json) { if (json["gd"].is_string()) { ver = json["gd"].as_string(); } else if (json["gd"].is_object()) { - std::string key; - switch (GEODE_PLATFORM_TARGET) { - case PlatformID::Android32: - case PlatformID::Android64: - key = "android"; break; - case PlatformID::MacOS: - key = "mac"; break; - case PlatformID::Windows: - key = "win"; break; - case PlatformID::iOS: - key = "ios"; break; - } + auto key = PlatformID::toShortString(GEODE_PLATFORM_TARGET, true); if (json["gd"].contains(key)) ver = json["gd"][ver].as_string(); } else { diff --git a/loader/src/utils/PlatformID.cpp b/loader/src/utils/PlatformID.cpp index 034e766d..b05019ea 100644 --- a/loader/src/utils/PlatformID.cpp +++ b/loader/src/utils/PlatformID.cpp @@ -6,14 +6,25 @@ using namespace geode::prelude; PlatformID PlatformID::from(const char* str) { switch (hash(str)) { - default: - case hash("unknown"): return PlatformID::Unknown; + case hash("win"): + case hash("Windows"): case hash("windows"): return PlatformID::Windows; + + case hash("mac"): + case hash("MacOS"): case hash("macos"): return PlatformID::MacOS; + + case hash("iOS"): case hash("ios"): return PlatformID::iOS; + + case hash("Android32"): case hash("android32"): return PlatformID::Android32; + case hash("Android64"): case hash("android64"): return PlatformID::Android64; + + case hash("Linux"): case hash("linux"): return PlatformID::Linux; + default: return PlatformID::Unknown; } }