change ModSettingsManager::save return type

This commit is contained in:
matcool 2024-11-15 14:42:52 -03:00
parent 64d9a289a3
commit da92090108
3 changed files with 4 additions and 9 deletions

View file

@ -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

View file

@ -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();

View file

@ -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;