2023-03-03 15:23:46 +00:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2023-10-19 17:21:17 +00:00
|
|
|
import { PresetHelper } from "@spt-aki/helpers/PresetHelper";
|
|
|
|
import { IPreset } from "@spt-aki/models/eft/common/IGlobals";
|
2024-02-24 23:26:27 +00:00
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
2023-10-19 17:21:17 +00:00
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class PresetController
|
|
|
|
{
|
|
|
|
constructor(
|
2024-02-24 23:26:27 +00:00
|
|
|
@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
|
|
|
|
{
|
2024-02-24 23:26:27 +00:00
|
|
|
const presets: [string, IPreset][] = Object.entries(this.databaseServer.getTables().globals.ItemPresets);
|
2023-03-03 15:23:46 +00:00
|
|
|
const reverse: Record<string, string[]> = {};
|
|
|
|
|
2024-02-24 23:26:27 +00:00
|
|
|
for (const [id, preset] of presets)
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2024-02-25 11:54:13 +00:00
|
|
|
if (id !== preset._id)
|
2024-02-24 23:26:27 +00:00
|
|
|
{
|
2024-02-25 11:54:13 +00:00
|
|
|
this.logger.error(
|
|
|
|
`Preset for template tpl: '${
|
|
|
|
preset._items[0]._tpl
|
|
|
|
} ${preset._name}' has invalid key: (${id} != ${preset._id}). Skipping`,
|
|
|
|
);
|
|
|
|
|
2024-02-24 23:26:27 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|