Skip to content

Commit 60d4f3a

Browse files
authored
refactor: ♻️ move consts from ModLoader to ModLoaderStore (#233)
* refactor: ♻️ move `const`s from `ModLoader` to ModLoaderStore` * feat: ✨ Add `get_unpacked_dir()` to `ModLoaderMod` * refactor: ♻️ added deprecation warning for `UNPACKED_DIR`
1 parent 5fc7268 commit 60d4f3a

File tree

5 files changed

+41
-29
lines changed

5 files changed

+41
-29
lines changed

addons/mod_loader/api/mod.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ static func save_scene(modified_scene: Node, scene_path: String) -> void:
9494
packed_scene.take_over_path(scene_path)
9595
ModLoaderLog.debug("save_scene - taking over path - new path -> %s" % packed_scene.resource_path, LOG_NAME)
9696
ModLoaderStore.saved_objects.append(packed_scene)
97+
98+
99+
static func get_unpacked_dir() -> String:
100+
return _ModLoaderPath.get_unpacked_mods_dir_path()

addons/mod_loader/internal/path.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ static func get_path_to_mods() -> String:
114114
return mods_folder_path
115115

116116

117+
static func get_unpacked_mods_dir_path() -> String:
118+
return ModLoaderStore.UNPACKED_DIR
119+
117120
# Get the path to the configs folder, with any applicable overrides applied
118121
static func get_path_to_configs() -> String:
119122
var configs_path := MOD_CONFIG_DIR_PATH

addons/mod_loader/internal/script_extension.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const LOG_NAME := "ModLoader:ScriptExtension"
1111
# Couple the extension paths with the parent paths and the extension's mod id
1212
# in a ScriptExtensionData resource
1313
# We need to pass the UNPACKED_DIR constant because the global ModLoader is not available during _init().
14-
static func handle_script_extensions(UNPACKED_DIR: String) -> void:
14+
static func handle_script_extensions() -> void:
1515
var script_extension_data_array := []
1616
for extension_path in ModLoaderStore.script_extensions:
1717

@@ -21,7 +21,7 @@ static func handle_script_extensions(UNPACKED_DIR: String) -> void:
2121

2222
var child_script = ResourceLoader.load(extension_path)
2323

24-
var mod_id: String = extension_path.trim_prefix(UNPACKED_DIR).get_slice("/", 0)
24+
var mod_id: String = extension_path.trim_prefix(ModLoaderStore.UNPACKED_DIR).get_slice("/", 0)
2525

2626
var parent_script: Script = child_script.get_base_script()
2727
var parent_script_path: String = parent_script.resource_path

addons/mod_loader/mod_loader.gd

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,20 @@ extends Node
2222

2323
signal logged(entry)
2424

25-
# Config
26-
# =============================================================================
27-
28-
# Most of these settings should never need to change, aside from the DEBUG_*
29-
# options (which should be `false` when distributing compiled PCKs)
30-
31-
const MODLOADER_VERSION = "5.0.1"
32-
33-
# If true, a complete array of filepaths is stored for each mod. This is
34-
# disabled by default because the operation can be very expensive, but may
35-
# be useful for debugging
36-
const DEBUG_ENABLE_STORING_FILEPATHS := false
37-
38-
# This is where mod ZIPs are unpacked to
39-
const UNPACKED_DIR := "res://mods-unpacked/"
40-
41-
42-
# Set to true to require using "--enable-mods" to enable them
43-
const REQUIRE_CMD_LINE := false
44-
4525
# Prefix for this file when using mod_log or dev_log
4626
const LOG_NAME := "ModLoader"
4727

28+
# --- DEPRECATED ---
29+
# UNPACKED_DIR was moved to ModLoaderStore.
30+
# However, many Brotato mods use this const directly, which is why the deprecation warning was added.
31+
var UNPACKED_DIR := "res://mods-unpacked/" setget ,deprecated_direct_access_UNPACKED_DIR
4832

4933
# Main
5034
# =============================================================================
5135

5236
func _init() -> void:
5337
# if mods are not enabled - don't load mods
54-
if REQUIRE_CMD_LINE and not _ModLoaderCLI.is_running_with_command_line_arg("--enable-mods"):
38+
if ModLoaderStore.REQUIRE_CMD_LINE and not _ModLoaderCLI.is_running_with_command_line_arg("--enable-mods"):
5539
return
5640

5741
# Rotate the log files once on startup. Can't be checked in utils, since it's static
@@ -170,7 +154,7 @@ func _load_mods() -> void:
170154

171155
ModLoaderLog.success("DONE: Completely finished loading mods", LOG_NAME)
172156

173-
_ModLoaderScriptExtension.handle_script_extensions(UNPACKED_DIR)
157+
_ModLoaderScriptExtension.handle_script_extensions()
174158

175159
ModLoaderLog.success("DONE: Installed all script extensions", LOG_NAME)
176160

@@ -271,8 +255,8 @@ func _load_zips_in_folder(folder_path: String) -> int:
271255
if OS.has_feature("editor") and not ModLoaderStore.has_shown_editor_zips_warning:
272256
ModLoaderLog.warning(str(
273257
"Loading any resource packs (.zip/.pck) with `load_resource_pack` will WIPE the entire virtual res:// directory. ",
274-
"If you have any unpacked mods in ", UNPACKED_DIR, ", they will not be loaded. ",
275-
"Please unpack your mod ZIPs instead, and add them to ", UNPACKED_DIR), LOG_NAME)
258+
"If you have any unpacked mods in ", ModLoaderStore.UNPACKED_DIR, ", they will not be loaded. ",
259+
"Please unpack your mod ZIPs instead, and add them to ", ModLoaderStore.UNPACKED_DIR), LOG_NAME)
276260
ModLoaderStore.has_shown_editor_zips_warning = true
277261

278262
ModLoaderLog.debug("Found mod ZIP: %s" % mod_folder_global_path, LOG_NAME)
@@ -339,7 +323,7 @@ func _load_steam_workshop_zips() -> int:
339323
# which adds their data to mod_data.
340324
func _setup_mods() -> int:
341325
# Path to the unpacked mods folder
342-
var unpacked_mods_path := UNPACKED_DIR
326+
var unpacked_mods_path := ModLoaderStore.UNPACKED_DIR
343327

344328
var dir := Directory.new()
345329
if not dir.open(unpacked_mods_path) == OK:
@@ -429,7 +413,7 @@ func _init_mod_data(mod_folder_path: String) -> void:
429413
var dir_name := _ModLoaderPath.get_file_name_from_path(mod_folder_path, false, true)
430414

431415
# Path to the mod in UNPACKED_DIR (eg "res://mods-unpacked/My-Mod")
432-
var local_mod_path := UNPACKED_DIR.plus_file(dir_name)
416+
var local_mod_path := ModLoaderStore.UNPACKED_DIR.plus_file(dir_name)
433417

434418
var mod := ModData.new(local_mod_path)
435419
mod.dir_name = dir_name
@@ -443,7 +427,7 @@ func _init_mod_data(mod_folder_path: String) -> void:
443427
# not needed anymore. It can be useful when debugging, but it's also an expensive
444428
# operation if a mod has a large number of files (eg. Brotato's Invasion mod,
445429
# which has ~1,000 files). That's why it's disabled by default
446-
if DEBUG_ENABLE_STORING_FILEPATHS:
430+
if ModLoaderStore.DEBUG_ENABLE_STORING_FILEPATHS:
447431
mod.file_paths = _ModLoaderPath.get_flat_view_dict(local_mod_path)
448432

449433

@@ -502,3 +486,8 @@ func save_scene(modified_scene: Node, scene_path: String) -> void:
502486
func get_mod_config(mod_dir_name: String = "", key: String = "") -> Dictionary:
503487
ModLoaderDeprecated.deprecated_changed("ModLoader.get_mod_config", "ModLoaderConfig.get_mod_config", "6.0.0")
504488
return ModLoaderConfig.get_mod_config(mod_dir_name, key)
489+
490+
491+
func deprecated_direct_access_UNPACKED_DIR() -> String:
492+
ModLoaderDeprecated.deprecated_message("The const \"UNPACKED_DIR\" was removed, use \"ModLoaderMod.get_unpacked_dir()\" instead", "6.0.0")
493+
return _ModLoaderPath.get_unpacked_mods_dir_path()

addons/mod_loader/mod_loader_store.gd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ extends Node
99
# Constants
1010
# =============================================================================
1111

12+
# Most of these settings should never need to change, aside from the DEBUG_*
13+
# options (which should be `false` when distributing compiled PCKs)
14+
15+
const MODLOADER_VERSION = "5.0.1"
16+
17+
# If true, a complete array of filepaths is stored for each mod. This is
18+
# disabled by default because the operation can be very expensive, but may
19+
# be useful for debugging
20+
const DEBUG_ENABLE_STORING_FILEPATHS := false
21+
22+
# This is where mod ZIPs are unpacked to
23+
const UNPACKED_DIR := "res://mods-unpacked/"
24+
25+
# Set to true to require using "--enable-mods" to enable them
26+
const REQUIRE_CMD_LINE := false
27+
1228
const LOG_NAME = "ModLoader:Store"
1329

1430
# Vars

0 commit comments

Comments
 (0)