updates to modLoadOrder

This commit is contained in:
Dev 2023-10-18 17:36:36 +01:00
parent 6231d73109
commit e8d3fb805e

View File

@ -1,5 +1,7 @@
import { injectable } from "tsyringe"; import { inject, injectable } from "tsyringe";
import { IPackageJsonData } from "../models/spt/mod/IPackageJsonData"; import { IPackageJsonData } from "../models/spt/mod/IPackageJsonData";
import { ILogger } from "../models/spt/utils/ILogger";
import { LocalisationService } from "../services/LocalisationService";
@injectable() @injectable()
export class ModLoadOrder export class ModLoadOrder
@ -8,6 +10,12 @@ export class ModLoadOrder
protected modsAvailable = new Map<string, IPackageJsonData>(); protected modsAvailable = new Map<string, IPackageJsonData>();
protected loadOrder = new Set<string>(); protected loadOrder = new Set<string>();
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("LocalisationService") protected localisationService: LocalisationService
)
{ }
public setModList(mods: Record<string, IPackageJsonData>): void public setModList(mods: Record<string, IPackageJsonData>): void
{ {
this.mods = new Map<string, IPackageJsonData>(Object.entries(mods)); this.mods = new Map<string, IPackageJsonData>(Object.entries(mods));
@ -82,12 +90,6 @@ export class ModLoadOrder
protected invertLoadBefore(mod: string): void protected invertLoadBefore(mod: string): void
{ {
if (!this.modsAvailable.has(mod))
{
console.log("missing mod", mod);
throw new Error("MISSING DEPENDENCY");
}
const loadBefore = this.getModsOnLoadBefore(mod); const loadBefore = this.getModsOnLoadBefore(mod);
for (const loadBeforeMod of loadBefore) for (const loadBeforeMod of loadBefore)
@ -111,17 +113,25 @@ export class ModLoadOrder
if (visited.has(mod)) if (visited.has(mod))
{ {
console.log("current mod", mod); // front: white, back: red
console.log("result", JSON.stringify(this.loadOrder, null, "\t")); this.logger.error(this.localisationService.getText("modloader-cyclic_dependency"));
console.log("visited", JSON.stringify(visited, null, "\t"));
throw new Error("CYCLIC DEPENDENCY"); // additional info
this.logger.debug(this.localisationService.getText("modloader-checking_mod", mod));
this.logger.debug(`${this.localisationService.getText("modloader-checked")}:`);
this.logger.debug(JSON.stringify(this.loadOrder, null, "\t"));
this.logger.debug(`${this.localisationService.getText("modloader-visited")}:`);
this.logger.debug(JSON.stringify(visited, null, "\t"));
// wait for input
process.exit(1);
} }
// check dependencies // check dependencies
if (!this.modsAvailable.has(mod)) if (!this.modsAvailable.has(mod))
{ {
console.log("missing mod", mod); this.logger.error(this.localisationService.getText("modloader-missing_dependency"));
throw new Error("MISSING DEPENDENCY"); throw new Error(this.localisationService.getText("modloader-error_parsing_mod_load_order"));
} }
const config = this.modsAvailable.get(mod); const config = this.modsAvailable.get(mod);