1
0
forked from noxious/server

npm run dev

This commit is contained in:
Dennis Postma 2024-09-30 22:42:46 +02:00
parent 3638e2a793
commit 4f9a1bc879
6 changed files with 26 additions and 27 deletions

View File

@ -9,24 +9,24 @@ export default class TilesCommand {
public async execute(): Promise<void> { public async execute(): Promise<void> {
// Get all tiles // Get all tiles
const tilesDir = path.join(process.cwd(), 'public', 'tiles'); const tilesDir = path.join(process.cwd(), 'public', 'tiles')
const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png')); const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png'))
// Create output directory if it doesn't exist // Create output directory if it doesn't exist
if (!fs.existsSync(tilesDir)) { if (!fs.existsSync(tilesDir)) {
fs.mkdirSync(tilesDir, { recursive: true }); fs.mkdirSync(tilesDir, { recursive: true })
} }
for (const tile of tiles) { for (const tile of tiles) {
// Check if tile is already 66x34 // 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) { if (metadata.width === 66 && metadata.height === 34) {
commandLogger.info(`Tile ${tile} already processed`); commandLogger.info(`Tile ${tile} already processed`)
continue; continue
} }
const inputPath = path.join(tilesDir, tile); const inputPath = path.join(tilesDir, tile)
const outputPath = path.join(tilesDir, tile); const outputPath = path.join(tilesDir, tile)
try { try {
await sharp(inputPath) await sharp(inputPath)
@ -36,14 +36,14 @@ export default class TilesCommand {
fit: 'fill', fit: 'fill',
kernel: 'nearest' kernel: 'nearest'
}) })
.toFile(outputPath); .toFile(outputPath)
commandLogger.info(`Processed: ${tile}`); commandLogger.info(`Processed: ${tile}`)
} catch (error) { } catch (error) {
console.error(`Error processing ${tile}:`, error); console.error(`Error processing ${tile}:`, error)
} }
} }
commandLogger.info('Tile processing completed.'); commandLogger.info('Tile processing completed.')
} }
} }

View File

@ -67,9 +67,15 @@ class CommandManager {
for (const file of files) { for (const file of files) {
try { try {
const extension = config.ENV === 'development' ? '.ts' : '.js' const extension = path.extname(file)
const commandName = path.basename(file, extension) 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)) { if (!fs.existsSync(commandPath)) {
commandLogger.warn(`Command file not found: ${commandPath}`) commandLogger.warn(`Command file not found: ${commandPath}`)

View File

@ -74,7 +74,7 @@ export class Server {
await CharacterManager.boot() await CharacterManager.boot()
// Load command manager // Load command manager
await CommandManager.boot(this.io); await CommandManager.boot(this.io)
// Listen for socket connections // Listen for socket connections
this.io.on('connection', this.handleConnection.bind(this)) this.io.on('connection', this.handleConnection.bind(this))

View File

@ -43,13 +43,6 @@ const watchLogs = () => {
}) })
} }
export const { export const { http: httpLogger, game: gameLogger, gameMaster: gameMasterLogger, app: appLogger, queue: queueLogger, command: commandLogger } = loggers
http: httpLogger,
game: gameLogger,
gameMaster: gameMasterLogger,
app: appLogger,
queue: queueLogger,
command: commandLogger
} = loggers
export { watchLogs } export { watchLogs }