@@ -16,10 +16,10 @@ static func handle_script_extensions() -> void:
1616 extension_paths .push_back (extension_path )
1717 else :
1818 ModLoaderLog .error ("The child script path '%s ' does not exist" % [extension_path ], LOG_NAME )
19-
19+
2020 # Sort by inheritance
2121 extension_paths .sort_custom (InheritanceSorting .new (), "_check_inheritances" )
22-
22+
2323 # Load and install all extensions
2424 for extension in extension_paths :
2525 var script : Script = apply_extension (extension )
@@ -33,13 +33,10 @@ class InheritanceSorting:
3333 var stack_cache := {}
3434 # This dictionary's keys are mod_ids and it stores the corresponding position in the load_order
3535 var load_order := {}
36- var unpacked_dir = _ModLoaderPath .get_unpacked_mods_dir_path ()
37-
38-
36+
3937 func _init () -> void :
4038 _populate_load_order_table ()
41-
42-
39+
4340 # Comparator function. return true if a should go before b. This may
4441 # enforce conditions beyond the stated inheritance relationship.
4542 func _check_inheritances (extension_a : String , extension_b : String ) -> bool :
@@ -58,37 +55,34 @@ class InheritanceSorting:
5855 return true
5956
6057 return compare_mods_order (extension_a , extension_b )
61-
62-
58+
6359 # Returns a list of scripts representing all the ancestors of the extension
6460 # script with the most recent ancestor last.
6561 #
6662 # Results are stored in a cache keyed by extension path
6763 func cached_inheritances_stack (extension_path : String ) -> Array :
6864 if stack_cache .has (extension_path ):
6965 return stack_cache [extension_path ]
70-
66+
7167 var stack := []
72-
68+
7369 var parent_script : Script = load (extension_path )
7470 while parent_script :
7571 stack .push_front (parent_script .resource_path )
7672 parent_script = parent_script .get_base_script ()
7773 stack .pop_back ()
78-
74+
7975 stack_cache [extension_path ] = stack
8076 return stack
81-
82-
77+
8378 # Secondary comparator function for resolving scripts extending the same vanilla script
8479 # Will return whether a comes before b in the load order
8580 func compare_mods_order (extension_a : String , extension_b : String ) -> bool :
8681 var mod_a_id : String = _ModLoaderPath .get_mod_dir (extension_a )
8782 var mod_b_id : String = _ModLoaderPath .get_mod_dir (extension_b )
88-
83+
8984 return load_order [mod_a_id ] < load_order [mod_b_id ]
90-
91-
85+
9286 # Populate a load order dictionary for faster access and comparison between mod ids
9387 func _populate_load_order_table () -> void :
9488 var mod_index := 0
0 commit comments