forked from noxious/server
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { BaseService } from '#application/base/baseService'
|
|
import { World } from '#entities/world'
|
|
import WorldRepository from '#repositories/worldRepository'
|
|
|
|
class WorldService extends BaseService {
|
|
async update(worldData: Partial<World>): Promise<boolean> {
|
|
try {
|
|
let world = await WorldRepository.getFirst()
|
|
if (!world) {
|
|
world = new World()
|
|
}
|
|
|
|
world.setDate(worldData.date || new Date())
|
|
|
|
if (worldData.isRainEnabled) {
|
|
world.setIsRainEnabled(worldData.isRainEnabled)
|
|
}
|
|
if (worldData.rainPercentage) {
|
|
world.setRainPercentage(worldData.rainPercentage)
|
|
}
|
|
if (worldData.isFogEnabled) {
|
|
world.setIsFogEnabled(worldData.isFogEnabled)
|
|
}
|
|
if (worldData.fogDensity) {
|
|
world.setFogDensity(worldData.fogDensity)
|
|
}
|
|
|
|
await world.save()
|
|
|
|
return true
|
|
} catch (error: any) {
|
|
this.logger.error(`Failed to update world: ${error instanceof Error ? error.message : String(error)}`)
|
|
return false
|
|
}
|
|
}
|
|
}
|
|
|
|
export default new WorldService()
|