Skip to content

Commit 09f6900

Browse files
committed
added a comparator method to sort extensions of the same script
added a comparator method to sort extensions of the same script following the load order
1 parent 0253c6d commit 09f6900

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

addons/mod_loader/internal/script_extension.gd

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class InheritanceSorting:
4545
return a_stack[index] < b_stack[index]
4646
last_index = index
4747

48-
if last_index < b_stack.size():
48+
if last_index < b_stack.size() - 1:
4949
return true
5050

51-
return extension_a < extension_b
51+
return compare_mods_order(extension_a, extension_b)
5252

5353
# Returns a list of scripts representing all the ancestors of the extension
5454
# script with the most recent ancestor last.
@@ -68,6 +68,21 @@ class InheritanceSorting:
6868

6969
stack_cache[extension_path] = stack
7070
return stack
71+
72+
# Secondary comparator function for resolving scripts extending the same vanilla script
73+
# Will return whether a comes before b in the load order
74+
func compare_mods_order(extension_a:String, extension_b:String)->bool:
75+
var mod_a_id = extension_a.trim_prefix(_ModLoaderPath.get_unpacked_mods_dir_path()).get_slice("/", 0)
76+
var mod_b_id = extension_b.trim_prefix(_ModLoaderPath.get_unpacked_mods_dir_path()).get_slice("/", 0)
77+
78+
for mod in ModLoaderStore.mod_load_order:
79+
if mod.dir_name == mod_a_id:
80+
return true
81+
elif mod.dir_name == mod_b_id:
82+
return false
83+
84+
# Should never happen
85+
return extension_a < extension_b
7186

7287

7388
static func apply_extension(extension_path: String) -> Script:

0 commit comments

Comments
 (0)