diff --git a/src/utilities/http.ts b/src/utilities/http.ts index 2581d5a..8ecc5ab 100644 --- a/src/utilities/http.ts +++ b/src/utilities/http.ts @@ -3,14 +3,11 @@ import UserService from '../services/userService' import jwt from 'jsonwebtoken' import config from './config' import { loginAccountSchema, registerAccountSchema } from './zodTypes' -import path from 'path' import { TAsset } from './types' import tileRepository from '../repositories/tileRepository' import objectRepository from '../repositories/objectRepository' import spriteRepository from '../repositories/spriteRepository' import fs from 'fs' -import zoneRepository from '../repositories/zoneRepository' -import zoneManager from '../managers/zoneManager' import { httpLogger } from './logger' import { getPublicPath } from './storage' @@ -20,10 +17,13 @@ async function addHttpRoutes(app: Application) { * @param req * @param res */ - app.get('/assets/sprites', async (req: Request, res: Response) => { + app.get('/assets', async (req: Request, res: Response) => { let assets: TAsset[] = [] const sprites = await spriteRepository.getAll() + const tiles = await tileRepository.getAll() + const objects = await objectRepository.getAll() + // sprites all contain spriteActions, loop through these sprites.forEach((sprite) => { sprite.spriteActions.forEach((spriteAction) => { @@ -31,81 +31,37 @@ async function addHttpRoutes(app: Application) { key: sprite.id + '-' + spriteAction.action, url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png', group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites', + updatedAt: sprite.updatedAt, frameCount: JSON.parse(JSON.stringify(spriteAction.sprites)).length, frameWidth: spriteAction.frameWidth, - frameHeight: spriteAction.frameHeight + frameHeight: spriteAction.frameHeight, }) }) }) - res.json(assets) - }) - - /** - * Get all assets for all zones - * @param req - * @param res - */ - app.get('/assets/zone', async (req: Request, res: Response) => { - const tiles = await tileRepository.getAll() - const objects = await objectRepository.getAll() - - const assets: TAsset[] = [] + // Get all tiles tiles.forEach((tile) => { assets.push({ key: tile.id, url: '/assets/tiles/' + tile.id + '.png', - group: 'tiles' + group: 'tiles', + updatedAt: tile.updatedAt }) }) + // Get all objects objects.forEach((object) => { assets.push({ key: object.id, url: '/assets/objects/' + object.id + '.png', - group: 'objects' + group: 'objects', + updatedAt: object.updatedAt }) }) res.json(assets) }) - /** - * Get assets for a specific zone - * @param req - * @param res - */ - app.get('/assets/zone/:zoneId', async (req: Request, res: Response) => { - const zoneId = req.params.zoneId - if (!zoneId || parseInt(zoneId) === 0) { - return res.status(400).json({ message: 'Invalid zone ID' }) - } - - const zone = await zoneRepository.getById(parseInt(zoneId)) - if (!zone) { - return res.status(404).json({ message: 'Zone not found' }) - } - - const assets = await zoneManager.getZoneAssets(zone) - - res.json([ - ...assets.tiles.map((x) => { - return { - key: x, - url: '/assets/tiles/' + x + '.png', - group: 'tiles' - } - }), - ...assets.objects.map((x) => { - return { - key: x, - url: '/assets/objects/' + x + '.png', - group: 'objects' - } - }) - ]) - }) - /** * Get a specific asset * @param req diff --git a/src/utilities/types.ts b/src/utilities/types.ts index 4aebba0..4bd7877 100644 --- a/src/utilities/types.ts +++ b/src/utilities/types.ts @@ -25,6 +25,7 @@ export type TAsset = { key: string url: string group: 'tiles' | 'objects' | 'sprites' | 'sprite_animations' | 'sound' | 'music' | 'ui' | 'font' | 'other' + updatedAt: Date frameCount?: number frameWidth?: number frameHeight?: number