From 3876e1ae1514f380774a0d207fe77959ac6d1377 Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 2 Aug 2023 08:50:04 +0100 Subject: [PATCH] Pull mod sorting code into its own function --- project/src/loaders/PreAkiModLoader.ts | 40 +++++++++++++++----------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/project/src/loaders/PreAkiModLoader.ts b/project/src/loaders/PreAkiModLoader.ts index 61b16a61..dee221ae 100644 --- a/project/src/loaders/PreAkiModLoader.ts +++ b/project/src/loaders/PreAkiModLoader.ts @@ -145,23 +145,7 @@ export class PreAkiModLoader implements IModLoader // sort mod order const missingFromOrderJSON = {}; - const sortedMods = mods.sort((prev, next) => - { - const previndex = this.order[prev]; - const nextindex = this.order[next]; - // mod is not on the list, move the mod to last - if (previndex === undefined) - { - missingFromOrderJSON[prev] = true; - return 1; - } - else if (nextindex === undefined) - { - missingFromOrderJSON[next] = true; - return -1; - } - return previndex - nextindex; - }); + const sortedMods = mods.sort((prev, next) => this.sortMods(prev, next, missingFromOrderJSON)); // log the missing mods from order.json Object.keys(missingFromOrderJSON).forEach((missingMod) => (this.logger.debug(this.localisationService.getText("modloader-mod_order_missing_from_json", missingMod)))); @@ -173,6 +157,28 @@ export class PreAkiModLoader implements IModLoader } } + protected sortMods(prev: string, next: string, missingFromOrderJSON: Record): number + { + const previndex = this.order[prev]; + const nextindex = this.order[next]; + + // mod is not on the list, move the mod to last + if (previndex === undefined) + { + missingFromOrderJSON[prev] = true; + + return 1; + } + else if (nextindex === undefined) + { + missingFromOrderJSON[next] = true; + + return -1; + } + + return previndex - nextindex; + } + /** * Check for duplicate mods loaded, show error if any * @param modPackageData Dictionary of mod package.json data