-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
Milestone
Description
Currently, the only way to update the config file is via ModLoaderConfig.update_config(). Adding a method to update a specific value within the config would be a nice quality-of-life improvement.
godot-mod-loader/addons/mod_loader/api/config.gd
Lines 72 to 101 in aab3aaa
| ## Updates an existing [ModConfig] object with new data and saves the config file.[br] | |
| ## [br] | |
| ## [b]Parameters:[/b][br] | |
| ## - [code]config[/code] ([ModConfig]): The [ModConfig] object to be updated.[br] | |
| ## [br] | |
| ## [b]Returns:[/b][br] | |
| ## - [ModConfig]: The updated [ModConfig] object if successful, or null otherwise. | |
| static func update_config(config: ModConfig) -> ModConfig: | |
| # Validate the config and check for any validation errors | |
| var error_message := config.validate() | |
| # Check if the config is the "default" config, which cannot be modified | |
| if config.name == DEFAULT_CONFIG_NAME: | |
| ModLoaderLog.error("The \"default\" config cannot be modified. Please create a new config instead.", LOG_NAME) | |
| return null | |
| # Check if the config passed validation | |
| if not config.is_valid: | |
| ModLoaderLog.error("Update for config \"%s\" failed validation with error message \"%s\"" % [config.name, error_message], LOG_NAME) | |
| return null | |
| # Save the updated config to the config file | |
| var is_save_success := config.save_to_file() | |
| if not is_save_success: | |
| ModLoaderLog.error("Failed to save config \"%s\" to \"%s\"." % [config.name, config.save_path], LOG_NAME) | |
| return null | |
| # Return the updated config | |
| return config |