#184: Added weather manager that periodically changes the weather in-game and emits this to players

This commit is contained in:
2024-11-05 22:45:57 +01:00
parent 3a566dae5a
commit ae0241fecb
3 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import { Server } from 'socket.io'
import { TSocket } from '../utilities/types'
import { gameLogger } from '../utilities/logger'
import WeatherManager from '../managers/weatherManager'
export default class Weather {
constructor(
private readonly io: Server,
private readonly socket: TSocket
) {}
public listen(): void {
this.socket.on('weather', this.handleEvent.bind(this))
}
private async handleEvent(): Promise<void> {
try {
const weather = await WeatherManager.getWeatherState()
this.socket.emit('weather', weather)
} catch (error: any) {
gameLogger.error('error', error.message)
}
}
}