91 lines
2.9 KiB
TypeScript
Raw Normal View History

import type { DependencyContainer } from "tsyringe";
2022-07-27 22:01:10 +01:00
import { IPreAkiLoadMod } from "@spt-aki/models/external/IPreAkiLoadMod";
import { IPostAkiLoadMod } from "@spt-aki/models/external/IPostAkiLoadMod";
2022-06-08 22:09:11 +01:00
import { DynamicRouterModService } from "@spt-aki/services/mod/dynamicRouter/DynamicRouterModService"
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"
import { JsonUtil } from "@spt-aki/utils/JsonUtil"
2022-07-27 22:01:10 +01:00
import { PreAkiModLoader } from "@spt-aki/loaders/PreAkiModLoader";
2022-07-27 22:01:10 +01:00
class HideoutArchitect implements IPreAkiLoadMod, IPostAkiLoadMod
{
2022-06-08 22:09:11 +01:00
private path;
private database: DatabaseServer;
private router: DynamicRouterModService;
private json: JsonUtil;
private globalLocale;
2022-07-27 22:01:10 +01:00
private modLoader: PreAkiModLoader;
private mod;
private translations;
private table;
2022-07-27 22:01:10 +01:00
public preAkiLoad(container: DependencyContainer)
{
this.router = container.resolve<DynamicRouterModService>("DynamicRouterModService");
2022-06-08 22:09:11 +01:00
this.path = require("path");
this.json = container.resolve<JsonUtil>("JsonUtil");
this.mod = require("../package.json");
this.translations = require("../res/translations.json");
this.hookRoutes();
2022-06-08 22:09:11 +01:00
}
2022-07-27 22:01:10 +01:00
public postAkiLoad(container: DependencyContainer)
{
2022-07-27 22:01:10 +01:00
this.modLoader = container.resolve<PreAkiModLoader>("PreAkiModLoader");
this.database = container.resolve<DatabaseServer>("DatabaseServer");
this.table = this.database.getTables();
this.globalLocale = this.table.locales.global;
this.loadLocalization();
}
private loadLocalization()
{
2022-06-08 22:09:11 +01:00
for (const language in this.translations)
{
if (!(language in this.globalLocale))
{
continue;
}
const attrKvPair = this.translations[language];
for (const attrKey in attrKvPair)
{
const attrValue = attrKvPair[attrKey];
this.globalLocale[language].interface[attrKey] = attrValue;
}
}
}
private hookRoutes()
{
this.router.registerDynamicRouter(
"HideoutArchitect",
[
{
url: "/HideoutArchitect/GetInfo",
action: (url, info, sessionId, output) =>
{
return this.getModInfo(url, info, sessionId, output)
}
}
],
"HideoutArchitect"
)
}
2022-06-08 22:09:11 +01:00
private getModInfo(url: string, info: any, sessionId: string, output: string)
{
2022-06-08 22:09:11 +01:00
const modOutput = {
status: 1,
data: null
};
2022-07-27 22:01:10 +01:00
modOutput.data = {...this.mod, ...{path: this.path.resolve(this.modLoader.getModPath("HideoutArchitect"))}};
modOutput.status = 0;
return this.json.serialize(modOutput);
}
}
module.exports = { mod: new HideoutArchitect() };