Server/project/src/controllers/PresetController.ts

36 lines
969 B
TypeScript
Raw Normal View History

2023-03-03 15:23:46 +00:00
import { inject, injectable } from "tsyringe";
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
import { IPreset } from "@spt-aki/models/eft/common/IGlobals";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
2023-03-03 15:23:46 +00:00
@injectable()
export class PresetController
{
constructor(
@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: IPreset[] = Object.values(this.databaseServer.getTables().globals.ItemPresets);
2023-03-03 15:23:46 +00:00
const reverse: Record<string, string[]> = {};
for (const preset of presets)
{
const tpl = preset._items[0]._tpl;
if (!(tpl in reverse))
{
reverse[tpl] = [];
}
reverse[tpl].push(preset._id);
}
this.presetHelper.hydratePresetStore(reverse);
}
}