1
0
forked from noxious/server

Improved texture generation

This commit is contained in:
2024-12-12 00:43:34 +01:00
parent ff39628f0c
commit 179ccdbc55
2 changed files with 106 additions and 22 deletions

View File

@ -129,19 +129,33 @@ export default class SpriteUpdateEvent {
await Promise.all(
processedActions.map(async ({ action, buffersWithDimensions, frameWidth, frameHeight }) => {
// Get and validate all frame dimensions first
const frames = await Promise.all(
buffersWithDimensions.map(async ({ buffer }) => {
const metadata = await sharp(buffer).metadata()
return {
buffer,
width: metadata.width!,
height: metadata.height!
}
})
)
const combinedImage = await sharp({
create: {
width: frameWidth * buffersWithDimensions.length,
width: frameWidth * frames.length,
height: frameHeight,
channels: 4,
background: { r: 0, g: 0, b: 0, alpha: 0 }
}
})
.composite(
buffersWithDimensions.map(({ buffer }, index) => ({
frames.map(({ buffer, width, height }, index) => ({
input: buffer,
left: index * frameWidth,
top: 0
// Center horizontally based on the exact middle of each frame
left: (index * frameWidth) + ((frameWidth - width) >> 1),
// Calculate vertical position to center in the available space
top: ((frameHeight - height) >> 1)
}))
)
.png()