From e3770d32ad7775665867af43edd161ed377fc0fa Mon Sep 17 00:00:00 2001 From: KANAjetzt <41547570+KANAjetzt@users.noreply.github.com> Date: Fri, 31 Oct 2025 21:28:35 +0100 Subject: [PATCH 1/4] feat: :sparkles: update_config_value --- addons/mod_loader/api/config.gd | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/addons/mod_loader/api/config.gd b/addons/mod_loader/api/config.gd index 83e59304..89f9ca0e 100644 --- a/addons/mod_loader/api/config.gd +++ b/addons/mod_loader/api/config.gd @@ -101,6 +101,31 @@ static func update_config(config: ModConfig) -> ModConfig: return config +# Updates an existing ModConfig object with new data and save the config file. +# +# Parameters: +# - config (ModConfig): The ModConfig object to be updated. +# - key (String): The key of the value that should be updated. +# - new_data (Variant): The data that should be stored +# +# Returns: +# - ModConfig: The updated ModConfig object if successful, or null otherwise. +static func update_config_value(config: ModConfig, key: String, new_data) -> ModConfig: + var config_data := config.data + + if not config_data.has(key): + ModLoaderLog.error("Update config value failed for \"%s\". No key \"%s\" found." % [config.name ,key]) + return null + + if not typeof(config_data[key]) == typeof(new_data): + ModLoaderLog.error("Update config value failed for \"%s\". There is a type mismatch between existing and new_data." [config.name]) + return null + + config.data[key] = new_data + + return update_config(config) + + # Deletes a ModConfig object and performs cleanup operations. # # Parameters: From c5e8336262492d860d60db066196c1e033de721d Mon Sep 17 00:00:00 2001 From: KANAjetzt <41547570+KANAjetzt@users.noreply.github.com> Date: Fri, 31 Oct 2025 21:31:47 +0100 Subject: [PATCH 2/4] fix: :bug: added missing `LOG_NAME` --- addons/mod_loader/api/config.gd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mod_loader/api/config.gd b/addons/mod_loader/api/config.gd index 89f9ca0e..95f4f764 100644 --- a/addons/mod_loader/api/config.gd +++ b/addons/mod_loader/api/config.gd @@ -114,11 +114,11 @@ static func update_config_value(config: ModConfig, key: String, new_data) -> Mod var config_data := config.data if not config_data.has(key): - ModLoaderLog.error("Update config value failed for \"%s\". No key \"%s\" found." % [config.name ,key]) + ModLoaderLog.error("Update config value failed for \"%s\". No key \"%s\" found." % [config.name ,key], LOG_NAME) return null if not typeof(config_data[key]) == typeof(new_data): - ModLoaderLog.error("Update config value failed for \"%s\". There is a type mismatch between existing and new_data." [config.name]) + ModLoaderLog.error("Update config value failed for \"%s\". There is a type mismatch between existing and new_data." [config.name], LOG_NAME) return null config.data[key] = new_data From 9a672fbc5f7f5c2a68be36819caf2d650f096750 Mon Sep 17 00:00:00 2001 From: KANAjetzt <41547570+KANAjetzt@users.noreply.github.com> Date: Fri, 31 Oct 2025 21:34:33 +0100 Subject: [PATCH 3/4] fix: :bug: missing `%` --- addons/mod_loader/api/config.gd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mod_loader/api/config.gd b/addons/mod_loader/api/config.gd index 95f4f764..6aa00c07 100644 --- a/addons/mod_loader/api/config.gd +++ b/addons/mod_loader/api/config.gd @@ -118,7 +118,7 @@ static func update_config_value(config: ModConfig, key: String, new_data) -> Mod return null if not typeof(config_data[key]) == typeof(new_data): - ModLoaderLog.error("Update config value failed for \"%s\". There is a type mismatch between existing and new_data." [config.name], LOG_NAME) + ModLoaderLog.error("Update config value failed for \"%s\". There is a type mismatch between existing and new_data." % [config.name], LOG_NAME) return null config.data[key] = new_data From 1d2d2466d6a71c9211ff218be519c2afb1856bb0 Mon Sep 17 00:00:00 2001 From: KANAjetzt <41547570+KANAjetzt@users.noreply.github.com> Date: Fri, 31 Oct 2025 22:08:55 +0100 Subject: [PATCH 4/4] refactor: :recycle: let the `update_config` func handle all validation --- addons/mod_loader/api/config.gd | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/addons/mod_loader/api/config.gd b/addons/mod_loader/api/config.gd index 6aa00c07..f2484f20 100644 --- a/addons/mod_loader/api/config.gd +++ b/addons/mod_loader/api/config.gd @@ -111,18 +111,7 @@ static func update_config(config: ModConfig) -> ModConfig: # Returns: # - ModConfig: The updated ModConfig object if successful, or null otherwise. static func update_config_value(config: ModConfig, key: String, new_data) -> ModConfig: - var config_data := config.data - - if not config_data.has(key): - ModLoaderLog.error("Update config value failed for \"%s\". No key \"%s\" found." % [config.name ,key], LOG_NAME) - return null - - if not typeof(config_data[key]) == typeof(new_data): - ModLoaderLog.error("Update config value failed for \"%s\". There is a type mismatch between existing and new_data." % [config.name], LOG_NAME) - return null - config.data[key] = new_data - return update_config(config)