From 4f9a1bc879b0e4b88f3b611580b3b573df9888e9 Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Mon, 30 Sep 2024 22:42:46 +0200 Subject: [PATCH] npm run dev --- src/commands/alert.ts | 2 +- src/commands/listZones.ts | 2 +- src/commands/tiles.ts | 26 +++++++++++++------------- src/managers/commandManager.ts | 12 +++++++++--- src/server.ts | 2 +- src/utilities/logger.ts | 9 +-------- 6 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/commands/alert.ts b/src/commands/alert.ts index ee3302c..ab9cce3 100644 --- a/src/commands/alert.ts +++ b/src/commands/alert.ts @@ -10,4 +10,4 @@ export default class AlertCommand { if (!message) return console.log('message is required') this.io.emit('notification', { message: message }) } -} \ No newline at end of file +} diff --git a/src/commands/listZones.ts b/src/commands/listZones.ts index 4d1d2da..d0992a6 100644 --- a/src/commands/listZones.ts +++ b/src/commands/listZones.ts @@ -9,4 +9,4 @@ export default class ListZonesCommand { public execute(input: CommandInput): void { console.log(ZoneManager.getLoadedZones()) } -} \ No newline at end of file +} diff --git a/src/commands/tiles.ts b/src/commands/tiles.ts index ca15b63..d55f905 100644 --- a/src/commands/tiles.ts +++ b/src/commands/tiles.ts @@ -9,24 +9,24 @@ export default class TilesCommand { public async execute(): Promise { // Get all tiles - const tilesDir = path.join(process.cwd(), 'public', 'tiles'); - const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png')); + const tilesDir = path.join(process.cwd(), 'public', 'tiles') + const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png')) // Create output directory if it doesn't exist if (!fs.existsSync(tilesDir)) { - fs.mkdirSync(tilesDir, { recursive: true }); + fs.mkdirSync(tilesDir, { recursive: true }) } for (const tile of tiles) { // Check if tile is already 66x34 - const metadata = await sharp(path.join(tilesDir, tile)).metadata(); + const metadata = await sharp(path.join(tilesDir, tile)).metadata() if (metadata.width === 66 && metadata.height === 34) { - commandLogger.info(`Tile ${tile} already processed`); - continue; + commandLogger.info(`Tile ${tile} already processed`) + continue } - const inputPath = path.join(tilesDir, tile); - const outputPath = path.join(tilesDir, tile); + const inputPath = path.join(tilesDir, tile) + const outputPath = path.join(tilesDir, tile) try { await sharp(inputPath) @@ -36,14 +36,14 @@ export default class TilesCommand { fit: 'fill', kernel: 'nearest' }) - .toFile(outputPath); + .toFile(outputPath) - commandLogger.info(`Processed: ${tile}`); + commandLogger.info(`Processed: ${tile}`) } catch (error) { - console.error(`Error processing ${tile}:`, error); + console.error(`Error processing ${tile}:`, error) } } - commandLogger.info('Tile processing completed.'); + commandLogger.info('Tile processing completed.') } -} \ No newline at end of file +} diff --git a/src/managers/commandManager.ts b/src/managers/commandManager.ts index fe5d320..d39f753 100644 --- a/src/managers/commandManager.ts +++ b/src/managers/commandManager.ts @@ -67,9 +67,15 @@ class CommandManager { for (const file of files) { try { - const extension = config.ENV === 'development' ? '.ts' : '.js' + const extension = path.extname(file) const commandName = path.basename(file, extension) - const commandPath = path.join(commandsDir, `${commandName}${extension}`) + + let commandPath: string + commandPath = path.join(commandsDir, `${commandName}.js`) + + if (config.ENV === 'development') { + commandPath = path.join(commandsDir, `${commandName}.ts`) + } if (!fs.existsSync(commandPath)) { commandLogger.warn(`Command file not found: ${commandPath}`) @@ -104,4 +110,4 @@ class CommandManager { } } -export default new CommandManager() \ No newline at end of file +export default new CommandManager() diff --git a/src/server.ts b/src/server.ts index de1628a..c191854 100644 --- a/src/server.ts +++ b/src/server.ts @@ -74,7 +74,7 @@ export class Server { await CharacterManager.boot() // Load command manager - await CommandManager.boot(this.io); + await CommandManager.boot(this.io) // Listen for socket connections this.io.on('connection', this.handleConnection.bind(this)) diff --git a/src/utilities/logger.ts b/src/utilities/logger.ts index 44b1b0e..7ac4eaf 100644 --- a/src/utilities/logger.ts +++ b/src/utilities/logger.ts @@ -43,13 +43,6 @@ const watchLogs = () => { }) } -export const { - http: httpLogger, - game: gameLogger, - gameMaster: gameMasterLogger, - app: appLogger, - queue: queueLogger, - command: commandLogger -} = loggers +export const { http: httpLogger, game: gameLogger, gameMaster: gameMasterLogger, app: appLogger, queue: queueLogger, command: commandLogger } = loggers export { watchLogs }