POC working new caching method - moved controllers folder, renamed assets to textures, fixed HTTP bug, formatted code
This commit is contained in:
parent
4397552a86
commit
f47023dc81
@ -116,4 +116,8 @@ export class AssetsController extends BaseController {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async downloadCache(req: Request, res: Response) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
92
src/controllers/cache.ts
Normal file
92
src/controllers/cache.ts
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import { Request, Response } from 'express'
|
||||||
|
|
||||||
|
import { BaseController } from '#application/base/baseController'
|
||||||
|
import { AssetData, UUID } from '#application/types'
|
||||||
|
import MapRepository from '#repositories/mapRepository'
|
||||||
|
import SpriteRepository from '#repositories/spriteRepository'
|
||||||
|
import TileRepository from '#repositories/tileRepository'
|
||||||
|
|
||||||
|
export class DataController extends BaseController {
|
||||||
|
private readonly mapRepository = new MapRepository()
|
||||||
|
private readonly spriteRepository = new SpriteRepository()
|
||||||
|
private readonly tileRepository = new TileRepository()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List tiles
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
*/
|
||||||
|
public async tiles(req: Request, res: Response) {
|
||||||
|
const assets: AssetData[] = []
|
||||||
|
const tiles = await this.tileRepository.getAll()
|
||||||
|
|
||||||
|
for (const tile of tiles) {
|
||||||
|
assets.push({ key: tile.getId(), data: '/assets/tiles/' + tile.getId() + '.png', group: 'tiles', updatedAt: tile.getUpdatedAt() } as AssetData)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.sendSuccess(res, assets)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List tiles by map
|
||||||
|
* @param req
|
||||||
|
* @param res
|
||||||
|
*/
|
||||||
|
public async listTilesByMap(req: Request, res: Response) {
|
||||||
|
const mapId = req.params.mapId as UUID
|
||||||
|
|
||||||
|
if (!mapId) {
|
||||||
|
return this.sendError(res, 'Invalid map ID', 400)
|
||||||
|
}
|
||||||
|
|
||||||
|
const map = await this.mapRepository.getById(mapId)
|
||||||
|
if (!map) {
|
||||||
|
return this.sendError(res, 'Map not found', 404)
|
||||||
|
}
|
||||||
|
|
||||||
|
const assets: AssetData[] = []
|
||||||
|
const tiles = await this.tileRepository.getByMapId(mapId)
|
||||||
|
|
||||||
|
for (const tile of tiles) {
|
||||||
|
assets.push({ key: tile.getId(), data: '/assets/tiles/' + tile.getId() + '.png', group: 'tiles', updatedAt: tile.getUpdatedAt() } as AssetData)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.sendSuccess(res, assets)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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: '/assets/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)
|
||||||
|
}
|
||||||
|
}
|
0
src/controllers/textures.ts
Normal file
0
src/controllers/textures.ts
Normal file
Loading…
x
Reference in New Issue
Block a user