0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/loaders/PostAkiModLoader.ts
Refringe 4ac12ef70a Formatting/Linting Changes (!168)
These are the formatting & linting configuration changes from the `3.8.0` branch and the changes that they make to the overall project.

The majority of these changes are from running two commands:

`npm run lint:fix`
`npm run style:fix`

This has already been run on the `3.8.0` branch and this PR should make `master` play nicer when it comes to merges going forward.

There are now four VSCode plugins recommended for server development. They've been added to the workspace file and a user should get a UI notification when the workspace is opened if they're not installed.

The four plugins are:
https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig
https://marketplace.visualstudio.com/items?itemName=dprint.dprint
https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
https://marketplace.visualstudio.com/items?itemName=biomejs.biome

Once installed they should just work within the workspace.

Also, be sure to `npm i` to get the new dprint application.

Co-authored-by: Refringe <brownelltyler@gmail.com>
Reviewed-on: SPT-AKI/Server#168
2023-11-16 21:42:06 +00:00

91 lines
3.2 KiB
TypeScript

import { DependencyContainer, inject, injectable } from "tsyringe";
import { BundleLoader } from "@spt-aki/loaders/BundleLoader";
import { ModTypeCheck } from "@spt-aki/loaders/ModTypeCheck";
import { PreAkiModLoader } from "@spt-aki/loaders/PreAkiModLoader";
import { IPostAkiLoadMod } from "@spt-aki/models/external/IPostAkiLoadMod";
import { IPostAkiLoadModAsync } from "@spt-aki/models/external/IPostAkiLoadModAsync";
import { IModLoader } from "@spt-aki/models/spt/mod/IModLoader";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { LocalisationService } from "@spt-aki/services/LocalisationService";
import { VFS } from "@spt-aki/utils/VFS";
@injectable()
export class PostAkiModLoader implements IModLoader
{
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("BundleLoader") protected bundleLoader: BundleLoader,
@inject("VFS") protected vfs: VFS,
@inject("PreAkiModLoader") protected preAkiModLoader: PreAkiModLoader,
@inject("LocalisationService") protected localisationService: LocalisationService,
@inject("ModTypeCheck") protected modTypeCheck: ModTypeCheck,
)
{}
public getModPath(mod: string): string
{
return this.preAkiModLoader.getModPath(mod);
}
public async load(): Promise<void>
{
if (globalThis.G_MODS_ENABLED)
{
await this.executeMods(this.preAkiModLoader.getContainer());
this.addBundles();
}
}
protected async executeMods(container: DependencyContainer): Promise<void>
{
const mods = this.preAkiModLoader.sortModsLoadOrder();
for (const modName of mods)
{
// // import class
const filepath = `${this.preAkiModLoader.getModPath(modName)}${
this.preAkiModLoader.getImportedModDetails()[modName].main
}`;
const modpath = `${process.cwd()}/${filepath}`;
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mod = require(modpath);
if (this.modTypeCheck.isPostAkiLoadAsync(mod.mod))
{
try
{
await (mod.mod as IPostAkiLoadModAsync).postAkiLoadAsync(container);
}
catch (err)
{
this.logger.error(
this.localisationService.getText(
"modloader-async_mod_error",
`${err?.message ?? ""}\n${err.stack ?? ""}`,
),
);
}
}
if (this.modTypeCheck.isPostAkiLoad(mod.mod))
{
(mod.mod as IPostAkiLoadMod).postAkiLoad(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);
}
}
}
}