forked from noxious/server
Aids
This commit is contained in:
parent
a8934f8e40
commit
9467797dc9
@ -129,41 +129,32 @@ export default class SpriteUpdateEvent {
|
|||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
processedActions.map(async ({ action, buffersWithDimensions, frameWidth, frameHeight }) => {
|
processedActions.map(async ({ action, buffersWithDimensions, frameWidth, frameHeight }) => {
|
||||||
// First prepare each frame with exact dimensions
|
// Get and validate all frame dimensions first
|
||||||
const centeredFrames = await Promise.all(
|
const frames = await Promise.all(
|
||||||
buffersWithDimensions.map(async ({ buffer }) => {
|
buffersWithDimensions.map(async ({ buffer }) => {
|
||||||
// Get the current dimensions
|
|
||||||
const metadata = await sharp(buffer).metadata()
|
const metadata = await sharp(buffer).metadata()
|
||||||
const width = metadata.width!
|
return {
|
||||||
|
buffer,
|
||||||
// Calculate padding to center the sprite
|
width: metadata.width!,
|
||||||
const leftPadding = ((frameWidth - width) >> 1)
|
height: metadata.height!
|
||||||
|
}
|
||||||
return await sharp(buffer)
|
|
||||||
.extend({
|
|
||||||
top: 0,
|
|
||||||
bottom: 0,
|
|
||||||
left: leftPadding,
|
|
||||||
right: frameWidth - width - leftPadding,
|
|
||||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
||||||
})
|
|
||||||
.toBuffer()
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
// Combine the frames
|
|
||||||
const combinedImage = await sharp({
|
const combinedImage = await sharp({
|
||||||
create: {
|
create: {
|
||||||
width: frameWidth * centeredFrames.length,
|
width: frameWidth * frames.length,
|
||||||
height: frameHeight,
|
height: frameHeight,
|
||||||
channels: 4,
|
channels: 4,
|
||||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.composite(
|
.composite(
|
||||||
centeredFrames.map((buffer, index) => ({
|
frames.map(({ buffer, width, height }, index) => ({
|
||||||
input: buffer,
|
input: buffer,
|
||||||
left: index * frameWidth,
|
// Center horizontally based on the exact middle of each frame
|
||||||
|
left: (index * frameWidth) + ((frameWidth - width) >> 1),
|
||||||
|
// Top position is always 0
|
||||||
top: 0
|
top: 0
|
||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user