forked from noxious/server
#184: Added commands to toggle rain / fog, command bug fix, minor improvements
This commit is contained in:
@ -31,6 +31,32 @@ class WeatherManager {
|
||||
appLogger.info('Weather manager loaded')
|
||||
}
|
||||
|
||||
public async toggleRain(): Promise<void> {
|
||||
this.weatherState.isRainEnabled = !this.weatherState.isRainEnabled
|
||||
this.weatherState.rainPercentage = this.weatherState.isRainEnabled
|
||||
? Math.floor(Math.random() * 50) + 50 // 50-100%
|
||||
: 0
|
||||
|
||||
// Save weather
|
||||
await this.saveWeather()
|
||||
|
||||
// Emit weather
|
||||
this.emitWeather()
|
||||
}
|
||||
|
||||
public async toggleFog(): Promise<void> {
|
||||
this.weatherState.isFogEnabled = !this.weatherState.isFogEnabled
|
||||
this.weatherState.fogDensity = this.weatherState.isFogEnabled
|
||||
? Math.random() * 0.7 + 0.3 // 0.3-1.0
|
||||
: 0
|
||||
|
||||
// Save weather
|
||||
await this.saveWeather()
|
||||
|
||||
// Emit weather
|
||||
this.emitWeather()
|
||||
}
|
||||
|
||||
private async loadWeather(): Promise<void> {
|
||||
try {
|
||||
this.weatherState.isRainEnabled = await readJsonValue<boolean>(this.getWorldFilePath(), 'isRainEnabled')
|
||||
@ -50,7 +76,9 @@ class WeatherManager {
|
||||
this.intervalId = setInterval(() => {
|
||||
this.updateWeather()
|
||||
this.emitWeather()
|
||||
this.saveWeather()
|
||||
this.saveWeather().catch((error) => {
|
||||
appLogger.error(`Failed to save weather: ${error instanceof Error ? error.message : String(error)}`)
|
||||
})
|
||||
}, WeatherManager.UPDATE_INTERVAL)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user