Skip to content

Commit 5698a12

Browse files
authored
feat: ✨ added load_from_unpacked option (#541)
* feat: ✨ added `load_from_unpacked` option * fix: 🐛 if not is_zip * refactor: ♻️ moved `load_from_unpacked` check to `_ModLoaderPath.get_mod_paths_from_all_sources()`
1 parent 10d048d commit 5698a12

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

addons/mod_loader/internal/path.gd

+5-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ static func get_mod_paths_from_all_sources() -> Array[String]:
194194
var mod_paths: Array[String] = []
195195

196196
var mod_dirs := get_dir_paths_in_dir(get_unpacked_mods_dir_path())
197-
mod_paths.append_array(mod_dirs)
197+
198+
if ModLoaderStore.has_feature.editor or ModLoaderStore.ml_options.load_from_unpacked:
199+
mod_paths.append_array(mod_dirs)
200+
else:
201+
ModLoaderLog.info("Loading mods from \"res://mods-unpacked\" is disabled.", LOG_NAME)
198202

199203
if ModLoaderStore.ml_options.load_from_local:
200204
var mods_dir := get_path_to_mods()

addons/mod_loader/mod_loader.gd

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ signal new_hooks_created
3030

3131
const LOG_NAME := "ModLoader"
3232

33-
var is_in_editor := OS.has_feature("editor")
34-
3533

3634
func _init() -> void:
3735
# if mods are not enabled - don't load mods
@@ -41,7 +39,7 @@ func _init() -> void:
4139
# Only load the hook pack if not in the editor
4240
# We can't use it in the editor - see https://github.com/godotengine/godot/issues/19815
4341
# Mod devs can use the Dev Tool to generate hooks in the editor.
44-
if not is_in_editor and _ModLoaderFile.file_exists(_ModLoaderPath.get_path_to_hook_pack()):
42+
if not ModLoaderStore.has_feature.editor and _ModLoaderFile.file_exists(_ModLoaderPath.get_path_to_hook_pack()):
4543
_load_mod_hooks_pack()
4644

4745
# Rotate the log files once on startup.
@@ -119,7 +117,7 @@ func _init() -> void:
119117
# "don't use ZIPs with unpacked mods!"
120118
# https://github.com/godotengine/godot/issues/19815
121119
# https://github.com/godotengine/godot/issues/16798
122-
if is_in_editor:
120+
if ModLoaderStore.has_feature.editor:
123121
ModLoaderLog.hint(
124122
"Loading any resource packs (.zip/.pck) with `load_resource_pack` will WIPE the entire virtual res:// directory. " +
125123
"If you have any unpacked mods in %s, they will not be loaded.Please unpack your mod ZIPs instead, and add them to %s" %

addons/mod_loader/mod_loader_store.gd

+3
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ var cache := {}
111111
# See: res://addons/mod_loader/resources/options_profile.gd
112112
var ml_options: ModLoaderOptionsProfile
113113

114+
var has_feature := {
115+
"editor" = OS.has_feature("editor")
116+
}
114117

115118
# Methods
116119
# =============================================================================

addons/mod_loader/resources/options_profile.gd

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ enum VERSION_VALIDATION {
7474
@export var load_from_steam_workshop: bool = false
7575
## Indicates whether to load mods from the "mods" folder located at the game's install directory, or the overridden mods path.
7676
@export var load_from_local: bool = true
77+
## Indicates whether to load mods from [code]"res://mods-unpacked"[/code] in the exported game.[br]
78+
## ===[br]
79+
## [b]Note:[color=note "Load from unpacked in the editor"][/color][/b][br]
80+
## In the editor, mods inside [code]"res://mods-unpacked"[/code] are always loaded. Use [member enable_mods] to disable mod loading completely.[br]
81+
## ===[br]
82+
@export var load_from_unpacked: bool = true
7783
## Path to a folder containing mods [br]
7884
## Mod zips should be directly in this folder
7985
@export_dir var override_path_to_mods = ""

0 commit comments

Comments
 (0)