From ddeee356b419e6dac21e61fa3644b1026c9664ee Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Sun, 29 Sep 2024 21:56:03 +0200 Subject: [PATCH] Revert "#169 : Expand tiles to 68x64px and draw 1px line to each side-profile to" This reverts commit e9fb277d634fe7395adcf45e7d3b6ad811213ba7. --- .../gameMaster/assetManager/tile/upload.ts | 51 +------------------ 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/src/socketEvents/gameMaster/assetManager/tile/upload.ts b/src/socketEvents/gameMaster/assetManager/tile/upload.ts index 6d292b8..69f1f40 100644 --- a/src/socketEvents/gameMaster/assetManager/tile/upload.ts +++ b/src/socketEvents/gameMaster/assetManager/tile/upload.ts @@ -1,11 +1,11 @@ import { Server } from 'socket.io' import { TSocket } from '../../../../utilities/types' +import { writeFile } from 'node:fs/promises' import path from 'path' import fs from 'fs/promises' import prisma from '../../../../utilities/prisma' import characterRepository from '../../../../repositories/characterRepository' import { gameMasterLogger } from '../../../../utilities/logger' -import sharp from 'sharp'; interface ITileData { [key: string]: Buffer @@ -44,9 +44,7 @@ export default class TileUploadEvent { const uuid = tile.id const filename = `${uuid}.png` const finalFilePath = path.join(public_folder, filename) - - // Process the image - await this.processAndSaveTile(tileData, finalFilePath) + await writeFile(finalFilePath, tileData) }) await Promise.all(uploadPromises) @@ -57,49 +55,4 @@ export default class TileUploadEvent { callback(false) } } - - private async processAndSaveTile(tileData: Buffer, outputPath: string): Promise { - const image = sharp(tileData); - const metadata = await image.metadata(); - - if (metadata.width !== 64 || metadata.height !== 32) { - throw new Error('Input tile must be 64x32 pixels'); - } - - const resizedImage = await image - .resize(66, 34, { - kernel: sharp.kernel.nearest, - fit: 'contain', - position: 'center', - background: { r: 0, g: 0, b: 0, alpha: 0 } - }) - .raw() - .toBuffer({ resolveWithObject: true }); - - const { data, info } = resizedImage; - const { width, height, channels } = info; - - // Add 1px lines on each side - for (let y = 0; y < height; y++) { - for (let x = 0; x < width; x++) { - if (x === 0 || x === width - 1 || y === 0 || y === height - 1) { - const idx = (y * width + x) * channels; - const nearestIdx = ( - y === 0 ? width + x : - y === height - 1 ? (height - 2) * width + x : - x === 0 ? y * width + 1 : - y * width + width - 2 - ) * channels; - - for (let c = 0; c < channels; c++) { - data[idx + c] = data[nearestIdx + c]; - } - } - } - } - - await sharp(data, { raw: { width, height, channels } }) - .png() - .toFile(outputPath); - } }