2022-05-25 13:35:25 +01:00
|
|
|
import type { DependencyContainer } from "tsyringe";
|
2022-06-08 22:09:11 +01:00
|
|
|
import { IMod } from "@spt-aki/models/external/mod";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { DynamicRouterModService } from "@spt-aki/services/mod/dynamicRouter/DynamicRouterModService"
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"
|
|
|
|
import { JsonUtil } from "@spt-aki/utils/JsonUtil"
|
|
|
|
import { InitialModLoader } from "@spt-aki/loaders/InitialModLoader"
|
2022-05-25 13:35:25 +01:00
|
|
|
|
|
|
|
class HideoutArchitect implements IMod
|
|
|
|
{
|
2022-06-08 22:09:11 +01:00
|
|
|
private path;
|
2022-05-25 13:35:25 +01:00
|
|
|
private logger: ILogger;
|
|
|
|
private database: DatabaseServer;
|
|
|
|
private router: DynamicRouterModService;
|
|
|
|
private json: JsonUtil;
|
|
|
|
private globalLocale;
|
|
|
|
private modLoader: InitialModLoader;
|
|
|
|
private mod;
|
|
|
|
private translations;
|
|
|
|
private table;
|
|
|
|
|
|
|
|
public load(container: DependencyContainer)
|
|
|
|
{
|
|
|
|
this.logger = container.resolve<ILogger>("WinstonLogger");
|
|
|
|
this.router = container.resolve<DynamicRouterModService>("DynamicRouterModService");
|
2022-06-08 22:09:11 +01:00
|
|
|
this.path = require("path");
|
2022-05-25 13:35:25 +01:00
|
|
|
this.json = container.resolve<JsonUtil>("JsonUtil");
|
|
|
|
this.mod = require("../package.json");
|
|
|
|
this.translations = require("../res/translations.json");
|
2022-06-22 19:25:21 +01:00
|
|
|
this.logger.info(`Loading: ${this.mod.author}: ${this.mod.name} - ${this.mod.version}`);
|
2022-05-25 13:35:25 +01:00
|
|
|
this.hookRoutes();
|
2022-06-08 22:09:11 +01:00
|
|
|
|
2022-05-25 13:35:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public delayedLoad(container: DependencyContainer)
|
|
|
|
{
|
|
|
|
this.modLoader = container.resolve<InitialModLoader>("InitialModLoader");
|
|
|
|
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];
|
2022-05-25 13:35:25 +01:00
|
|
|
|
|
|
|
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-05-25 13:35:25 +01:00
|
|
|
{
|
2022-06-08 22:09:11 +01:00
|
|
|
const modOutput = {
|
2022-05-25 13:35:25 +01:00
|
|
|
status: 1,
|
|
|
|
data: null
|
|
|
|
};
|
|
|
|
|
2022-06-08 22:09:11 +01:00
|
|
|
modOutput.data = {...this.mod, ...{path: this.path.resolve(this.modLoader.getModPath(this.mod.name))}};
|
2022-05-25 13:35:25 +01:00
|
|
|
modOutput.status = 0;
|
|
|
|
|
|
|
|
return this.json.serialize(modOutput);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { mod: new HideoutArchitect() };
|