forked from noxious/server
#184: Added weather manager that periodically changes the weather in-game and emits this to players
This commit is contained in:
24
src/socketEvents/weather.ts
Normal file
24
src/socketEvents/weather.ts
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user