Skip to content

Commit a147471

Browse files
authored
feat: ✨ Advanced Mod Configs (#237)
* feat: ✨ Added `JSONConfigFile` addon as submodule * chore: 🔧 added `.gitmodules` to `.gitattributes` * refactor: ♻️ remove `JSONConfigFile` add `JSON_Schema_Validator` * chore: ⬆️ update JSON Schema Validator * feat: ✨ added `config_schema` to `ModManifest` With it `_handle_mod_config()` | `_get_config_default_data()` generates the `config_default`s from the `config_schema` default keys | `get_config_default_data_as_string()` | `get_config_schema_as_string()` | `is_config_valid()` validates the config based on the schema using the `JSON_Schema_Validator` Addon * feat: ✨ Save default conifg to File If there is no json file for this mod config yet * refactor: ♻️ load mod config after the manifest With this change, the config data of the `config_defaults` defined in the `config_schema` is available in the first run. * feat: ✨ added `get_dict_from_dict()` used in `ModManifest` to get `config_schema` * fix: 🐛 only `_handle_mod_config()` if there is a schema * refactor: ♻️ simplified `get_mod_config()` Only returning the full config data without the key parameter, as it only allowed retrieving top-level properties. | Removing the distinction between user config and default config. The default config is now generated based on the default key of the config_schema and saved to the mod config file. This ensures that there is always a user config. - To revert to the default config, simply delete the config JSON file. * refactor: 🚧 Adding `ModConfig` Resource * fix: 🚧 mod config loading remove `not` from if statement, and removed the call to the original `_load_mod_configs()` function * chore: 🐛 * feat: 🚧 wip: configs loading * feat: ✨ added `get_dir_paths_in_dir()` * feat: ✨ added `get_file_paths_in_dir()` * style: 🎨 added missing empty line * feat: ✨ imporved `ModConfig` added `name` and `Is_valid` prop | Added `_init()` function to validate on init. * refactor: ♻️ multiple entries per mod in `mod_list` Added `current_config` to `mod_list` if the mod has a config file * feat: ✨ added `get_mod_config_schema(mod_id: String)` * feat: ✨ Implemented `current_config` Reworked the config loading in *mod_manifest.gd* and *mod_data.gd* | The `current_config` for each mod is now stored in the user profiles. * refactor: ♻️ Renamed funcs | use a dict to store configs Removed `mod` from functions in `config.gd` to maintain uniformity with other functions within this class. | Configurations are now stored inside a dictionary instead of an array in `ModData`, where the key represents the config name. This change makes it much easier to access and locate the appropriate config based on its name. * feat: ✨ added `save_to_disc()` in `ModConfig` * feat: ✨ added `get_path_to_mod_configs()` added `get_path_to_mod_configs()` in `_ModLoaderPath` * feat: ✨ added `create_new_config()` * refactor: ♻️ `set_current_config()` param changed to ModConfig * feat: ✨ added `get_mods_with_config()` * feat: ✨ added `current_config_changed(config)` signal * feat: ✨ added `remove_file(file_path: String)` and added missing types * style: 🎨 renamed `create_new_config` -> `create_config` also reworked error messages * feat: ✨ added `delete_config()` * feat: ✨ added `get_default_config()` * feat: ✨ added `remove_from_disc()` * refactor: ♻️ changed `_schema` param in `_init()` default is an empty dictionary now, if empty the `config_schema` is retrieved from the `ModLoaderStore`. Otherwise, the provided schema in `_schema` is used. * feat: ✨ added `get_schema_for_prop()` * chore: ⬆️ updated JSON_Schema_Validator * refactor: ♻️ improved `schema_drill()` and renamed it to `_traverse_schema()` * feat: ✨ added `get_path_to_mod_config_file()` * style: ✏️ renamed `get_path_to_mod_configs()` to `get_path_to_mod_configs_dir()` * fix: 🐛 update `mod_list` when loading profile Fixed an error where the `current_config` specified in the `mod_list` of a user profile could point to a non-existent config if the config file was manually deleted. * fix: 🐛 Handle invalid `current_config` in a User Profile If the `current_config` in a user profile is set to an invalid configuration, it will now fallback to the default configuration. * refactor: ♻️ `create_config()` return `ModConfig` Instead of returning a success boolean, `create_config()` now returns a `ModConfig` resource if successful. * feat: ✨ added `update_config()` * refactor: ♻️ update `is_valid` in `validate()` * refactor: ♻️ updated `update_config(config: ModConfig)` Using the `save_to_disc()` method of `ModConfig` * refactor: ♻️ don't update config if `default` * refactor: ♻️ added `DEFAULT_CONFIG_NAME` added a const for the default config name * refactor: ♻️ load **all** mod config files Before, only valid configs were loaded into the `ModData`, which led to inconsistency between the stored config files and the configs in ModData. To prevent the need to check the file system all the time for existing configs, non-valid configs are now also added to the `ModData`. * refactor: ♻️ use `get_default_config()` * chore: ⬆️ updated `JSON_Schema_Validator` * style: 💡 improved comments * style: 💡 added more comments * style: 💡 comment improvements * style: 🎨 moved functions around * style: 💡 improved comments in *profile.gd* * fix: ✏️ fixed typo in comment * fix: 🐛 find and replace error * style: 💡 improved comments * refactor: ♻️ inverted booleans in `is_valid()` to make it more intuitive * style: 🎨 renamed disk -> file * style: ✏️ updated comment to match function name * refactor: 🔥 removed unused `get_dir_paths_in_dir()` * refactor: ♻️ only load configs if defaults are valid `load_mod_config_defaults()` is now called in `load_configs()` in `mod_data.gd` to allow skipping the config loading if the default values in the schema are invalid. Additionally, the `default.json` file is now validated, so the default config is regenerated if the schema has changed and the defaults are no longer valid. * feat: ✨ added `_ModLoaderCache` Implemented `_ModLoaderCache` to store the MD5s of the config schema in `"user://ModLoaderCache.json"`. This enables checking if the config schema has changed since the last start, allowing the regeneration of the default config only if a change is detected. * style: 💡 added func comments for `_ModLoaderCache` * refactor: ♻️ return cache data in `add_data()` to align with the other methods * refactor: ♻️ changed cache file name * fix: 🐛 handle non existing cache Fixed an error that occurred when the `default.json` config file existed, but the cache had been deleted.
1 parent 49464db commit a147471

File tree

14 files changed

+817
-218
lines changed

14 files changed

+817
-218
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Git stuff
22
/.gitattributes export-ignore
33
/.gitignore export-ignore
4+
/.gitmodules export-ignore
45
.github/ export-ignore
56
/README.md export-ignore
67
/CONTRIBUTING.md export-ignore

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "addons/JSONConfigFile"]
2+
path = addons/JSON_Schema_Validator
3+
url = https://github.com/GodotModding/JSON-Shema-validator.git

addons/JSON_Schema_Validator

Submodule JSON_Schema_Validator added at fdf1640

0 commit comments

Comments
 (0)