From 2fa1d1825135b514acb1786b3153a38df8e2ebd3 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 22 Dec 2022 11:44:39 +0000 Subject: [PATCH] Clean up add trader example --- TypeScript/13AddTrader/src/mod.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/TypeScript/13AddTrader/src/mod.ts b/TypeScript/13AddTrader/src/mod.ts index cd60713..8a4c62d 100644 --- a/TypeScript/13AddTrader/src/mod.ts +++ b/TypeScript/13AddTrader/src/mod.ts @@ -13,6 +13,7 @@ import { ITraderAssort, ITraderBase } from "@spt-aki/models/eft/common/tables/IT import { ITraderConfig, UpdateTime } from "@spt-aki/models/spt/config/ITraderConfig"; import { JsonUtil } from "@spt-aki/utils/JsonUtil"; import { Item } from "@spt-aki/models/eft/common/tables/IItem"; +import { IDatabaseTables } from "@spt-aki/models/spt/server/IDatabaseTables"; // The new trader config import * as baseJson from "../db/base.json"; @@ -39,7 +40,7 @@ class SampleTrader implements IPreAkiLoadMod, IPostDBLoadMod { public postDBLoad(container: DependencyContainer): void { this.logger.debug(`[${this.mod}] Delayed Loading... `); - const databaseServer = container.resolve("DatabaseServer"); + const databaseServer: DatabaseServer = container.resolve("DatabaseServer"); const jsonUtil = container.resolve("JsonUtil"); // Keep a reference to the tables @@ -52,16 +53,8 @@ class SampleTrader implements IPreAkiLoadMod, IPostDBLoadMod { questassort: undefined }; - // For each language, add locale for the new trader - const locales = Object.values(tables.locales.global) as Record[]; - for (const locale of locales) { - locale[`${baseJson._id} FullName`] = baseJson.name; - locale[`${baseJson._id} FirstName`] = "Cat"; - locale[`${baseJson._id} Nickname`] = baseJson.nickname; - locale[`${baseJson._id} Nickname`] = baseJson.nickname; - locale[`${baseJson._id} Location`] = baseJson.location; - locale[`${baseJson._id} Description`] = "This is the cat shop"; - } + this.addTraderToLocales(tables, baseJson.name, "Cat", baseJson.nickname, baseJson.location, "This is the cat shop"); + this.logger.debug(`[${this.mod}] Delayed Loaded`); } @@ -124,6 +117,19 @@ class SampleTrader implements IPreAkiLoadMod, IPostDBLoadMod { return assortTable; } + + private addTraderToLocales(tables: IDatabaseTables, fullName: string, firstName: string, nickName: string, location: string, description: string) + { + // For each language, add locale for the new trader + const locales = Object.values(tables.locales.global) as Record[]; + for (const locale of locales) { + locale[`${baseJson._id} FullName`] = fullName; + locale[`${baseJson._id} FirstName`] = firstName; + locale[`${baseJson._id} Nickname`] = nickName; + locale[`${baseJson._id} Location`] = location; + locale[`${baseJson._id} Description`] = description; + } + } } module.exports = { mod: new SampleTrader() } \ No newline at end of file