Update command manager and commands to OOP
This commit is contained in:
@ -2,8 +2,12 @@ import { Server } from 'socket.io'
|
||||
|
||||
type CommandInput = string[]
|
||||
|
||||
module.exports = function (input: CommandInput, io: Server) {
|
||||
const message: string = input.join(' ') ?? null
|
||||
if (!message) return console.log('message is required')
|
||||
io.emit('notification', { message: message })
|
||||
}
|
||||
export default class AlertCommand {
|
||||
constructor(private readonly io: Server) {}
|
||||
|
||||
public execute(input: CommandInput): void {
|
||||
const message: string = input.join(' ') ?? null
|
||||
if (!message) return console.log('message is required')
|
||||
this.io.emit('notification', { message: message })
|
||||
}
|
||||
}
|
@ -3,6 +3,10 @@ import ZoneManager from '../managers/zoneManager'
|
||||
|
||||
type CommandInput = string[]
|
||||
|
||||
module.exports = function (input: CommandInput, io: Server) {
|
||||
console.log(ZoneManager.getLoadedZones())
|
||||
}
|
||||
export default class ListZonesCommand {
|
||||
constructor(private readonly io: Server) {}
|
||||
|
||||
public execute(input: CommandInput): void {
|
||||
console.log(ZoneManager.getLoadedZones())
|
||||
}
|
||||
}
|
@ -2,43 +2,48 @@ import path from 'path'
|
||||
import fs from 'fs'
|
||||
import sharp from 'sharp'
|
||||
import { commandLogger } from '../utilities/logger'
|
||||
import { Server } from 'socket.io'
|
||||
|
||||
module.exports = async function () {
|
||||
// Get all tiles
|
||||
const tilesDir = path.join(process.cwd(), 'public', 'tiles');
|
||||
const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png'));
|
||||
export default class TilesCommand {
|
||||
constructor(private readonly io: Server) {}
|
||||
|
||||
// Create output directory if it doesn't exist
|
||||
if (!fs.existsSync(tilesDir)) {
|
||||
fs.mkdirSync(tilesDir, { recursive: true });
|
||||
}
|
||||
public async execute(): Promise<void> {
|
||||
// Get all tiles
|
||||
const tilesDir = path.join(process.cwd(), 'public', 'tiles');
|
||||
const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png'));
|
||||
|
||||
for (const tile of tiles) {
|
||||
// Check if tile is already 66x34
|
||||
const metadata = await sharp(path.join(tilesDir, tile)).metadata();
|
||||
if (metadata.width === 66 && metadata.height === 34) {
|
||||
commandLogger.info(`Tile ${tile} already processed`);
|
||||
continue;
|
||||
// Create output directory if it doesn't exist
|
||||
if (!fs.existsSync(tilesDir)) {
|
||||
fs.mkdirSync(tilesDir, { recursive: true });
|
||||
}
|
||||
|
||||
const inputPath = path.join(tilesDir, tile);
|
||||
const outputPath = path.join(tilesDir, tile);
|
||||
for (const tile of tiles) {
|
||||
// Check if tile is already 66x34
|
||||
const metadata = await sharp(path.join(tilesDir, tile)).metadata();
|
||||
if (metadata.width === 66 && metadata.height === 34) {
|
||||
commandLogger.info(`Tile ${tile} already processed`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await sharp(inputPath)
|
||||
.resize({
|
||||
width: 66,
|
||||
height: 34,
|
||||
fit: 'fill',
|
||||
kernel: 'nearest'
|
||||
})
|
||||
.toFile(outputPath);
|
||||
const inputPath = path.join(tilesDir, tile);
|
||||
const outputPath = path.join(tilesDir, tile);
|
||||
|
||||
commandLogger.info(`Processed: ${tile}`);
|
||||
} catch (error) {
|
||||
console.error(`Error processing ${tile}:`, error);
|
||||
try {
|
||||
await sharp(inputPath)
|
||||
.resize({
|
||||
width: 66,
|
||||
height: 34,
|
||||
fit: 'fill',
|
||||
kernel: 'nearest'
|
||||
})
|
||||
.toFile(outputPath);
|
||||
|
||||
commandLogger.info(`Processed: ${tile}`);
|
||||
} catch (error) {
|
||||
console.error(`Error processing ${tile}:`, error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commandLogger.info('Tile processing completed.');
|
||||
commandLogger.info('Tile processing completed.');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user