@@ -81,20 +81,20 @@ var _saved_objects = []
81
81
82
82
func _init ():
83
83
# if mods are not enabled - don't load mods
84
- if REQUIRE_CMD_LINE && ( ! _check_cmd_line_arg ( "--enable-mods" ) ):
84
+ if REQUIRE_CMD_LINE and not ModLoaderUtils . is_running_with_command_line_arg ( "--enable-mods" ):
85
85
return
86
86
87
87
# Log game install dir
88
- ModLoaderUtils .log_info (str ( "game_install_directory: " , _get_local_folder_dir () ), LOG_NAME )
88
+ ModLoaderUtils .log_info ("game_install_directory: %s " % ModLoaderUtils . get_local_folder_dir ( ), LOG_NAME )
89
89
90
90
# check if we want to use a different mods path that is provided as a command line argument
91
- var cmd_line_mod_path = _get_cmd_line_arg ("--mods-path" )
91
+ var cmd_line_mod_path := ModLoaderUtils . get_cmd_line_arg_value ("--mods-path" )
92
92
if cmd_line_mod_path != "" :
93
93
os_mods_path_override = cmd_line_mod_path
94
94
ModLoaderUtils .log_info ("The path mods are loaded from has been changed via the CLI arg `--mods-path`, to: " + cmd_line_mod_path , LOG_NAME )
95
95
96
96
# Check for the CLI arg that overrides the configs path
97
- var cmd_line_configs_path = _get_cmd_line_arg ("--configs-path" )
97
+ var cmd_line_configs_path = ModLoaderUtils . get_cmd_line_arg_value ("--configs-path" )
98
98
if cmd_line_configs_path != "" :
99
99
os_configs_path_override = cmd_line_configs_path
100
100
ModLoaderUtils .log_info ("The path configs are loaded from has been changed via the CLI arg `--configs-path`, to: " + cmd_line_configs_path , LOG_NAME )
@@ -154,7 +154,7 @@ func _init():
154
154
# (UNPACKED_DIR)
155
155
func _load_mod_zips ():
156
156
# Path to the games mod folder
157
- var game_mod_folder_path = _get_local_folder_dir ("mods" )
157
+ var game_mod_folder_path = ModLoaderUtils . get_local_folder_dir ("mods" )
158
158
159
159
var dir = Directory .new ()
160
160
if dir .open (game_mod_folder_path ) != OK :
@@ -257,7 +257,7 @@ func _setup_mods():
257
257
# Load mod config JSONs from res://configs
258
258
func _load_mod_configs ():
259
259
var found_configs_count = 0
260
- var configs_path = _get_local_folder_dir ("configs" )
260
+ var configs_path = ModLoaderUtils . get_local_folder_dir ("configs" )
261
261
262
262
# CLI override, set with `--configs-path="C://path/configs"`
263
263
# (similar to os_mods_path_override)
@@ -266,7 +266,7 @@ func _load_mod_configs():
266
266
267
267
for dir_name in mod_data :
268
268
var json_path = configs_path .plus_file (dir_name + ".json" )
269
- var mod_config = ModData . _get_json_as_dict (json_path )
269
+ var mod_config = ModLoaderUtils . get_json_as_dict (json_path )
270
270
271
271
ModLoaderUtils .log_debug (str ("Config JSON: Looking for config at path: " , json_path ), LOG_NAME )
272
272
@@ -306,7 +306,7 @@ func _load_mod_configs():
306
306
# which depends on the name used in a given mod ZIP (eg "mods-unpacked/Folder-Name")
307
307
func _init_mod_data (mod_folder_path ):
308
308
# The file name should be a valid mod id
309
- var dir_name = _get_file_name (mod_folder_path , false , true )
309
+ var dir_name = ModLoaderUtils . get_file_name_from_path (mod_folder_path , false , true )
310
310
311
311
# Path to the mod in UNPACKED_DIR (eg "res://mods-unpacked/My-Mod")
312
312
var local_mod_path = str (UNPACKED_DIR , dir_name )
@@ -320,7 +320,7 @@ func _init_mod_data(mod_folder_path):
320
320
# operation if a mod has a large number of files (eg. Brotato's Invasion mod,
321
321
# which has ~1,000 files). That's why it's disabled by default
322
322
if DEBUG_ENABLE_STORING_FILEPATHS :
323
- mod .file_paths = _get_flat_view_dict (local_mod_path )
323
+ mod .file_paths = ModLoaderUtils . get_flat_view_dict (local_mod_path )
324
324
325
325
326
326
# Run dependency checks on a mod, checking any dependencies it lists in its
@@ -403,113 +403,6 @@ func _init_mod(mod: ModData):
403
403
add_child (mod_main_instance , true )
404
404
405
405
406
- # Utils (Mod Loader)
407
- # =============================================================================
408
-
409
- # Util functions used in the mod loading process
410
-
411
- # Check if the provided command line argument was present when launching the game
412
- func _check_cmd_line_arg (argument ) -> bool :
413
- for arg in OS .get_cmdline_args ():
414
- if arg == argument :
415
- return true
416
-
417
- return false
418
-
419
- # Get the command line argument value if present when launching the game
420
- func _get_cmd_line_arg (argument ) -> String :
421
- for arg in OS .get_cmdline_args ():
422
- if arg .find ("=" ) > - 1 :
423
- var key_value = arg .split ("=" )
424
- # True if the checked argument matches a user-specified arg key
425
- # (eg. checking `--mods-path` will match with `--mods-path="C://mods"`
426
- if key_value [0 ] == argument :
427
- return key_value [1 ]
428
-
429
- return ""
430
-
431
- # Get the path to a local folder. Primarily used to get the (packed) mods
432
- # folder, ie "res://mods" or the OS's equivalent, as well as the configs path
433
- func _get_local_folder_dir (subfolder :String = "" ):
434
- var game_install_directory = OS .get_executable_path ().get_base_dir ()
435
-
436
- if OS .get_name () == "OSX" :
437
- game_install_directory = game_install_directory .get_base_dir ().get_base_dir ()
438
-
439
- # Fix for running the game through the Godot editor (as the EXE path would be
440
- # the editor's own EXE, which won't have any mod ZIPs)
441
- # if OS.is_debug_build():
442
- if OS .has_feature ("editor" ):
443
- game_install_directory = "res://"
444
-
445
- return game_install_directory .plus_file (subfolder )
446
-
447
-
448
- func _get_file_name (path , is_lower_case = true , is_no_extension = false ):
449
- var file_name = path .get_file ()
450
-
451
- if (is_lower_case ):
452
- file_name = file_name .to_lower ()
453
-
454
- if (is_no_extension ):
455
- var file_extension = file_name .get_extension ()
456
- file_name = file_name .replace (str ("." ,file_extension ), '' )
457
-
458
- return file_name
459
-
460
-
461
- # Get a flat array of all files in the target directory. This was needed in the
462
- # original version of this script, before becoming deprecated. It may still be
463
- # used if DEBUG_ENABLE_STORING_FILEPATHS is true.
464
- # Source: https://gist.github.com/willnationsdev/00d97aa8339138fd7ef0d6bd42748f6e
465
- func _get_flat_view_dict (p_dir = "res://" , p_match = "" , p_match_is_regex = false ):
466
- var regex = null
467
- if p_match_is_regex :
468
- regex = RegEx .new ()
469
- regex .compile (p_match )
470
- if not regex .is_valid ():
471
- return []
472
-
473
- var dirs = [p_dir ]
474
- var first = true
475
- var data = []
476
- while not dirs .empty ():
477
- var dir = Directory .new ()
478
- var dir_name = dirs .back ()
479
- dirs .pop_back ()
480
-
481
- if dir .open (dir_name ) == OK :
482
- dir .list_dir_begin ()
483
- var file_name = dir .get_next ()
484
- while file_name != "" :
485
- if not dir_name == "res://" :
486
- first = false
487
- # ignore hidden, temporary, or system content
488
- if not file_name .begins_with ("." ) and not file_name .get_extension () in ["tmp" , "import" ]:
489
- # If a directory, then add to list of directories to visit
490
- if dir .current_is_dir ():
491
- dirs .push_back (dir .get_current_dir () + "/" + file_name )
492
- # If a file, check if we already have a record for the same name
493
- else :
494
- var path = dir .get_current_dir () + ("/" if not first else "" ) + file_name
495
- # grab all
496
- if not p_match :
497
- data .append (path )
498
- # grab matching strings
499
- elif not p_match_is_regex and file_name .find (p_match , 0 ) != - 1 :
500
- data .append (path )
501
- # grab matching regex
502
- else :
503
- var regex_match = regex .search (path )
504
- if regex_match != null :
505
- data .append (path )
506
- # Move on to the next file in this directory
507
- file_name = dir .get_next ()
508
- # We've exhausted all files in this directory. Close the iterator.
509
- dir .list_dir_end ()
510
- return data
511
-
512
-
513
406
# Helpers
514
407
# =============================================================================
515
408
0 commit comments