Server/project/src/controllers/WeatherController.ts

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { inject, injectable } from "tsyringe";
import { WeatherGenerator } from "@spt-aki/generators/WeatherGenerator";
import { IWeatherData } from "@spt-aki/models/eft/weather/IWeatherData";
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
import { IWeatherConfig } from "@spt-aki/models/spt/config/IWeatherConfig";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
2023-03-03 16:23:46 +01:00
@injectable()
export class WeatherController
{
protected weatherConfig: IWeatherConfig;
constructor(
@inject("WeatherGenerator") protected weatherGenerator: WeatherGenerator,
@inject("WinstonLogger") protected logger: ILogger,
@inject("ConfigServer") protected configServer: ConfigServer,
2023-03-03 16:23:46 +01:00
)
{
this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER);
}
2023-07-15 15:49:25 +02:00
/** Handle client/weather */
2023-03-03 16:23:46 +01:00
public generate(): IWeatherData
{
let result: IWeatherData = { acceleration: 0, time: "", date: "", weather: null };
2023-03-03 16:23:46 +01:00
result = this.weatherGenerator.calculateGameTime(result);
result.weather = this.weatherGenerator.generateWeather();
return result;
}
/**
* Get the current in-raid time (MUST HAVE PLAYER LOGGED INTO CLIENT TO WORK)
* @returns Date object
*/
public getCurrentInRaidTime(): Date
{
return this.weatherGenerator.getInRaidTime(new Date());
}
}