From 3f674e522d47364025dc7f210daaa94c730c612b Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:48:19 +0300 Subject: [PATCH] quick impl one-of --- loader/include/Geode/loader/Setting.hpp | 5 +++++ loader/src/loader/Setting.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/loader/include/Geode/loader/Setting.hpp b/loader/include/Geode/loader/Setting.hpp index 932a367c..d95a01f5 100644 --- a/loader/include/Geode/loader/Setting.hpp +++ b/loader/include/Geode/loader/Setting.hpp @@ -101,6 +101,11 @@ namespace geode { */ std::optional filter; + /** + * A list of options the user can choose from + */ + std::optional> options; + static Result parse(JsonMaybeObject& obj); }; diff --git a/loader/src/loader/Setting.cpp b/loader/src/loader/Setting.cpp index 45225e11..4f330264 100644 --- a/loader/src/loader/Setting.cpp +++ b/loader/src/loader/Setting.cpp @@ -75,6 +75,7 @@ Result StringSetting::parse(JsonMaybeObject& obj) { parseCommon(sett, obj); obj.has("match").into(sett.match); obj.has("filter").into(sett.filter); + obj.has("one-of").into(sett.options); return Ok(sett); } @@ -376,6 +377,21 @@ IMPL_TO_VALID(String) { }; } } + else if (m_definition.options) { + if (std::find( + m_definition.options.value().begin(), + m_definition.options.value().end(), + value + ) == m_definition.options.value().end()) { + return { + m_definition.defaultValue, + fmt::format( + "Value must be one of {}", + fmt::join(m_definition.options.value(), ", ") + ) + }; + } + } return { value, std::nullopt }; }