Stash
This commit is contained in:
parent
d6681f9af7
commit
c59b391a6a
Binary file not shown.
@ -489,7 +489,7 @@ export default class InitCommand extends BaseCommand {
|
|||||||
|
|
||||||
private async createCharacterHair(): Promise<void> {
|
private async createCharacterHair(): Promise<void> {
|
||||||
const hairSprite = new Sprite()
|
const hairSprite = new Sprite()
|
||||||
hairSprite.setId('922ee95f-1500-49c0-8ead-f8cc46dad136').setName('Hair 1')
|
hairSprite.setId('922ee95f-1500-49c0-8ead-f8cc46dad136').setName('Hair 1').setWidth(30).setHeight(40)
|
||||||
await hairSprite.save()
|
await hairSprite.save()
|
||||||
|
|
||||||
const frontAction = new SpriteAction()
|
const frontAction = new SpriteAction()
|
||||||
|
@ -65,9 +65,12 @@ export class AvatarController extends BaseController {
|
|||||||
return this.sendError(res, 'Body sprite file not found', 404)
|
return this.sendError(res, 'Body sprite file not found', 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get body sprite metadata
|
||||||
|
const bodyMetadata = await sharp(bodySpritePath).metadata()
|
||||||
|
|
||||||
let avatar = sharp(bodySpritePath).extend({
|
let avatar = sharp(bodySpritePath).extend({
|
||||||
top: 2,
|
top: 0,
|
||||||
bottom: 2,
|
bottom: 0,
|
||||||
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -76,7 +79,21 @@ export class AvatarController extends BaseController {
|
|||||||
if (characterHair?.sprite?.id) {
|
if (characterHair?.sprite?.id) {
|
||||||
const hairSpritePath = Storage.getPublicPath('sprites', characterHair.sprite.id, 'front.png')
|
const hairSpritePath = Storage.getPublicPath('sprites', characterHair.sprite.id, 'front.png')
|
||||||
if (fs.existsSync(hairSpritePath)) {
|
if (fs.existsSync(hairSpritePath)) {
|
||||||
avatar = avatar.composite([{ input: hairSpritePath, gravity: 'north' }])
|
// Resize hair sprite to match body dimensions
|
||||||
|
const resizedHair = await sharp(hairSpritePath)
|
||||||
|
.resize(bodyMetadata.width, bodyMetadata.height, {
|
||||||
|
fit: 'contain',
|
||||||
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
||||||
|
})
|
||||||
|
.toBuffer()
|
||||||
|
|
||||||
|
avatar = avatar.composite([
|
||||||
|
{
|
||||||
|
input: resizedHair,
|
||||||
|
left: 0,
|
||||||
|
top: -27 // Apply vertical offset
|
||||||
|
}
|
||||||
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,6 +101,7 @@ export class AvatarController extends BaseController {
|
|||||||
res.setHeader('Content-Type', 'image/png')
|
res.setHeader('Content-Type', 'image/png')
|
||||||
return avatar.pipe(res)
|
return avatar.pipe(res)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.error('Avatar generation error:', error)
|
||||||
return this.sendError(res, 'Error generating avatar', 500)
|
return this.sendError(res, 'Error generating avatar', 500)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ interface EffectiveDimensions {
|
|||||||
type Payload = {
|
type Payload = {
|
||||||
id: UUID
|
id: UUID
|
||||||
name: string
|
name: string
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
spriteActions: Array<{
|
spriteActions: Array<{
|
||||||
action: string
|
action: string
|
||||||
sprites: SpriteImage[]
|
sprites: SpriteImage[]
|
||||||
@ -56,7 +58,7 @@ export default class SpriteUpdateEvent extends BaseEvent {
|
|||||||
await spriteRepository.getEntityManager().populate(sprite, ['spriteActions'])
|
await spriteRepository.getEntityManager().populate(sprite, ['spriteActions'])
|
||||||
|
|
||||||
// Update sprite in database
|
// Update sprite in database
|
||||||
await sprite.setName(data.name).setUpdatedAt(new Date()).save()
|
await sprite.setName(data.name).setWidth(data.width).setHeight(data.height).setUpdatedAt(new Date()).save()
|
||||||
|
|
||||||
// First verify all sprite sheets can be generated
|
// First verify all sprite sheets can be generated
|
||||||
for (const actionData of data.spriteActions) {
|
for (const actionData of data.spriteActions) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user