Added padding to character

This commit is contained in:
Dennis Postma 2024-12-22 01:18:18 +01:00
parent bf58fc4944
commit 6e3c97d7d1
2 changed files with 21 additions and 4 deletions

View File

@ -29,14 +29,24 @@ async function generateAvatar(res: Response, options: AvatarOptions) {
return res.status(404).json({ message: 'Body sprite file not found' })
}
let avatar = sharp(bodySpritePath)
let avatar = sharp(bodySpritePath).extend({
top: 2,
bottom: 2,
background: { r: 0, g: 0, b: 0, alpha: 0 }
})
if (options.characterHairId) {
const characterHair = await CharacterHairRepository.getById(options.characterHairId)
if (characterHair?.spriteId) {
const hairSpritePath = getPublicPath('sprites', characterHair.spriteId, 'front.png')
if (fs.existsSync(hairSpritePath)) {
avatar = avatar.composite([{ input: hairSpritePath, gravity: 'north' }])
avatar = avatar.composite([{
input: hairSpritePath,
gravity: 'north',
// Top is originY in min
// top: Math.round(Number(characterHair.sprite!.spriteActions.find((action) => action.action === 'front')?.originY ?? 0)),
// left: 0
}])
} else {
console.error(`Hair sprite file not found: ${hairSpritePath}`)
}

View File

@ -12,9 +12,16 @@ class CharacterHairRepository {
}
})
}
async getById(id: number): Promise<CharacterHair | null> {
async getById(id: number) {
return prisma.characterHair.findUnique({
where: { id }
where: { id },
include: {
sprite: {
include: {
spriteActions: true
}
}
}
})
}
}