From da9209010846847195ea8e2faa67fd41462842a3 Mon Sep 17 00:00:00 2001 From: matcool <26722564+matcool@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:42:52 -0300 Subject: [PATCH] change ModSettingsManager::save return type --- loader/include/Geode/loader/ModSettingsManager.hpp | 6 +----- loader/src/loader/ModImpl.cpp | 3 +-- loader/src/loader/ModSettingsManager.cpp | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/loader/include/Geode/loader/ModSettingsManager.hpp b/loader/include/Geode/loader/ModSettingsManager.hpp index 6f5db523..296b34bf 100644 --- a/loader/include/Geode/loader/ModSettingsManager.hpp +++ b/loader/include/Geode/loader/ModSettingsManager.hpp @@ -40,12 +40,8 @@ namespace geode { * The format of the savedata will be an object with the keys being * setting IDs and then the values the values of the saved settings * @note If saving a setting fails, it will log a warning to the console - * @warning This will overwrite the whole `json` parameter - be sure to - * pass the full settings savedata to `load()` so you can be sure that - * unregistered custom settings' saved values don't disappear! - * @todo in v4: make this return the value instead lol */ - void save(matjson::Value& json); + matjson::Value save(); /** * Get the savedata for settings, aka the JSON object that contains all diff --git a/loader/src/loader/ModImpl.cpp b/loader/src/loader/ModImpl.cpp index acd09801..f8e71ccf 100644 --- a/loader/src/loader/ModImpl.cpp +++ b/loader/src/loader/ModImpl.cpp @@ -210,8 +210,7 @@ Result<> Mod::Impl::saveData() { } // ModSettingsManager keeps track of the whole savedata - matjson::Value json; - m_settings->save(json); + matjson::Value json = m_settings->save(); // saveData is expected to be synchronous, and always called from GD thread ModStateEvent(m_self, ModEventType::DataSaved).post(); diff --git a/loader/src/loader/ModSettingsManager.cpp b/loader/src/loader/ModSettingsManager.cpp index 1ab4fb9e..d18b664e 100644 --- a/loader/src/loader/ModSettingsManager.cpp +++ b/loader/src/loader/ModSettingsManager.cpp @@ -214,12 +214,12 @@ Result<> ModSettingsManager::load(matjson::Value const& json) { } return Ok(); } -void ModSettingsManager::save(matjson::Value& json) { +matjson::Value ModSettingsManager::save() { for (auto& [key, _] : m_impl->settings) { m_impl->saveSettingValueToSave(key); } // Doing this since `ModSettingsManager` is expected to manage savedata fully - json = m_impl->savedata; + return m_impl->savedata; } matjson::Value& ModSettingsManager::getSaveData() { return m_impl->savedata;