1
0
forked from noxious/server
This commit is contained in:
2024-12-18 03:05:11 +01:00
parent 3f10b03d24
commit 1cbf116ad4
3 changed files with 28 additions and 29 deletions

View File

@ -100,29 +100,6 @@ export default class SpriteUpdateEvent {
)
}
async function updateDatabase(id: string, name: string, processedActions: ProcessedSpriteAction[]) {
await prisma.sprite.update({
where: { id },
data: {
name,
spriteActions: {
deleteMany: { spriteId: id },
create: processedActions.map(({ action, sprites, originX, originY, isAnimated, isLooping, frameWidth, frameHeight, frameSpeed }) => ({
action,
sprites,
originX,
originY,
isAnimated,
isLooping,
frameWidth,
frameHeight,
frameSpeed
}))
}
}
})
}
async function saveSpritesToDisk(id: string, processedActions: ProcessedSpriteAction[]) {
const publicFolder = getPublicPath('sprites', id)
await mkdir(publicFolder, { recursive: true })
@ -153,8 +130,8 @@ export default class SpriteUpdateEvent {
frames.map(({ buffer, width, height }, index) => ({
input: buffer,
// 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
left: index * frameWidth + ((frameWidth - width) >> 1),
// Top position is always 0
top: 0
}))
)
@ -166,5 +143,28 @@ export default class SpriteUpdateEvent {
})
)
}
async function updateDatabase(id: string, name: string, processedActions: ProcessedSpriteAction[]) {
await prisma.sprite.update({
where: { id },
data: {
name,
spriteActions: {
deleteMany: { spriteId: id },
create: processedActions.map(({ action, sprites, originX, originY, isAnimated, isLooping, frameWidth, frameHeight, frameSpeed }) => ({
action,
sprites,
originX,
originY,
isAnimated,
isLooping,
frameWidth,
frameHeight,
frameSpeed
}))
}
}
})
}
}
}