1
0
forked from noxious/server

Formatted code

This commit is contained in:
Dennis Postma 2025-01-31 02:20:24 +01:00
parent 60753cb2db
commit f0bfa0b983

View File

@ -1,9 +1,11 @@
import fs from 'fs'
import sharp from 'sharp'
import { BaseEvent } from '#application/base/baseEvent'
import { UUID } from '#application/types'
import SpriteRepository from '#repositories/spriteRepository'
import { SpriteAction } from '#entities/spriteAction'
import sharp from 'sharp'
import fs from 'fs'
import SpriteRepository from '#repositories/spriteRepository'
interface SpriteImage {
url: string
@ -59,7 +61,7 @@ export default class SpriteUpdateEvent extends BaseEvent {
// First verify all sprite sheets can be generated
for (const actionData of data.spriteActions) {
if (!await this.generateSpriteSheet(actionData.sprites, sprite.getId(), actionData.action)) {
if (!(await this.generateSpriteSheet(actionData.sprites, sprite.getId(), actionData.action))) {
return callback(false)
}
}
@ -74,13 +76,13 @@ export default class SpriteUpdateEvent extends BaseEvent {
// Create new actions
for (const actionData of data.spriteActions) {
// Process images and calculate dimensions
const imageData = await Promise.all(actionData.sprites.map(sprite => this.processImage(sprite)))
const effectiveDimensions = imageData.map(dimensions => this.calculateEffectiveDimensions(dimensions))
const imageData = await Promise.all(actionData.sprites.map((sprite) => this.processImage(sprite)))
const effectiveDimensions = imageData.map((dimensions) => this.calculateEffectiveDimensions(dimensions))
// Calculate total height needed for the sprite sheet
const maxHeight = Math.max(...effectiveDimensions.map(d => d.height))
const maxTop = Math.max(...effectiveDimensions.map(d => d.top))
const maxBottom = Math.max(...effectiveDimensions.map(d => d.bottom))
const maxHeight = Math.max(...effectiveDimensions.map((d) => d.height))
const maxTop = Math.max(...effectiveDimensions.map((d) => d.top))
const maxBottom = Math.max(...effectiveDimensions.map((d) => d.bottom))
const totalHeight = maxHeight + maxTop + maxBottom
const spriteAction = new SpriteAction()
@ -111,14 +113,14 @@ export default class SpriteUpdateEvent extends BaseEvent {
if (!sprites.length) return true
// Process all images and get their dimensions
const imageData = await Promise.all(sprites.map(sprite => this.processImage(sprite)))
const effectiveDimensions = imageData.map(dimensions => this.calculateEffectiveDimensions(dimensions))
const imageData = await Promise.all(sprites.map((sprite) => this.processImage(sprite)))
const effectiveDimensions = imageData.map((dimensions) => this.calculateEffectiveDimensions(dimensions))
// Calculate maximum dimensions
const maxWidth = Math.max(...effectiveDimensions.map(d => d.width))
const maxHeight = Math.max(...effectiveDimensions.map(d => d.height))
const maxTop = Math.max(...effectiveDimensions.map(d => d.top))
const maxBottom = Math.max(...effectiveDimensions.map(d => d.bottom))
const maxWidth = Math.max(...effectiveDimensions.map((d) => d.width))
const maxHeight = Math.max(...effectiveDimensions.map((d) => d.height))
const maxTop = Math.max(...effectiveDimensions.map((d) => d.top))
const maxBottom = Math.max(...effectiveDimensions.map((d) => d.bottom))
// Calculate total height needed
const totalHeight = maxHeight + maxTop + maxBottom
@ -207,10 +209,10 @@ export default class SpriteUpdateEvent extends BaseEvent {
if (!sprites.length) return 0
// Process all images and get their dimensions
const imageData = await Promise.all(sprites.map(sprite => this.processImage(sprite)))
const effectiveDimensions = imageData.map(dimensions => this.calculateEffectiveDimensions(dimensions))
const imageData = await Promise.all(sprites.map((sprite) => this.processImage(sprite)))
const effectiveDimensions = imageData.map((dimensions) => this.calculateEffectiveDimensions(dimensions))
// Calculate maximum width needed
return Math.max(...effectiveDimensions.map(d => d.width))
return Math.max(...effectiveDimensions.map((d) => d.width))
}
}