Server/project/src/callbacks/SaveCallbacks.ts

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { inject, injectable } from "tsyringe";
2023-03-03 16:23:46 +01:00
import { OnLoad } from "../di/OnLoad";
import { OnUpdate } from "../di/OnUpdate";
import { ConfigTypes } from "../models/enums/ConfigTypes";
import { ICoreConfig } from "../models/spt/config/ICoreConfig";
import { ConfigServer } from "../servers/ConfigServer";
2023-03-03 16:23:46 +01:00
import { SaveServer } from "../servers/SaveServer";
@injectable()
export class SaveCallbacks implements OnLoad, OnUpdate
{
protected coreConfig: ICoreConfig;
2023-03-03 16:23:46 +01:00
constructor(
@inject("SaveServer") protected saveServer: SaveServer,
@inject("ConfigServer") protected configServer: ConfigServer
2023-03-03 16:23:46 +01:00
)
{
this.coreConfig = this.configServer.getConfig(ConfigTypes.CORE);
2023-03-03 16:23:46 +01:00
}
public async onLoad(): Promise<void>
{
this.saveServer.load();
}
public getRoute(): string
{
return "aki-save";
}
public async onUpdate(secondsSinceLastRun: number): Promise<boolean>
{
// run every 15 seconds
if (secondsSinceLastRun > this.coreConfig.profileSaveIntervalSeconds)
2023-03-03 16:23:46 +01:00
{
this.saveServer.save();
return true;
}
return false;
}
}