forked from noxious/server
Improved texture generation
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user