@@ -26,11 +26,6 @@ extends Node
26
26
# Most of these settings should never need to change, aside from the DEBUG_*
27
27
# options (which should be `false` when distributing compiled PCKs)
28
28
29
- # Enables logging messages made with dev_log. Usually these are enabled with the
30
- # command line arg `--log-dev`, but you can also enable them this way if you're
31
- # debugging in the editor
32
- const DEBUG_ENABLE_DEV_LOG = false
33
-
34
29
# If true, a complete array of filepaths is stored for each mod. This is
35
30
# disabled by default because the operation can be very expensive, but may
36
31
# be useful for debugging
@@ -90,24 +85,24 @@ func _init():
90
85
return
91
86
92
87
# Log game install dir
93
- mod_log (str ("game_install_directory: " , _get_local_folder_dir ()), LOG_NAME )
88
+ ModLoaderUtils . log_info (str ("game_install_directory: " , _get_local_folder_dir ()), LOG_NAME )
94
89
95
90
# check if we want to use a different mods path that is provided as a command line argument
96
91
var cmd_line_mod_path = _get_cmd_line_arg ("--mods-path" )
97
92
if cmd_line_mod_path != "" :
98
93
os_mods_path_override = cmd_line_mod_path
99
- mod_log ("The path mods are loaded from has been changed via the CLI arg `--mods-path`, to: " + cmd_line_mod_path , LOG_NAME )
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 )
100
95
101
96
# Check for the CLI arg that overrides the configs path
102
97
var cmd_line_configs_path = _get_cmd_line_arg ("--configs-path" )
103
98
if cmd_line_configs_path != "" :
104
99
os_configs_path_override = cmd_line_configs_path
105
- mod_log ("The path configs are loaded from has been changed via the CLI arg `--configs-path`, to: " + cmd_line_configs_path , LOG_NAME )
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 )
106
101
107
102
# Loop over "res://mods" and add any mod zips to the unpacked virtual
108
103
# directory (UNPACKED_DIR)
109
104
_load_mod_zips ()
110
- mod_log ("DONE: Loaded all mod files into the virtual filesystem" , LOG_NAME )
105
+ ModLoaderUtils . log_success ("DONE: Loaded all mod files into the virtual filesystem" , LOG_NAME )
111
106
112
107
# Loop over UNPACKED_DIR. This triggers _init_mod_data for each mod
113
108
# directory, which adds their data to mod_data.
@@ -125,7 +120,7 @@ func _init():
125
120
var mod : ModData = mod_data [dir_name ]
126
121
mod .load_manifest ()
127
122
128
- mod_log ("DONE: Loaded all meta data" , LOG_NAME )
123
+ ModLoaderUtils . log_success ("DONE: Loaded all meta data" , LOG_NAME )
129
124
130
125
# Run dependency checks after loading mod_manifest. If a mod depends on another
131
126
# mod that hasn't been loaded, that dependent mod won't be loaded.
@@ -142,61 +137,17 @@ func _init():
142
137
var mod_i = 1
143
138
for mod in mod_load_order : # mod === mod_data
144
139
mod = mod as ModData
145
- dev_log ("mod_load_order -> %s ) %s " % [mod_i , mod .dir_name ], LOG_NAME )
140
+ ModLoaderUtils . log_debug ("mod_load_order -> %s ) %s " % [mod_i , mod .dir_name ], LOG_NAME )
146
141
mod_i += 1
147
142
148
143
# Instance every mod and add it as a node to the Mod Loader
149
144
for mod in mod_load_order :
150
- # mod_log(str("Initializing -> ", mod.mod_manifest.extra.godot.id), LOG_NAME)
151
- mod_log ("Initializing -> %s " % mod .manifest .get_mod_id (), LOG_NAME )
145
+ ModLoaderUtils .log_info ("Initializing -> %s " % mod .manifest .get_mod_id (), LOG_NAME )
152
146
_init_mod (mod )
153
147
154
- dev_log (str ("mod_data: " , JSON .print (mod_data , ' ' )), LOG_NAME )
155
-
156
- mod_log ("DONE: Completely finished loading mods" , LOG_NAME )
157
-
158
-
159
- # Log developer info. Has to be enabled, either with the command line arg
160
- # `--log-dev`, or by temporarily enabling DEBUG_ENABLE_DEV_LOG
161
- func dev_log (text :String , mod_name :String = "Unknown-Mod" , pretty :bool = false ):
162
- if DEBUG_ENABLE_DEV_LOG || (_check_cmd_line_arg ("--log-dev" )):
163
- mod_log (text , mod_name , pretty )
164
-
165
-
166
- # Log info for a mod. Accepts the mod name as the 2nd arg, which prefixes
167
- # the logged string with "{mod_name}: "
168
- func mod_log (text :String , mod_name :String = "Unknown-Mod" , pretty :bool = false )-> void :
169
- # Prefix with "{mod_name}: "
170
- var prefix = mod_name + ": "
171
-
172
- var date_time = Time .get_datetime_dict_from_system ()
148
+ ModLoaderUtils .log_debug_json_print ("mod data" , mod_data , LOG_NAME )
173
149
174
- # Add leading zeroes if needed
175
- var hour := (date_time .hour as String ).pad_zeros (2 )
176
- var mins := (date_time .minute as String ).pad_zeros (2 )
177
- var secs := (date_time .second as String ).pad_zeros (2 )
178
-
179
- var date_time_string := "%s .%s .%s - %s :%s :%s " % [date_time .day , date_time .month , date_time .year , hour , mins , secs ]
180
-
181
- print (str (date_time_string ,' ' , prefix , text ))
182
-
183
- var log_file = File .new ()
184
-
185
- if (! log_file .file_exists (MOD_LOG_PATH )):
186
- log_file .open (MOD_LOG_PATH , File .WRITE )
187
- log_file .store_string ('%s Created mod.log!' % date_time_string )
188
- log_file .close ()
189
-
190
- var _error = log_file .open (MOD_LOG_PATH , File .READ_WRITE )
191
- if _error :
192
- print (_error )
193
- return
194
- log_file .seek_end ()
195
- if pretty :
196
- log_file .store_string ("\n " + str (date_time_string ,' ' , prefix , JSON .print (text , " " )))
197
- else :
198
- log_file .store_string ("\n " + str (date_time_string ,' ' , prefix , text ))
199
- log_file .close ()
150
+ ModLoaderUtils .log_success ("DONE: Completely finished loading mods" , LOG_NAME )
200
151
201
152
202
153
# Loop over "res://mods" and add any mod zips to the unpacked virtual directory
@@ -207,10 +158,10 @@ func _load_mod_zips():
207
158
208
159
var dir = Directory .new ()
209
160
if dir .open (game_mod_folder_path ) != OK :
210
- mod_log ("Can't open mod folder %s ." % game_mod_folder_path , LOG_NAME )
161
+ ModLoaderUtils . log_error ("Can't open mod folder %s ." % game_mod_folder_path , LOG_NAME )
211
162
return
212
163
if dir .list_dir_begin () != OK :
213
- mod_log ("Can't read mod folder %s ." % game_mod_folder_path , LOG_NAME )
164
+ ModLoaderUtils . log_error ("Can't read mod folder %s ." % game_mod_folder_path , LOG_NAME )
214
165
return
215
166
216
167
var has_shown_editor_warning = false
@@ -246,22 +197,22 @@ func _load_mod_zips():
246
197
# https://github.com/godotengine/godot/issues/19815
247
198
# https://github.com/godotengine/godot/issues/16798
248
199
if OS .has_feature ("editor" ) && ! has_shown_editor_warning :
249
- mod_log (str (
250
- "WARNING: Loading any resource packs (.zip/.pck) with `load_resource_pack` will WIPE the entire virtual res:// directory. " ,
200
+ ModLoaderUtils . log_warning (str (
201
+ "Loading any resource packs (.zip/.pck) with `load_resource_pack` will WIPE the entire virtual res:// directory. " ,
251
202
"If you have any unpacked mods in " , UNPACKED_DIR , ", they will not be loaded. " ,
252
203
"Please unpack your mod ZIPs instead, and add them to " , UNPACKED_DIR ), LOG_NAME )
253
204
has_shown_editor_warning = true
254
205
255
- dev_log (str ("Found mod ZIP: " , mod_folder_global_path ), LOG_NAME )
206
+ ModLoaderUtils . log_debug (str ("Found mod ZIP: " , mod_folder_global_path ), LOG_NAME )
256
207
257
208
# If there was an error loading the mod zip file
258
209
if ! is_mod_loaded_success :
259
210
# Log the error and continue with the next file
260
- mod_log (str (mod_zip_file_name , " failed to load." ), LOG_NAME )
211
+ ModLoaderUtils . log_error (str (mod_zip_file_name , " failed to load." ), LOG_NAME )
261
212
continue
262
213
263
214
# Mod successfully loaded!
264
- mod_log (str (mod_zip_file_name , " loaded." ), LOG_NAME )
215
+ ModLoaderUtils . log_success (str (mod_zip_file_name , " loaded." ), LOG_NAME )
265
216
266
217
dir .list_dir_end ()
267
218
@@ -274,10 +225,10 @@ func _setup_mods():
274
225
275
226
var dir = Directory .new ()
276
227
if dir .open (unpacked_mods_path ) != OK :
277
- mod_log ("Can't open unpacked mods folder %s ." % unpacked_mods_path , LOG_NAME )
228
+ ModLoaderUtils . log_error ("Can't open unpacked mods folder %s ." % unpacked_mods_path , LOG_NAME )
278
229
return
279
230
if dir .list_dir_begin () != OK :
280
- mod_log ("Can't read unpacked mods folder %s ." % unpacked_mods_path , LOG_NAME )
231
+ ModLoaderUtils . log_error ("Can't read unpacked mods folder %s ." % unpacked_mods_path , LOG_NAME )
281
232
return
282
233
283
234
# Get all unpacked mod dirs
@@ -317,13 +268,13 @@ func _load_mod_configs():
317
268
var json_path = configs_path .plus_file (dir_name + ".json" )
318
269
var mod_config = ModData ._get_json_as_dict (json_path )
319
270
320
- dev_log (str ("Config JSON: Looking for config at path: " , json_path ), LOG_NAME )
271
+ ModLoaderUtils . log_debug (str ("Config JSON: Looking for config at path: " , json_path ), LOG_NAME )
321
272
322
273
if mod_config .size () > 0 :
323
274
found_configs_count += 1
324
275
325
- mod_log (str ("Config JSON: Found a config file: '" , json_path , "'" ), LOG_NAME )
326
- dev_log (str ("Config JSON: File data: " , JSON .print (mod_config )), LOG_NAME )
276
+ ModLoaderUtils . log_info (str ("Config JSON: Found a config file: '" , json_path , "'" ), LOG_NAME )
277
+ ModLoaderUtils . log_debug (str ("Config JSON: File data: " , JSON .print (mod_config )), LOG_NAME )
327
278
328
279
# Check `load_from` option. This lets you specify the name of a
329
280
# different JSON file to load your config from. Must be in the same
@@ -333,21 +284,21 @@ func _load_mod_configs():
333
284
if mod_config .has ("load_from" ):
334
285
var new_path = mod_config .load_from
335
286
if new_path != "" && new_path != str (dir_name , ".json" ):
336
- mod_log (str ("Config JSON: Following load_from path: " , new_path ), LOG_NAME )
287
+ ModLoaderUtils . log_info (str ("Config JSON: Following load_from path: " , new_path ), LOG_NAME )
337
288
var new_config = ModData ._get_json_as_dict (configs_path + new_path )
338
289
if new_config .size () > 0 != null :
339
290
mod_config = new_config
340
- mod_log (str ("Config JSON: Loaded from custom json: " , new_path ), LOG_NAME )
341
- dev_log (str ("Config JSON: File data: " , JSON .print (mod_config )), LOG_NAME )
291
+ ModLoaderUtils . log_info (str ("Config JSON: Loaded from custom json: " , new_path ), LOG_NAME )
292
+ ModLoaderUtils . log_debug (str ("Config JSON: File data: " , JSON .print (mod_config )), LOG_NAME )
342
293
else :
343
- mod_log (str ("Config JSON: ERROR - Could not load data via `load_from` for " , dir_name , ", at path: " , new_path ), LOG_NAME )
294
+ ModLoaderUtils . log_error (str ("Config JSON: ERROR - Could not load data via `load_from` for " , dir_name , ", at path: " , new_path ), LOG_NAME )
344
295
345
296
mod_data [dir_name ].config = mod_config
346
297
347
298
if found_configs_count > 0 :
348
- mod_log (str ("Config JSON: Loaded " , str (found_configs_count ), " config(s)" ), LOG_NAME )
299
+ ModLoaderUtils . log_success (str ("Config JSON: Loaded " , str (found_configs_count ), " config(s)" ), LOG_NAME )
349
300
else :
350
- mod_log (str ("Config JSON: No mod configs were found" ), LOG_NAME )
301
+ ModLoaderUtils . log_info (str ("Config JSON: No mod configs were found" ), LOG_NAME )
351
302
352
303
353
304
# Add a mod's data to mod_data.
@@ -376,7 +327,7 @@ func _init_mod_data(mod_folder_path):
376
327
# mod_manifest (ie. its manifest.json file). If a mod depends on another mod that
377
328
# hasn't been loaded, the dependent mod won't be loaded.
378
329
func _check_dependencies (mod_id :String , deps :Array ):
379
- dev_log (str ("Checking dependencies - mod_id: " , mod_id , " dependencies: " , deps ), LOG_NAME )
330
+ ModLoaderUtils . log_debug (str ("Checking dependencies - mod_id: " , mod_id , " dependencies: " , deps ), LOG_NAME )
380
331
381
332
# loop through each dependency
382
333
for dependency_id in deps :
@@ -392,7 +343,7 @@ func _check_dependencies(mod_id:String, deps:Array):
392
343
393
344
# increase importance score by 1
394
345
dependency .importance = dependency .importance + 1
395
- dev_log (str ("Dependency -> " , dependency_id , " importance -> " , dependency .importance ), LOG_NAME )
346
+ ModLoaderUtils . log_debug (str ("Dependency -> " , dependency_id , " importance -> " , dependency .importance ), LOG_NAME )
396
347
397
348
# check if dependency has dependencies
398
349
if (dependency_mod_manifest .dependencies .size () > 0 ):
@@ -401,7 +352,7 @@ func _check_dependencies(mod_id:String, deps:Array):
401
352
402
353
# Handle missing dependencies: Sets `is_loadable` to false and logs an error
403
354
func _handle_missing_dependency (mod_id , dependency_id ):
404
- mod_log (str ("ERROR - missing dependency - mod_id -> " , mod_id , " dependency_id -> " , dependency_id ), LOG_NAME )
355
+ ModLoaderUtils . log_error (str ("Missing dependency - mod_id -> " , mod_id , " dependency_id -> " , dependency_id ), LOG_NAME )
405
356
# if mod is not present in the missing dependencies array
406
357
if (! mod_missing_dependencies .has (mod_id )):
407
358
# add it
@@ -440,15 +391,15 @@ func _compare_importance(a, b):
440
391
func _init_mod (mod : ModData ):
441
392
var mod_main_path = mod .get_required_mod_file_path (ModData .required_mod_files .MOD_MAIN )
442
393
443
- dev_log ("Loading script from -> %s " % mod_main_path , LOG_NAME )
394
+ ModLoaderUtils . log_debug ("Loading script from -> %s " % mod_main_path , LOG_NAME )
444
395
var mod_main_script = ResourceLoader .load (mod_main_path )
445
- dev_log ("Loaded script -> %s " % mod_main_script , LOG_NAME )
396
+ ModLoaderUtils . log_debug ("Loaded script -> %s " % mod_main_script , LOG_NAME )
446
397
447
398
var mod_main_instance = mod_main_script .new (self )
448
399
# mod_main_instance.name = mod.mod_manifest.extra.godot.id
449
400
mod_main_instance .name = mod .manifest .get_mod_id ()
450
401
451
- dev_log ("Adding child -> %s " % mod_main_instance , LOG_NAME )
402
+ ModLoaderUtils . log_debug ("Adding child -> %s " % mod_main_instance , LOG_NAME )
452
403
add_child (mod_main_instance , true )
453
404
454
405
@@ -495,19 +446,15 @@ func _get_local_folder_dir(subfolder:String = ""):
495
446
496
447
497
448
func _get_file_name (path , is_lower_case = true , is_no_extension = false ):
498
- # mod_log(str("Get file name from path -> ", path), LOG_NAME)
499
449
var file_name = path .get_file ()
500
450
501
451
if (is_lower_case ):
502
- # mod_log(str("Get file name in lower case"), LOG_NAME)
503
452
file_name = file_name .to_lower ()
504
453
505
454
if (is_no_extension ):
506
- # mod_log(str("Get file name without extension"), LOG_NAME)
507
455
var file_extension = file_name .get_extension ()
508
456
file_name = file_name .replace (str ("." ,file_extension ), '' )
509
457
510
- # mod_log(str("return file name -> ", file_name), LOG_NAME)
511
458
return file_name
512
459
513
460
@@ -577,7 +524,7 @@ func _get_flat_view_dict(p_dir = "res://", p_match = "", p_match_is_regex = fals
577
524
func install_script_extension (child_script_path :String ):
578
525
# Check path to file exists
579
526
if ! File .new ().file_exists (child_script_path ):
580
- mod_log ( "ERROR - The child script path '%s ' does not exist" % [child_script_path ], LOG_NAME )
527
+ ModLoaderUtils . log_error ( " The child script path '%s ' does not exist" % [child_script_path ], LOG_NAME )
581
528
return
582
529
583
530
var child_script = ResourceLoader .load (child_script_path )
@@ -593,7 +540,7 @@ func install_script_extension(child_script_path:String):
593
540
594
541
var parent_script = child_script .get_base_script ()
595
542
var parent_script_path = parent_script .resource_path
596
- mod_log ("Installing script extension: %s <- %s " % [parent_script_path , child_script_path ], LOG_NAME )
543
+ ModLoaderUtils . log_info ("Installing script extension: %s <- %s " % [parent_script_path , child_script_path ], LOG_NAME )
597
544
child_script .take_over_path (parent_script_path )
598
545
599
546
@@ -603,7 +550,7 @@ func install_script_extension(child_script_path:String):
603
550
func add_translation_from_resource (resource_path : String ):
604
551
var translation_object = load (resource_path )
605
552
TranslationServer .add_translation (translation_object )
606
- mod_log (str ("Added Translation from Resource -> " , resource_path ), LOG_NAME )
553
+ ModLoaderUtils . log_info (str ("Added Translation from Resource -> " , resource_path ), LOG_NAME )
607
554
608
555
609
556
func append_node_in_scene (modified_scene , node_name :String = "" , node_parent = null , instance_path :String = "" , is_visible :bool = true ):
@@ -628,9 +575,9 @@ func append_node_in_scene(modified_scene, node_name:String = "", node_parent = n
628
575
func save_scene (modified_scene , scene_path :String ):
629
576
var packed_scene = PackedScene .new ()
630
577
packed_scene .pack (modified_scene )
631
- dev_log (str ("packing scene -> " , packed_scene ), LOG_NAME )
578
+ ModLoaderUtils . log_debug (str ("packing scene -> " , packed_scene ), LOG_NAME )
632
579
packed_scene .take_over_path (scene_path )
633
- dev_log (str ("save_scene - taking over path - new path -> " , packed_scene .resource_path ), LOG_NAME )
580
+ ModLoaderUtils . log_debug (str ("save_scene - taking over path - new path -> " , packed_scene .resource_path ), LOG_NAME )
634
581
_saved_objects .append (packed_scene )
635
582
636
583
@@ -688,7 +635,7 @@ func get_mod_config(mod_id:String = "", key:String = "")->Dictionary:
688
635
689
636
# Log if any errors occured
690
637
if error_num != 0 :
691
- dev_log (str ("Config: " , error_msg ), mod_id )
638
+ ModLoaderUtils . log_debug (str ("Config: " , error_msg ), mod_id )
692
639
693
640
return {
694
641
"error" : error_num ,
0 commit comments