Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Mod Config: Add API method to store a config value #489

Open
KANAjetzt opened this issue Dec 14, 2024 · 0 comments
Open

Mod Config: Add API method to store a config value #489

KANAjetzt opened this issue Dec 14, 2024 · 0 comments
Labels
3.x 4.x enhancement New feature or request
Milestone

Comments

@KANAjetzt
Copy link
Member

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.

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

@KANAjetzt KANAjetzt added enhancement New feature or request 4.x 3.x labels Dec 14, 2024
@KANAjetzt KANAjetzt added this to the 4.x - 7.x milestone Dec 14, 2024
@KANAjetzt KANAjetzt changed the title Mod Configs: Add API method to store a config value Mod Config: Add API method to store a config value Dec 14, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
3.x 4.x enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant