forked from noxious/server
Entirely replaces asset controller with improved ones (textures & cache)
This commit is contained in:
parent
39ec4daa06
commit
849ef07297
@ -1,45 +0,0 @@
|
|||||||
import { Request, Response } from 'express'
|
|
||||||
|
|
||||||
import { BaseController } from '#application/base/baseController'
|
|
||||||
import { AssetData, UUID } from '#application/types'
|
|
||||||
import SpriteRepository from '#repositories/spriteRepository'
|
|
||||||
|
|
||||||
export class AssetsController extends BaseController {
|
|
||||||
private readonly spriteRepository = new SpriteRepository()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List sprite actions
|
|
||||||
* @param req
|
|
||||||
* @param res
|
|
||||||
*/
|
|
||||||
public async listSpriteActions(req: Request, res: Response) {
|
|
||||||
const spriteId = req.params.spriteId as UUID
|
|
||||||
|
|
||||||
if (!spriteId) {
|
|
||||||
return this.sendError(res, 'Invalid sprite ID', 400)
|
|
||||||
}
|
|
||||||
|
|
||||||
const sprite = await this.spriteRepository.getById(spriteId)
|
|
||||||
if (!sprite) {
|
|
||||||
return this.sendError(res, 'Sprite not found', 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.spriteRepository.getEntityManager().populate(sprite, ['spriteActions'])
|
|
||||||
|
|
||||||
const assets: AssetData[] = sprite.getSpriteActions().map((spriteAction) => ({
|
|
||||||
key: sprite.getId() + '-' + spriteAction.getAction(),
|
|
||||||
data: '/textures/sprites/' + sprite.getId() + '/' + spriteAction.getAction() + '.png',
|
|
||||||
group: spriteAction.getIsAnimated() ? 'sprite_animations' : 'sprites',
|
|
||||||
updatedAt: sprite.getUpdatedAt(),
|
|
||||||
originX: Number(spriteAction.getOriginX().toString()),
|
|
||||||
originY: Number(spriteAction.getOriginY().toString()),
|
|
||||||
isAnimated: spriteAction.getIsAnimated(),
|
|
||||||
frameRate: spriteAction.getFrameRate(),
|
|
||||||
frameWidth: spriteAction.getFrameWidth(),
|
|
||||||
frameHeight: spriteAction.getFrameHeight(),
|
|
||||||
frameCount: spriteAction.getSprites()?.length
|
|
||||||
}))
|
|
||||||
|
|
||||||
return this.sendSuccess(res, assets)
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,9 +15,7 @@ export class Sprite extends BaseSprite {
|
|||||||
updatedAt: this.getUpdatedAt(),
|
updatedAt: this.getUpdatedAt(),
|
||||||
spriteActions: this.getSpriteActions().map((spriteAction) => ({
|
spriteActions: this.getSpriteActions().map((spriteAction) => ({
|
||||||
id: spriteAction.getId(),
|
id: spriteAction.getId(),
|
||||||
sprite: spriteAction.getSprite().getId(),
|
|
||||||
action: spriteAction.getAction(),
|
action: spriteAction.getAction(),
|
||||||
// sprites: spriteAction.getSprites(), // We dont want to send this to the client
|
|
||||||
originX: spriteAction.getOriginX(),
|
originX: spriteAction.getOriginX(),
|
||||||
originY: spriteAction.getOriginY(),
|
originY: spriteAction.getOriginY(),
|
||||||
isAnimated: spriteAction.getIsAnimated(),
|
isAnimated: spriteAction.getIsAnimated(),
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Application } from 'express'
|
import { Application } from 'express'
|
||||||
|
|
||||||
import { AssetsController } from '#controllers/assets'
|
|
||||||
import { AuthController } from '#controllers/auth'
|
import { AuthController } from '#controllers/auth'
|
||||||
import { AvatarController } from '#controllers/avatar'
|
import { AvatarController } from '#controllers/avatar'
|
||||||
import { CacheController } from '#controllers/cache'
|
import { CacheController } from '#controllers/cache'
|
||||||
@ -12,7 +11,6 @@ import { TexturesController } from '#controllers/textures'
|
|||||||
class HttpManager {
|
class HttpManager {
|
||||||
private readonly authController: AuthController = new AuthController()
|
private readonly authController: AuthController = new AuthController()
|
||||||
private readonly avatarController: AvatarController = new AvatarController()
|
private readonly avatarController: AvatarController = new AvatarController()
|
||||||
private readonly assetsController: AssetsController = new AssetsController()
|
|
||||||
private readonly texturesController: TexturesController = new TexturesController()
|
private readonly texturesController: TexturesController = new TexturesController()
|
||||||
private readonly cacheController: CacheController = new CacheController()
|
private readonly cacheController: CacheController = new CacheController()
|
||||||
|
|
||||||
@ -36,9 +34,6 @@ class HttpManager {
|
|||||||
app.get('/avatar/:characterName', (req, res) => this.avatarController.getByName(req, res))
|
app.get('/avatar/:characterName', (req, res) => this.avatarController.getByName(req, res))
|
||||||
app.get('/avatar/s/:characterTypeId/:characterHairId?', (req, res) => this.avatarController.getByParams(req, res))
|
app.get('/avatar/s/:characterTypeId/:characterHairId?', (req, res) => this.avatarController.getByParams(req, res))
|
||||||
|
|
||||||
// Assets routes
|
|
||||||
app.get('/assets/list_sprite_actions/:spriteId', (req, res) => this.assetsController.listSpriteActions(req, res))
|
|
||||||
|
|
||||||
// Download texture file
|
// Download texture file
|
||||||
app.get('/textures/:type/:spriteId?/:file', (req, res) => this.texturesController.download(req, res))
|
app.get('/textures/:type/:spriteId?/:file', (req, res) => this.texturesController.download(req, res))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user