2024-05-21 17:59:04 +00:00
|
|
|
import { PresetHelper } from "@spt/helpers/PresetHelper";
|
|
|
|
import { IPreset } from "@spt/models/eft/common/IGlobals";
|
|
|
|
import { ILogger } from "@spt/models/spt/utils/ILogger";
|
2024-05-28 13:59:19 +01:00
|
|
|
import { DatabaseService } from "@spt/services/DatabaseService";
|
2024-07-23 11:12:53 -04:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
2024-07-23 11:12:53 -04:00
|
|
|
export class PresetController {
|
2023-03-03 15:23:46 +00:00
|
|
|
constructor(
|
2024-05-28 14:04:20 +00:00
|
|
|
@inject("PrimaryLogger") protected logger: ILogger,
|
2023-03-03 15:23:46 +00:00
|
|
|
@inject("PresetHelper") protected presetHelper: PresetHelper,
|
2024-05-28 13:59:19 +01:00
|
|
|
@inject("DatabaseService") protected databaseService: DatabaseService,
|
2024-07-23 11:12:53 -04:00
|
|
|
) {}
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
public initialize(): void {
|
2024-05-28 13:59:19 +01:00
|
|
|
const presets: [string, IPreset][] = Object.entries(this.databaseService.getGlobals().ItemPresets);
|
2023-03-03 15:23:46 +00:00
|
|
|
const reverse: Record<string, string[]> = {};
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
for (const [id, preset] of presets) {
|
|
|
|
if (id !== preset._id) {
|
2024-02-25 11:54:13 +00:00
|
|
|
this.logger.error(
|
2024-05-17 15:32:41 -04:00
|
|
|
`Preset for template tpl: '${preset._items[0]._tpl} ${preset._name}' has invalid key: (${id} != ${preset._id}). Skipping`,
|
2024-02-25 11:54:13 +00:00
|
|
|
);
|
|
|
|
|
2024-02-24 23:26:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
const tpl = preset._items[0]._tpl;
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
if (!(tpl in reverse)) {
|
2023-03-03 15:23:46 +00:00
|
|
|
reverse[tpl] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
reverse[tpl].push(preset._id);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.presetHelper.hydratePresetStore(reverse);
|
|
|
|
}
|
|
|
|
}
|