defered addBundles after PostDBModLoader is run
- defered addBundles after PostDBModLoader is run - removed unused injected class instances
This commit is contained in:
parent
fdc6be4dc7
commit
5e8fb7b303
@ -1,6 +1,5 @@
|
|||||||
import { DependencyContainer, inject, injectable } from "tsyringe";
|
import { DependencyContainer, inject, injectable } from "tsyringe";
|
||||||
|
|
||||||
import { BundleLoader } from "@spt-aki/loaders/BundleLoader";
|
|
||||||
import { ModTypeCheck } from "@spt-aki/loaders/ModTypeCheck";
|
import { ModTypeCheck } from "@spt-aki/loaders/ModTypeCheck";
|
||||||
import { PreAkiModLoader } from "@spt-aki/loaders/PreAkiModLoader";
|
import { PreAkiModLoader } from "@spt-aki/loaders/PreAkiModLoader";
|
||||||
import { IPostAkiLoadMod } from "@spt-aki/models/external/IPostAkiLoadMod";
|
import { IPostAkiLoadMod } from "@spt-aki/models/external/IPostAkiLoadMod";
|
||||||
@ -8,15 +7,14 @@ import { IPostAkiLoadModAsync } from "@spt-aki/models/external/IPostAkiLoadModAs
|
|||||||
import { IModLoader } from "@spt-aki/models/spt/mod/IModLoader";
|
import { IModLoader } from "@spt-aki/models/spt/mod/IModLoader";
|
||||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||||
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
||||||
import { VFS } from "@spt-aki/utils/VFS";
|
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class PostAkiModLoader implements IModLoader
|
export class PostAkiModLoader implements IModLoader
|
||||||
{
|
{
|
||||||
|
protected container: DependencyContainer;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject("WinstonLogger") protected logger: ILogger,
|
@inject("WinstonLogger") protected logger: ILogger,
|
||||||
@inject("BundleLoader") protected bundleLoader: BundleLoader,
|
|
||||||
@inject("VFS") protected vfs: VFS,
|
|
||||||
@inject("PreAkiModLoader") protected preAkiModLoader: PreAkiModLoader,
|
@inject("PreAkiModLoader") protected preAkiModLoader: PreAkiModLoader,
|
||||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||||
@inject("ModTypeCheck") protected modTypeCheck: ModTypeCheck,
|
@inject("ModTypeCheck") protected modTypeCheck: ModTypeCheck,
|
||||||
@ -32,12 +30,12 @@ export class PostAkiModLoader implements IModLoader
|
|||||||
{
|
{
|
||||||
if (globalThis.G_MODS_ENABLED)
|
if (globalThis.G_MODS_ENABLED)
|
||||||
{
|
{
|
||||||
await this.executeMods(this.preAkiModLoader.getContainer());
|
this.container = this.preAkiModLoader.getContainer();
|
||||||
this.addBundles();
|
await this.executeModsAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async executeMods(container: DependencyContainer): Promise<void>
|
protected async executeModsAsync(): Promise<void>
|
||||||
{
|
{
|
||||||
const mods = this.preAkiModLoader.sortModsLoadOrder();
|
const mods = this.preAkiModLoader.sortModsLoadOrder();
|
||||||
for (const modName of mods)
|
for (const modName of mods)
|
||||||
@ -54,7 +52,7 @@ export class PostAkiModLoader implements IModLoader
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await (mod.mod as IPostAkiLoadModAsync).postAkiLoadAsync(container);
|
await (mod.mod as IPostAkiLoadModAsync).postAkiLoadAsync(this.container);
|
||||||
}
|
}
|
||||||
catch (err)
|
catch (err)
|
||||||
{
|
{
|
||||||
@ -69,21 +67,7 @@ export class PostAkiModLoader implements IModLoader
|
|||||||
|
|
||||||
if (this.modTypeCheck.isPostAkiLoad(mod.mod))
|
if (this.modTypeCheck.isPostAkiLoad(mod.mod))
|
||||||
{
|
{
|
||||||
(mod.mod as IPostAkiLoadMod).postAkiLoad(container);
|
(mod.mod as IPostAkiLoadMod).postAkiLoad(this.container);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected addBundles(): void
|
|
||||||
{
|
|
||||||
const mods = this.preAkiModLoader.sortModsLoadOrder();
|
|
||||||
for (const modName of mods)
|
|
||||||
{
|
|
||||||
// add mod bundles
|
|
||||||
const modpath = this.preAkiModLoader.getModPath(modName);
|
|
||||||
if (this.vfs.exists(`${modpath}bundles.json`))
|
|
||||||
{
|
|
||||||
this.bundleLoader.addBundles(modpath);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { DependencyContainer, inject, injectable } from "tsyringe";
|
import { DependencyContainer, inject, injectable } from "tsyringe";
|
||||||
|
|
||||||
import { OnLoad } from "@spt-aki/di/OnLoad";
|
import { OnLoad } from "@spt-aki/di/OnLoad";
|
||||||
|
import { BundleLoader } from "@spt-aki/loaders/BundleLoader";
|
||||||
import { ModTypeCheck } from "@spt-aki/loaders/ModTypeCheck";
|
import { ModTypeCheck } from "@spt-aki/loaders/ModTypeCheck";
|
||||||
import { PreAkiModLoader } from "@spt-aki/loaders/PreAkiModLoader";
|
import { PreAkiModLoader } from "@spt-aki/loaders/PreAkiModLoader";
|
||||||
import { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod";
|
import { IPostDBLoadMod } from "@spt-aki/models/external/IPostDBLoadMod";
|
||||||
@ -11,8 +12,11 @@ import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
|||||||
@injectable()
|
@injectable()
|
||||||
export class PostDBModLoader implements OnLoad
|
export class PostDBModLoader implements OnLoad
|
||||||
{
|
{
|
||||||
|
protected container: DependencyContainer;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject("WinstonLogger") protected logger: ILogger,
|
@inject("WinstonLogger") protected logger: ILogger,
|
||||||
|
@inject("BundleLoader") protected bundleLoader: BundleLoader,
|
||||||
@inject("PreAkiModLoader") protected preAkiModLoader: PreAkiModLoader,
|
@inject("PreAkiModLoader") protected preAkiModLoader: PreAkiModLoader,
|
||||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||||
@inject("ModTypeCheck") protected modTypeCheck: ModTypeCheck,
|
@inject("ModTypeCheck") protected modTypeCheck: ModTypeCheck,
|
||||||
@ -23,7 +27,9 @@ export class PostDBModLoader implements OnLoad
|
|||||||
{
|
{
|
||||||
if (globalThis.G_MODS_ENABLED)
|
if (globalThis.G_MODS_ENABLED)
|
||||||
{
|
{
|
||||||
await this.executeMods(this.preAkiModLoader.getContainer());
|
this.container = this.preAkiModLoader.getContainer();
|
||||||
|
await this.executeModsAsync();
|
||||||
|
this.addBundles();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +43,7 @@ export class PostDBModLoader implements OnLoad
|
|||||||
return this.preAkiModLoader.getModPath(mod);
|
return this.preAkiModLoader.getModPath(mod);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async executeMods(container: DependencyContainer): Promise<void>
|
protected async executeModsAsync(): Promise<void>
|
||||||
{
|
{
|
||||||
const mods = this.preAkiModLoader.sortModsLoadOrder();
|
const mods = this.preAkiModLoader.sortModsLoadOrder();
|
||||||
for (const modName of mods)
|
for (const modName of mods)
|
||||||
@ -54,7 +60,7 @@ export class PostDBModLoader implements OnLoad
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await (mod.mod as IPostDBLoadModAsync).postDBLoadAsync(container);
|
await (mod.mod as IPostDBLoadModAsync).postDBLoadAsync(this.container);
|
||||||
}
|
}
|
||||||
catch (err)
|
catch (err)
|
||||||
{
|
{
|
||||||
@ -69,7 +75,21 @@ export class PostDBModLoader implements OnLoad
|
|||||||
|
|
||||||
if (this.modTypeCheck.isPostDBAkiLoad(mod.mod))
|
if (this.modTypeCheck.isPostDBAkiLoad(mod.mod))
|
||||||
{
|
{
|
||||||
(mod.mod as IPostDBLoadMod).postDBLoad(container);
|
(mod.mod as IPostDBLoadMod).postDBLoad(this.container);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected addBundles(): void
|
||||||
|
{
|
||||||
|
const importedMods = this.preAkiModLoader.getImportedModDetails();
|
||||||
|
for (const [mod, pkg] of Object.entries(importedMods))
|
||||||
|
{
|
||||||
|
const modPath = this.preAkiModLoader.getModPath(mod);
|
||||||
|
|
||||||
|
if (pkg.isBundleMod ?? false)
|
||||||
|
{
|
||||||
|
this.bundleLoader.addBundles(modPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import path from "node:path";
|
|||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
import { DependencyContainer, inject, injectable } from "tsyringe";
|
import { DependencyContainer, inject, injectable } from "tsyringe";
|
||||||
|
|
||||||
import { BundleLoader } from "@spt-aki/loaders/BundleLoader";
|
|
||||||
import { ModLoadOrder } from "@spt-aki/loaders/ModLoadOrder";
|
import { ModLoadOrder } from "@spt-aki/loaders/ModLoadOrder";
|
||||||
import { ModTypeCheck } from "@spt-aki/loaders/ModTypeCheck";
|
import { ModTypeCheck } from "@spt-aki/loaders/ModTypeCheck";
|
||||||
import { ModDetails } from "@spt-aki/models/eft/profile/IAkiProfile";
|
import { ModDetails } from "@spt-aki/models/eft/profile/IAkiProfile";
|
||||||
@ -24,7 +23,7 @@ import { VFS } from "@spt-aki/utils/VFS";
|
|||||||
@injectable()
|
@injectable()
|
||||||
export class PreAkiModLoader implements IModLoader
|
export class PreAkiModLoader implements IModLoader
|
||||||
{
|
{
|
||||||
protected static container: DependencyContainer;
|
protected container: DependencyContainer;
|
||||||
|
|
||||||
protected readonly basepath = "user/mods/";
|
protected readonly basepath = "user/mods/";
|
||||||
protected readonly modOrderPath = "user/mods/order.json";
|
protected readonly modOrderPath = "user/mods/order.json";
|
||||||
@ -39,7 +38,6 @@ export class PreAkiModLoader implements IModLoader
|
|||||||
@inject("VFS") protected vfs: VFS,
|
@inject("VFS") protected vfs: VFS,
|
||||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||||
@inject("ModCompilerService") protected modCompilerService: ModCompilerService,
|
@inject("ModCompilerService") protected modCompilerService: ModCompilerService,
|
||||||
@inject("BundleLoader") protected bundleLoader: BundleLoader,
|
|
||||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
||||||
@inject("ModLoadOrder") protected modLoadOrder: ModLoadOrder,
|
@inject("ModLoadOrder") protected modLoadOrder: ModLoadOrder,
|
||||||
@ -57,9 +55,9 @@ export class PreAkiModLoader implements IModLoader
|
|||||||
{
|
{
|
||||||
if (globalThis.G_MODS_ENABLED)
|
if (globalThis.G_MODS_ENABLED)
|
||||||
{
|
{
|
||||||
PreAkiModLoader.container = container;
|
this.container = container;
|
||||||
await this.importModsAsync();
|
await this.importModsAsync();
|
||||||
await this.executeModsAsync(container);
|
await this.executeModsAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,10 +361,9 @@ export class PreAkiModLoader implements IModLoader
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute each mod found in this.imported
|
* Execute each mod found in this.imported
|
||||||
* @param container Dependence container to give to mod when it runs
|
|
||||||
* @returns void promise
|
* @returns void promise
|
||||||
*/
|
*/
|
||||||
protected async executeModsAsync(container: DependencyContainer): Promise<void>
|
protected async executeModsAsync(): Promise<void>
|
||||||
{
|
{
|
||||||
// Sort mods load order
|
// Sort mods load order
|
||||||
const source = this.sortModsLoadOrder();
|
const source = this.sortModsLoadOrder();
|
||||||
@ -401,7 +398,7 @@ export class PreAkiModLoader implements IModLoader
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await (requiredMod.mod as IPreAkiLoadModAsync).preAkiLoadAsync(container);
|
await (requiredMod.mod as IPreAkiLoadModAsync).preAkiLoadAsync(this.container);
|
||||||
globalThis[mod] = requiredMod;
|
globalThis[mod] = requiredMod;
|
||||||
}
|
}
|
||||||
catch (err)
|
catch (err)
|
||||||
@ -420,7 +417,7 @@ export class PreAkiModLoader implements IModLoader
|
|||||||
// Perform sync load of mod
|
// Perform sync load of mod
|
||||||
if (this.modTypeCheck.isPreAkiLoad(requiredMod.mod))
|
if (this.modTypeCheck.isPreAkiLoad(requiredMod.mod))
|
||||||
{
|
{
|
||||||
(requiredMod.mod as IPreAkiLoadMod).preAkiLoad(container);
|
(requiredMod.mod as IPreAkiLoadMod).preAkiLoad(this.container);
|
||||||
globalThis[mod] = requiredMod;
|
globalThis[mod] = requiredMod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -450,13 +447,6 @@ export class PreAkiModLoader implements IModLoader
|
|||||||
{
|
{
|
||||||
const modPath = this.getModPath(mod);
|
const modPath = this.getModPath(mod);
|
||||||
|
|
||||||
const isBundleMod = pkg.isBundleMod ?? false;
|
|
||||||
|
|
||||||
if (isBundleMod)
|
|
||||||
{
|
|
||||||
this.bundleLoader.addBundles(modPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
const typeScriptFiles = this.vfs.getFilesOfType(`${modPath}src`, ".ts");
|
const typeScriptFiles = this.vfs.getFilesOfType(`${modPath}src`, ".ts");
|
||||||
|
|
||||||
if (typeScriptFiles.length > 0)
|
if (typeScriptFiles.length > 0)
|
||||||
@ -736,9 +726,9 @@ export class PreAkiModLoader implements IModLoader
|
|||||||
|
|
||||||
public getContainer(): DependencyContainer
|
public getContainer(): DependencyContainer
|
||||||
{
|
{
|
||||||
if (PreAkiModLoader.container)
|
if (this.container)
|
||||||
{
|
{
|
||||||
return PreAkiModLoader.container;
|
return this.container;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(this.localisationService.getText("modloader-dependency_container_not_initalized"));
|
throw new Error(this.localisationService.getText("modloader-dependency_container_not_initalized"));
|
||||||
|
Loading…
Reference in New Issue
Block a user