Revert "#169 : Expand tiles to 68x64px and draw 1px line to each side-profile to"
This reverts commit e9fb277d634fe7395adcf45e7d3b6ad811213ba7.
This commit is contained in:
parent
e9fb277d63
commit
ddeee356b4
@ -1,11 +1,11 @@
|
|||||||
import { Server } from 'socket.io'
|
import { Server } from 'socket.io'
|
||||||
import { TSocket } from '../../../../utilities/types'
|
import { TSocket } from '../../../../utilities/types'
|
||||||
|
import { writeFile } from 'node:fs/promises'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import prisma from '../../../../utilities/prisma'
|
import prisma from '../../../../utilities/prisma'
|
||||||
import characterRepository from '../../../../repositories/characterRepository'
|
import characterRepository from '../../../../repositories/characterRepository'
|
||||||
import { gameMasterLogger } from '../../../../utilities/logger'
|
import { gameMasterLogger } from '../../../../utilities/logger'
|
||||||
import sharp from 'sharp';
|
|
||||||
|
|
||||||
interface ITileData {
|
interface ITileData {
|
||||||
[key: string]: Buffer
|
[key: string]: Buffer
|
||||||
@ -44,9 +44,7 @@ export default class TileUploadEvent {
|
|||||||
const uuid = tile.id
|
const uuid = tile.id
|
||||||
const filename = `${uuid}.png`
|
const filename = `${uuid}.png`
|
||||||
const finalFilePath = path.join(public_folder, filename)
|
const finalFilePath = path.join(public_folder, filename)
|
||||||
|
await writeFile(finalFilePath, tileData)
|
||||||
// Process the image
|
|
||||||
await this.processAndSaveTile(tileData, finalFilePath)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
await Promise.all(uploadPromises)
|
await Promise.all(uploadPromises)
|
||||||
@ -57,49 +55,4 @@ export default class TileUploadEvent {
|
|||||||
callback(false)
|
callback(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processAndSaveTile(tileData: Buffer, outputPath: string): Promise<void> {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user