Skip to content

Commit 63723f2

Browse files
authored
feat: ✨ store the mod source in ModData (#387)
* feat: ✨ store the mod source in `ModData` Added the `sources` enum to `ModData`. Added the `set_mod_source(path: String)` function to `ModData`. Updated `_init_mod_data()` in `ModLoader` to set the mod source. * style: 🎨 indentation * refactor: ♻️ change `set_mod_source` to `get_mod_source`
1 parent 7a9deb5 commit 63723f2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

addons/mod_loader/mod_loader.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,18 +293,20 @@ func _setup_mods() -> int:
293293
# The mod_folder_path is just the folder name that was added to UNPACKED_DIR,
294294
# which depends on the name used in a given mod ZIP (eg "mods-unpacked/Folder-Name")
295295
func _init_mod_data(mod_id: String, zip_path := "") -> void:
296-
# Path to the mod in UNPACKED_DIR (eg "res://mods-unpacked/My-Mod")
296+
# Path to the mod in UNPACKED_DIR (eg "res://mods-unpacked/My-Mod")
297297
var local_mod_path := _ModLoaderPath.get_unpacked_mods_dir_path().path_join(mod_id)
298298

299299
var mod := ModData.new()
300300
if not zip_path.is_empty():
301301
mod.zip_name = _ModLoaderPath.get_file_name_from_path(zip_path)
302302
mod.zip_path = zip_path
303+
mod.source = mod.get_mod_source()
303304
mod.dir_path = local_mod_path
304305
mod.dir_name = mod_id
305306
var mod_overwrites_path := mod.get_optional_mod_file_path(ModData.optional_mod_files.OVERWRITES)
306307
mod.is_overwrite = _ModLoaderFile.file_exists(mod_overwrites_path)
307308
mod.is_locked = true if mod_id in ModLoaderStore.ml_options.locked_mods else false
309+
308310
ModLoaderStore.mod_data[mod_id] = mod
309311

310312
# Get the mod file paths

addons/mod_loader/resources/mod_data.gd

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ enum optional_mod_files {
2323
OVERWRITES
2424
}
2525

26+
# Specifies the source from which the mod has been loaded:
27+
# UNPACKED = From the mods-unpacked directory ( only when in the editor ).
28+
# LOCAL = From the local mod zip directory, which by default is ../game_dir/mods.
29+
# STEAM_WORKSHOP = Loaded from ../Steam/steamapps/workshop/content/1234567/[..].
30+
enum sources {
31+
UNPACKED,
32+
LOCAL,
33+
STEAM_WORKSHOP,
34+
}
35+
2636
# Name of the Mod's zip file
2737
var zip_name := ""
2838
# Path to the Mod's zip file
@@ -47,6 +57,8 @@ var manifest: ModManifest
4757
# Updated in load_configs
4858
var configs := {}
4959
var current_config: ModConfig: set = _set_current_config
60+
# Specifies the source from which the mod has been loaded
61+
var source: int
5062

5163
# only set if DEBUG_ENABLE_STORING_FILEPATHS is enabled
5264
var file_paths: PackedStringArray = []
@@ -154,8 +166,18 @@ func get_required_mod_file_path(required_file: int) -> String:
154166
return dir_path.path_join("manifest.json")
155167
return ""
156168

169+
157170
func get_optional_mod_file_path(optional_file: int) -> String:
158171
match optional_file:
159172
optional_mod_files.OVERWRITES:
160173
return dir_path.path_join("overwrites.gd")
161174
return ""
175+
176+
177+
func get_mod_source() -> sources:
178+
if zip_path.contains("workshop"):
179+
return sources.STEAM_WORKSHOP
180+
if zip_path == "":
181+
return sources.UNPACKED
182+
183+
return sources.LOCAL

0 commit comments

Comments
 (0)