From 22add14a9f723f02bd65fd9d76ba43a4aff26638 Mon Sep 17 00:00:00 2001 From: The Bearodactyl Date: Wed, 19 Feb 2025 20:14:44 -0600 Subject: [PATCH] (feat) add way for mod devs to programatically update setting names and descriptions --- loader/include/Geode/loader/Mod.hpp | 14 ++++++++++++++ loader/include/Geode/loader/SettingV3.hpp | 8 ++++++++ loader/src/loader/Mod.cpp | 12 ++++++++++++ loader/src/loader/SettingV3.cpp | 6 ++++++ 4 files changed, 40 insertions(+) diff --git a/loader/include/Geode/loader/Mod.hpp b/loader/include/Geode/loader/Mod.hpp index 84e51fc36..c4da8f229 100644 --- a/loader/include/Geode/loader/Mod.hpp +++ b/loader/include/Geode/loader/Mod.hpp @@ -293,6 +293,20 @@ namespace geode { saved[key] = value; return old; } + + /** + * Set the name of setting. + * @param key Setting key + * @param name New name + */ + void setSettingName(std::string_view key, std::string_view name); + + /** + * Set the description of a setting. + * @param key Setting key + * @param desc New description + */ + void setSettingDescription(std::string_view key, std::string_view description); /** * Get the Mod of the current mod being developed diff --git a/loader/include/Geode/loader/SettingV3.hpp b/loader/include/Geode/loader/SettingV3.hpp index 9f83cf1fc..479a93bde 100644 --- a/loader/include/Geode/loader/SettingV3.hpp +++ b/loader/include/Geode/loader/SettingV3.hpp @@ -150,6 +150,14 @@ namespace geode { * Get the description of this setting */ std::optional getDescription() const; + /** + * Set the display name of this setting + */ + void setDisplayName(std::string_view name); + /** + * Set the description of this setting + */ + void setDescription(std::string_view desc); /** * Get the "enable-if" scheme for this setting */ diff --git a/loader/src/loader/Mod.cpp b/loader/src/loader/Mod.cpp index 986c20f3a..58286a550 100644 --- a/loader/src/loader/Mod.cpp +++ b/loader/src/loader/Mod.cpp @@ -163,6 +163,18 @@ std::shared_ptr Mod::getSetting(std::string_view key) const { return m_impl->m_settings->get(std::string(key)); } +void Mod::setSettingName(std::string_view key, std::string_view name) { + if (auto setting = getSetting(key)) { + setting->setDisplayName(name); + } +} + +void Mod::setSettingDescription(std::string_view key, std::string_view desc) { + if (auto setting = getSetting(key)) { + setting->setDescription(desc); + } +} + Result<> Mod::registerCustomSettingType(std::string_view type, SettingGenerator generator) { return m_impl->m_settings->registerCustomSettingType(type, generator); } diff --git a/loader/src/loader/SettingV3.cpp b/loader/src/loader/SettingV3.cpp index 00ef688b5..55c129af4 100644 --- a/loader/src/loader/SettingV3.cpp +++ b/loader/src/loader/SettingV3.cpp @@ -585,6 +585,12 @@ std::string SettingV3::getDisplayName() const { std::optional SettingV3::getDescription() const { return m_impl->description; } +void SettingV3::setDisplayName(std::string_view name) { + m_impl->name = name; +} +void SettingV3::setDescription(std::string_view description) { + m_impl->description = description; +} std::optional SettingV3::getEnableIf() const { return m_impl->enableIf; }