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