From 83a35cbc8cef03edffc289c0418c521158dd7c90 Mon Sep 17 00:00:00 2001 From: CWX Date: Fri, 5 Jul 2024 14:21:30 +0100 Subject: [PATCH] implement localweather for pve mode --- project/src/callbacks/WeatherCallbacks.ts | 6 ++++++ project/src/controllers/WeatherController.ts | 12 ++++++++++++ .../spt/weather/IGetLocalWeatherResponseData.ts | 7 +++++++ project/src/routers/static/WeatherStaticRouter.ts | 14 ++++++++++++++ 4 files changed, 39 insertions(+) create mode 100644 project/src/models/spt/weather/IGetLocalWeatherResponseData.ts diff --git a/project/src/callbacks/WeatherCallbacks.ts b/project/src/callbacks/WeatherCallbacks.ts index dfbef05b..975632ea 100644 --- a/project/src/callbacks/WeatherCallbacks.ts +++ b/project/src/callbacks/WeatherCallbacks.ts @@ -4,6 +4,7 @@ import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData"; import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData"; import { IWeatherData } from "@spt/models/eft/weather/IWeatherData"; import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil"; +import { IGetLocalWeatherResponseData } from "@spt/models/spt/weather/IGetLocalWeatherResponseData"; @injectable() export class WeatherCallbacks @@ -22,4 +23,9 @@ export class WeatherCallbacks { return this.httpResponse.getBody(this.weatherController.generate()); } + + public getLocalWeather(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData + { + return this.httpResponse.getBody(this.weatherController.generateLocal(sessionID)); + } } diff --git a/project/src/controllers/WeatherController.ts b/project/src/controllers/WeatherController.ts index f3b28352..5ab34fb3 100644 --- a/project/src/controllers/WeatherController.ts +++ b/project/src/controllers/WeatherController.ts @@ -5,6 +5,8 @@ import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; import { IWeatherConfig } from "@spt/models/spt/config/IWeatherConfig"; import { ILogger } from "@spt/models/spt/utils/ILogger"; import { ConfigServer } from "@spt/servers/ConfigServer"; +import { IGetLocalWeatherResponseData } from "@spt/models/spt/weather/IGetLocalWeatherResponseData"; +import { SeasonalEventService } from "@spt/services/SeasonalEventService"; @injectable() export class WeatherController @@ -15,6 +17,7 @@ export class WeatherController @inject("WeatherGenerator") protected weatherGenerator: WeatherGenerator, @inject("PrimaryLogger") protected logger: ILogger, @inject("ConfigServer") protected configServer: ConfigServer, + @inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService, ) { this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER); @@ -39,4 +42,13 @@ export class WeatherController { return this.weatherGenerator.getInRaidTime(); } + + public generateLocal(sesssionID: string): IGetLocalWeatherResponseData + { + let result: IGetLocalWeatherResponseData = { season: this.seasonalEventService.getActiveWeatherSeason(), weather: [] }; + + result.weather.push(this.weatherGenerator.generateWeather()); + + return result; + } } diff --git a/project/src/models/spt/weather/IGetLocalWeatherResponseData.ts b/project/src/models/spt/weather/IGetLocalWeatherResponseData.ts new file mode 100644 index 00000000..6b263c7c --- /dev/null +++ b/project/src/models/spt/weather/IGetLocalWeatherResponseData.ts @@ -0,0 +1,7 @@ +import { IWeather } from "@spt/models/eft/weather/IWeatherData"; + +export interface IGetLocalWeatherResponseData +{ + season: number; + weather: IWeather[]; +} \ No newline at end of file diff --git a/project/src/routers/static/WeatherStaticRouter.ts b/project/src/routers/static/WeatherStaticRouter.ts index dac05b6e..52e7846b 100644 --- a/project/src/routers/static/WeatherStaticRouter.ts +++ b/project/src/routers/static/WeatherStaticRouter.ts @@ -3,6 +3,7 @@ import { WeatherCallbacks } from "@spt/callbacks/WeatherCallbacks"; import { RouteAction, StaticRouter } from "@spt/di/Router"; import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData"; import { IWeatherData } from "@spt/models/eft/weather/IWeatherData"; +import { IGetLocalWeatherResponseData } from "@spt/models/spt/weather/IGetLocalWeatherResponseData"; @injectable() export class WeatherStaticRouter extends StaticRouter @@ -22,6 +23,19 @@ export class WeatherStaticRouter extends StaticRouter return this.weatherCallbacks.getWeather(url, info, sessionID); }, ), + + new RouteAction( + "/client/localGame/weather", + async ( + url: string, + info: any, + sessionID: string, + _output: string + ): Promise> => + { + return this.weatherCallbacks.getLocalWeather(url, info, sessionID); + }, + ), ]); } }