From 4a743cb1e1dceb002c9da5da42d4f8bd29f55328 Mon Sep 17 00:00:00 2001 From: Kai Date: Fri, 31 Jan 2025 11:52:42 +0100 Subject: [PATCH] feat: :sparkles: added custom validation option --- addons/mod_loader/mod_loader_store.gd | 3 ++ addons/mod_loader/resources/mod_manifest.gd | 8 ++- .../mod_loader/resources/options_profile.gd | 49 +++++++++++++++++-- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/addons/mod_loader/mod_loader_store.gd b/addons/mod_loader/mod_loader_store.gd index f9fc89fe..78bb84f2 100644 --- a/addons/mod_loader/mod_loader_store.gd +++ b/addons/mod_loader/mod_loader_store.gd @@ -177,6 +177,9 @@ func _update_ml_options_from_options_resource() -> void: # Update from the options in the resource ml_options = override_options + if not ml_options.customize_script_path.is_empty(): + ml_options.customize_script_instance = load(ml_options.customize_script_path).new(self) + func _exit_tree() -> void: # Save the cache to the cache file. diff --git a/addons/mod_loader/resources/mod_manifest.gd b/addons/mod_loader/resources/mod_manifest.gd index fc98b6aa..8105a41c 100644 --- a/addons/mod_loader/resources/mod_manifest.gd +++ b/addons/mod_loader/resources/mod_manifest.gd @@ -114,7 +114,13 @@ func validate(manifest: Dictionary, path: String) -> bool: steam_workshop_id = ModLoaderUtils.get_string_from_dict(godot_details, "steam_workshop_id") if not ModLoaderStore.ml_options.disable_game_version_validation: - _is_game_version_compatible(mod_id) + if ModLoaderStore.ml_options.custom_game_version_validation: + if ModLoaderStore.ml_options.custom_game_version_validation_callable: + ModLoaderStore.ml_options.custom_game_version_validation_callable.call(self) + else: + ModLoaderLog.error("No custom game version validation callable detected. Please provide a valid validation callable.", LOG_NAME) + else: + _is_game_version_compatible(mod_id) is_mod_id_array_valid(mod_id, dependencies, "dependency") is_mod_id_array_valid(mod_id, incompatibilities, "incompatibility") diff --git a/addons/mod_loader/resources/options_profile.gd b/addons/mod_loader/resources/options_profile.gd index ce3c92a0..3a03f65f 100644 --- a/addons/mod_loader/resources/options_profile.gd +++ b/addons/mod_loader/resources/options_profile.gd @@ -6,7 +6,7 @@ extends Resource @export var enable_mods: bool = true ## List of mod ids that can't be turned on or off @export var locked_mods: Array[String] = [] - +## List of mods that will not be loaded @export var disabled_mods: Array[String] = [] ## Disables the requirement for the mod loader autoloads to be first @export var allow_modloader_autoloads_anywhere: bool = false @@ -63,6 +63,49 @@ extends Resource @export var disable_restart := false @export_group("Mod Validation") -## Activate this option to disable validation of the game version specified in [member semantic_version] -## and the mod's [member ModManifest.compatible_game_version]. +## Activate this option to disable validation of the game version specified in [member semantic_version] +## and the mod's [member ModManifest.compatible_game_version]. @export var disable_game_version_validation := false +## Activate this option to use a custom game version validation, use the [member customize_script_path] +## to specify a script to customize the Mod Loader Options. In this script you have to set [member custom_game_version_validation_callable] +## with a custom validation [Callable]. +## +##[codeblock] +##extends RefCounted +## +## +##func _init(mod_loader_store: ModLoaderStore) -> void: +## mod_loader_store.ml_options.custom_game_version_validation_callable = custom_is_game_version_compatible +## +## +##func custom_is_game_version_compatible(manifest: ModManifest) -> bool: +## print("! ☞゚ヮ゚)☞ CUSTOM VALIDATION HERE ☜゚ヮ゚☜) !") +## +## var mod_id := manifest.get_mod_id() +## +## for version in manifest.compatible_game_version: +## if not version == "pizza": +## manifest.validation_messages_warning.push_back( +## "The mod \"%s\" may not be compatible with the current game version. +## Enable at your own risk. (current game version: %s, mod compatible with game versions: %s)" % +## [mod_id, MyGlobalVars.MyGameVersion, manifest.compatible_game_version] +## ) +## return false +## +## return true +##[/codeblock] +## +## Using the customization script allows you to place your custom code outside of the addon directory to simplify mod loader updates. +## +@export var custom_game_version_validation := false +## This is the callable that is called during [ModManifest] validation. +## See the example at [member disable_game_version_validation] to learn how to set this. +var custom_game_version_validation_callable: Callable +## Use this to specify a script to customize mod loader options. +## Can be used to set custom options properties. +## The customize_script is initialized with the [ModLoaderStore] as the first and only argument. +## See [member disable_game_version_validation] for an example on how to use it. +@export_file var customize_script_path: String + +## This is where the instance of [member customize_script_path] is stored. +var customize_script_instance: RefCounted