Server/project/src/Program.ts

35 lines
1.3 KiB
TypeScript
Raw Normal View History

import { ErrorHandler } from "@spt/ErrorHandler";
import { Container } from "@spt/di/Container";
import type { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { App } from "@spt/utils/App";
import { Watermark } from "@spt/utils/Watermark";
import { container } from "tsyringe";
2023-03-03 16:23:46 +01:00
export class Program {
2023-03-03 16:23:46 +01:00
private errorHandler: ErrorHandler;
constructor() {
2023-03-03 16:23:46 +01:00
// set window properties
process.stdout.setEncoding("utf8");
process.title = "SPT Server";
2023-03-03 16:23:46 +01:00
this.errorHandler = new ErrorHandler();
}
2023-11-16 02:35:05 +01:00
public async start(): Promise<void> {
try {
2023-03-03 16:23:46 +01:00
Container.registerTypes(container);
const childContainer = container.createChildContainer();
const watermark = childContainer.resolve<Watermark>("Watermark");
watermark.initialize();
const preSptModLoader = childContainer.resolve<PreSptModLoader>("PreSptModLoader");
2023-03-03 16:23:46 +01:00
Container.registerListTypes(childContainer);
await preSptModLoader.load(childContainer);
Container.registerPostLoadTypes(container, childContainer);
childContainer.resolve<App>("App").load();
} catch (err: any) {
2023-11-16 02:35:05 +01:00
this.errorHandler.handleCriticalError(err instanceof Error ? err : new Error(err));
2023-03-03 16:23:46 +01:00
}
}
}