#184: Added commands to toggle rain / fog, command bug fix, minor improvements

This commit is contained in:
2024-11-05 23:15:56 +01:00
parent 26dbaa45a7
commit c4a42066ab
6 changed files with 160 additions and 12 deletions

View File

@ -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)
}