1
0
forked from noxious/server

Improvements to weatherManager

This commit is contained in:
Dennis Postma 2024-12-28 22:17:57 +01:00
parent f5c4f3df19
commit 6e58de8840

View File

@ -1,6 +1,6 @@
import { Server } from 'socket.io'
import { appLogger } from '#application/logger'
import Logger, { LoggerType } from '#application/logger'
import worldRepository from '#repositories/worldRepository'
import worldService from '#services/worldService'
@ -15,6 +15,7 @@ class WeatherManager {
private static readonly UPDATE_INTERVAL = 60000 // Check weather every minute
private static readonly RAIN_CHANCE = 0.2 // 20% chance of rain
private static readonly FOG_CHANCE = 0.15 // 15% chance of fog
private readonly logger = Logger.type(LoggerType.APP)
private io: Server | null = null
private intervalId: NodeJS.Timeout | null = null
@ -29,7 +30,7 @@ class WeatherManager {
// this.io = io
// await this.loadWeather()
// this.startWeatherLoop()
appLogger.info('Weather manager loaded')
this.logger.info('Weather manager loaded')
}
public async toggleRain(): Promise<void> {
@ -65,7 +66,7 @@ class WeatherManager {
}
}
} catch (error) {
appLogger.error(`Failed to load weather: ${error instanceof Error ? error.message : String(error)}`)
this.logger.error(`Failed to load weather: ${error instanceof Error ? error.message : String(error)}`)
}
}
@ -78,7 +79,7 @@ class WeatherManager {
this.updateWeather()
this.emitWeather()
await this.saveWeather().catch((error) => {
appLogger.error(`Failed to save weather: ${error instanceof Error ? error.message : String(error)}`)
this.logger.error(`Failed to save weather: ${error instanceof Error ? error.message : String(error)}`)
})
}, WeatherManager.UPDATE_INTERVAL)
}
@ -114,7 +115,7 @@ class WeatherManager {
fogDensity: this.weatherState.fogDensity
})
} catch (error) {
appLogger.error(`Failed to save weather: ${error instanceof Error ? error.message : String(error)}`)
this.logger.error(`Failed to save weather: ${error instanceof Error ? error.message : String(error)}`)
}
}