Minor improvement with generating sprites

This commit is contained in:
Dennis Postma 2025-01-29 23:22:56 +01:00
parent caf0e5c2f4
commit e57c19defd

View File

@ -124,13 +124,15 @@ export default class SpriteUpdateEvent extends BaseEvent {
const maxWidth = Math.max(...imageData.map((data) => data.width)) const maxWidth = Math.max(...imageData.map((data) => data.width))
const maxHeight = Math.max(...imageData.map((data) => data.height)) const maxHeight = Math.max(...imageData.map((data) => data.height))
console.log(maxWidth, maxHeight)
// Extend all images to match the largest dimensions without resizing // Extend all images to match the largest dimensions without resizing
const resizedBuffers = await Promise.all( const resizedBuffers = await Promise.all(
imageData.map(async ({ buffer, width, height }) => { imageData.map(async ({ buffer, width, height }) => {
// Calculate padding to center the sprite // Calculate padding to center the sprite
const topPadding = 0 // This is always 0. We don't need to calculate it const topPadding = 0 // This is always 0. We don't need to calculate it
const bottomPadding = Math.ceil((maxHeight - height) / 2) const bottomPadding = Math.ceil((maxHeight - height) / 2)
const leftPadding = Math.floor((maxWidth - width) / 2) const leftPadding = Math.ceil((maxWidth - width) / 2)
const rightPadding = Math.ceil((maxWidth - width) / 2) const rightPadding = Math.ceil((maxWidth - width) / 2)
return await sharp(buffer) return await sharp(buffer)