Server/project/src/controllers/PresetController.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-03-03 15:23:46 +00:00
import { inject, injectable } from "tsyringe";
import { PresetHelper } from "@spt/helpers/PresetHelper";
import { IPreset } from "@spt/models/eft/common/IGlobals";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
2023-03-03 15:23:46 +00:00
@injectable()
export class PresetController
{
constructor(
@inject("WinstonLogger") protected logger: ILogger,
2023-03-03 15:23:46 +00:00
@inject("PresetHelper") protected presetHelper: PresetHelper,
2023-11-15 20:35:05 -05:00
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
2023-03-03 15:23:46 +00:00
)
2023-11-15 20:35:05 -05:00
{}
2023-03-03 15:23:46 +00:00
public initialize(): void
{
const presets: [string, IPreset][] = Object.entries(this.databaseServer.getTables().globals.ItemPresets);
2023-03-03 15:23:46 +00:00
const reverse: Record<string, string[]> = {};
for (const [id, preset] of presets)
2023-03-03 15:23:46 +00:00
{
if (id !== preset._id)
{
this.logger.error(
`Preset for template tpl: '${preset._items[0]._tpl} ${preset._name}' has invalid key: (${id} != ${preset._id}). Skipping`,
);
continue;
}
2023-03-03 15:23:46 +00:00
const tpl = preset._items[0]._tpl;
if (!(tpl in reverse))
{
reverse[tpl] = [];
}
reverse[tpl].push(preset._id);
}
this.presetHelper.hydratePresetStore(reverse);
}
}