Server/project/src/controllers/PresetController.ts

40 lines
1.3 KiB
TypeScript
Raw Normal View History

import { PresetHelper } from "@spt/helpers/PresetHelper";
import { IPreset } from "@spt/models/eft/common/IGlobals";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { DatabaseService } from "@spt/services/DatabaseService";
import { inject, injectable } from "tsyringe";
2023-03-03 15:23:46 +00:00
@injectable()
export class PresetController {
2023-03-03 15:23:46 +00:00
constructor(
@inject("PrimaryLogger") protected logger: ILogger,
2023-03-03 15:23:46 +00:00
@inject("PresetHelper") protected presetHelper: PresetHelper,
@inject("DatabaseService") protected databaseService: DatabaseService,
) {}
2023-03-03 15:23:46 +00:00
public initialize(): void {
const presets: [string, IPreset][] = Object.entries(this.databaseService.getGlobals().ItemPresets);
2023-03-03 15:23:46 +00:00
const reverse: Record<string, string[]> = {};
for (const [id, preset] of presets) {
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)) {
2023-03-03 15:23:46 +00:00
reverse[tpl] = [];
}
reverse[tpl].push(preset._id);
}
this.presetHelper.hydratePresetStore(reverse);
}
}