Skip to content

Commit 4a743cb

Browse files
committed
feat: ✨ added custom validation option
1 parent 692652c commit 4a743cb

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

addons/mod_loader/mod_loader_store.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func _update_ml_options_from_options_resource() -> void:
177177
# Update from the options in the resource
178178
ml_options = override_options
179179

180+
if not ml_options.customize_script_path.is_empty():
181+
ml_options.customize_script_instance = load(ml_options.customize_script_path).new(self)
182+
180183

181184
func _exit_tree() -> void:
182185
# Save the cache to the cache file.

addons/mod_loader/resources/mod_manifest.gd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ func validate(manifest: Dictionary, path: String) -> bool:
114114
steam_workshop_id = ModLoaderUtils.get_string_from_dict(godot_details, "steam_workshop_id")
115115

116116
if not ModLoaderStore.ml_options.disable_game_version_validation:
117-
_is_game_version_compatible(mod_id)
117+
if ModLoaderStore.ml_options.custom_game_version_validation:
118+
if ModLoaderStore.ml_options.custom_game_version_validation_callable:
119+
ModLoaderStore.ml_options.custom_game_version_validation_callable.call(self)
120+
else:
121+
ModLoaderLog.error("No custom game version validation callable detected. Please provide a valid validation callable.", LOG_NAME)
122+
else:
123+
_is_game_version_compatible(mod_id)
118124

119125
is_mod_id_array_valid(mod_id, dependencies, "dependency")
120126
is_mod_id_array_valid(mod_id, incompatibilities, "incompatibility")

addons/mod_loader/resources/options_profile.gd

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extends Resource
66
@export var enable_mods: bool = true
77
## List of mod ids that can't be turned on or off
88
@export var locked_mods: Array[String] = []
9-
9+
## List of mods that will not be loaded
1010
@export var disabled_mods: Array[String] = []
1111
## Disables the requirement for the mod loader autoloads to be first
1212
@export var allow_modloader_autoloads_anywhere: bool = false
@@ -63,6 +63,49 @@ extends Resource
6363
@export var disable_restart := false
6464

6565
@export_group("Mod Validation")
66-
## Activate this option to disable validation of the game version specified in [member semantic_version]
67-
## and the mod's [member ModManifest.compatible_game_version].
66+
## Activate this option to disable validation of the game version specified in [member semantic_version]
67+
## and the mod's [member ModManifest.compatible_game_version].
6868
@export var disable_game_version_validation := false
69+
## Activate this option to use a custom game version validation, use the [member customize_script_path]
70+
## to specify a script to customize the Mod Loader Options. In this script you have to set [member custom_game_version_validation_callable]
71+
## with a custom validation [Callable].
72+
##
73+
##[codeblock]
74+
##extends RefCounted
75+
##
76+
##
77+
##func _init(mod_loader_store: ModLoaderStore) -> void:
78+
## mod_loader_store.ml_options.custom_game_version_validation_callable = custom_is_game_version_compatible
79+
##
80+
##
81+
##func custom_is_game_version_compatible(manifest: ModManifest) -> bool:
82+
## print("! ☞゚ヮ゚)☞ CUSTOM VALIDATION HERE ☜゚ヮ゚☜) !")
83+
##
84+
## var mod_id := manifest.get_mod_id()
85+
##
86+
## for version in manifest.compatible_game_version:
87+
## if not version == "pizza":
88+
## manifest.validation_messages_warning.push_back(
89+
## "The mod \"%s\" may not be compatible with the current game version.
90+
## Enable at your own risk. (current game version: %s, mod compatible with game versions: %s)" %
91+
## [mod_id, MyGlobalVars.MyGameVersion, manifest.compatible_game_version]
92+
## )
93+
## return false
94+
##
95+
## return true
96+
##[/codeblock]
97+
##
98+
## Using the customization script allows you to place your custom code outside of the addon directory to simplify mod loader updates.
99+
##
100+
@export var custom_game_version_validation := false
101+
## This is the callable that is called during [ModManifest] validation.
102+
## See the example at [member disable_game_version_validation] to learn how to set this.
103+
var custom_game_version_validation_callable: Callable
104+
## Use this to specify a script to customize mod loader options.
105+
## Can be used to set custom options properties.
106+
## The customize_script is initialized with the [ModLoaderStore] as the first and only argument.
107+
## See [member disable_game_version_validation] for an example on how to use it.
108+
@export_file var customize_script_path: String
109+
110+
## This is where the instance of [member customize_script_path] is stored.
111+
var customize_script_instance: RefCounted

0 commit comments

Comments
 (0)