Storage class is now OOP
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import sharp from 'sharp'
|
||||
import { Server } from 'socket.io'
|
||||
|
||||
import { BaseCommand } from '#application/base/baseCommand'
|
||||
import { CharacterGender, CharacterRace } from '#application/enums'
|
||||
import { getPublicPath } from '#application/storage'
|
||||
import Storage from '#application/storage'
|
||||
import { UUID } from '#application/types'
|
||||
import { Character } from '#entities/character'
|
||||
import { CharacterHair } from '#entities/characterHair'
|
||||
@ -44,7 +43,7 @@ export default class InitCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
private async importTiles(): Promise<void> {
|
||||
for (const tile of fs.readdirSync(getPublicPath('tiles'))) {
|
||||
for (const tile of fs.readdirSync(Storage.getPublicPath('tiles'))) {
|
||||
const newTile = new Tile()
|
||||
newTile.setId(tile.split('.')[0] as UUID).setName('New tile')
|
||||
|
||||
@ -53,18 +52,18 @@ export default class InitCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
private async importObjects(): Promise<void> {
|
||||
for (const object of fs.readdirSync(getPublicPath('objects'))) {
|
||||
for (const object of fs.readdirSync(Storage.getPublicPath('objects'))) {
|
||||
const newMapObject = new MapObject()
|
||||
newMapObject
|
||||
.setId(object.split('.')[0] as UUID)
|
||||
.setName('New object')
|
||||
.setFrameWidth(
|
||||
(await sharp(getPublicPath('objects', object))
|
||||
(await sharp(Storage.getPublicPath('objects', object))
|
||||
.metadata()
|
||||
.then((metadata) => metadata.height)) ?? 0
|
||||
)
|
||||
.setFrameHeight(
|
||||
(await sharp(getPublicPath('objects', object))
|
||||
(await sharp(Storage.getPublicPath('objects', object))
|
||||
.metadata()
|
||||
.then((metadata) => metadata.width)) ?? 0
|
||||
)
|
||||
|
@ -3,12 +3,12 @@ import fs from 'fs'
|
||||
import sharp from 'sharp'
|
||||
|
||||
import { BaseCommand } from '#application/base/baseCommand'
|
||||
import { getPublicPath } from '#application/storage'
|
||||
import Storage from '#application/storage'
|
||||
|
||||
export default class TilesCommand extends BaseCommand {
|
||||
public async execute(): Promise<void> {
|
||||
// Get all tiles
|
||||
const tilesDir = getPublicPath('tiles')
|
||||
const tilesDir = Storage.getPublicPath('tiles')
|
||||
const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png'))
|
||||
|
||||
// Create output directory if it doesn't exist
|
||||
@ -18,14 +18,14 @@ export default class TilesCommand extends BaseCommand {
|
||||
|
||||
for (const tile of tiles) {
|
||||
// Check if tile is already 66x34
|
||||
const metadata = await sharp(getPublicPath('tiles', tile)).metadata()
|
||||
const metadata = await sharp(Storage.getPublicPath('tiles', tile)).metadata()
|
||||
if (metadata.width === 66 && metadata.height === 34) {
|
||||
this.logger.info(`Tile ${tile} already processed`)
|
||||
continue
|
||||
}
|
||||
|
||||
const inputPath = getPublicPath('tiles', tile)
|
||||
const tempPath = getPublicPath('tiles', `temp_${tile}`)
|
||||
const inputPath = Storage.getPublicPath('tiles', tile)
|
||||
const tempPath = Storage.getPublicPath('tiles', `temp_${tile}`)
|
||||
|
||||
try {
|
||||
await sharp(inputPath)
|
||||
|
Reference in New Issue
Block a user