@@ -16,10 +16,10 @@ static func handle_script_extensions() -> void:
16
16
extension_paths .push_back (extension_path )
17
17
else :
18
18
ModLoaderLog .error ("The child script path '%s ' does not exist" % [extension_path ], LOG_NAME )
19
-
19
+
20
20
# Sort by inheritance
21
21
extension_paths .sort_custom (InheritanceSorting .new (), "_check_inheritances" )
22
-
22
+
23
23
# Load and install all extensions
24
24
for extension in extension_paths :
25
25
var script : Script = apply_extension (extension )
@@ -33,13 +33,10 @@ class InheritanceSorting:
33
33
var stack_cache := {}
34
34
# This dictionary's keys are mod_ids and it stores the corresponding position in the load_order
35
35
var load_order := {}
36
- var unpacked_dir = _ModLoaderPath .get_unpacked_mods_dir_path ()
37
-
38
-
36
+
39
37
func _init () -> void :
40
38
_populate_load_order_table ()
41
-
42
-
39
+
43
40
# Comparator function. return true if a should go before b. This may
44
41
# enforce conditions beyond the stated inheritance relationship.
45
42
func _check_inheritances (extension_a : String , extension_b : String ) -> bool :
@@ -58,37 +55,34 @@ class InheritanceSorting:
58
55
return true
59
56
60
57
return compare_mods_order (extension_a , extension_b )
61
-
62
-
58
+
63
59
# Returns a list of scripts representing all the ancestors of the extension
64
60
# script with the most recent ancestor last.
65
61
#
66
62
# Results are stored in a cache keyed by extension path
67
63
func cached_inheritances_stack (extension_path : String ) -> Array :
68
64
if stack_cache .has (extension_path ):
69
65
return stack_cache [extension_path ]
70
-
66
+
71
67
var stack := []
72
-
68
+
73
69
var parent_script : Script = load (extension_path )
74
70
while parent_script :
75
71
stack .push_front (parent_script .resource_path )
76
72
parent_script = parent_script .get_base_script ()
77
73
stack .pop_back ()
78
-
74
+
79
75
stack_cache [extension_path ] = stack
80
76
return stack
81
-
82
-
77
+
83
78
# Secondary comparator function for resolving scripts extending the same vanilla script
84
79
# Will return whether a comes before b in the load order
85
80
func compare_mods_order (extension_a : String , extension_b : String ) -> bool :
86
81
var mod_a_id : String = _ModLoaderPath .get_mod_dir (extension_a )
87
82
var mod_b_id : String = _ModLoaderPath .get_mod_dir (extension_b )
88
-
83
+
89
84
return load_order [mod_a_id ] < load_order [mod_b_id ]
90
-
91
-
85
+
92
86
# Populate a load order dictionary for faster access and comparison between mod ids
93
87
func _populate_load_order_table () -> void :
94
88
var mod_index := 0
0 commit comments