Continuation of refactor

This commit is contained in:
2024-12-28 20:40:05 +01:00
parent 6dda79f8b2
commit e1a6f650fb
27 changed files with 158 additions and 236 deletions

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'
@ -11,12 +11,13 @@ class DateManager {
private io: Server | null = null
private intervalId: NodeJS.Timeout | null = null
private currentDate: Date = new Date()
private logger = Logger.type(LoggerType.APP)
public async boot(io: Server): Promise<void> {
this.io = io
await this.loadDate()
this.startDateLoop()
appLogger.info('Date manager loaded')
this.logger.info('Date manager loaded')
}
public async setTime(time: string): Promise<void> {
@ -38,7 +39,7 @@ class DateManager {
this.emitDate()
await this.saveDate()
} catch (error) {
appLogger.error(`Failed to set time: ${error instanceof Error ? error.message : String(error)}`)
this.logger.error(`Failed to set time: ${error instanceof Error ? error.message : String(error)}`)
throw error
}
}
@ -51,7 +52,7 @@ class DateManager {
this.currentDate = world.date
}
} catch (error) {
appLogger.error(`Failed to load date: ${error instanceof Error ? error.message : String(error)}`)
this.logger.error(`Failed to load date: ${error instanceof Error ? error.message : String(error)}`)
this.currentDate = new Date() // Use current date as fallback
}
}
@ -82,7 +83,7 @@ class DateManager {
date: this.currentDate
})
} catch (error) {
appLogger.error(`Failed to save date: ${error instanceof Error ? error.message : String(error)}`)
this.logger.error(`Failed to save date: ${error instanceof Error ? error.message : String(error)}`)
}
}