forked from noxious/server
Started working on Dexie support
This commit is contained in:
parent
63804336be
commit
b6e7a5d7fe
@ -3,14 +3,11 @@ import UserService from '../services/userService'
|
|||||||
import jwt from 'jsonwebtoken'
|
import jwt from 'jsonwebtoken'
|
||||||
import config from './config'
|
import config from './config'
|
||||||
import { loginAccountSchema, registerAccountSchema } from './zodTypes'
|
import { loginAccountSchema, registerAccountSchema } from './zodTypes'
|
||||||
import path from 'path'
|
|
||||||
import { TAsset } from './types'
|
import { TAsset } from './types'
|
||||||
import tileRepository from '../repositories/tileRepository'
|
import tileRepository from '../repositories/tileRepository'
|
||||||
import objectRepository from '../repositories/objectRepository'
|
import objectRepository from '../repositories/objectRepository'
|
||||||
import spriteRepository from '../repositories/spriteRepository'
|
import spriteRepository from '../repositories/spriteRepository'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import zoneRepository from '../repositories/zoneRepository'
|
|
||||||
import zoneManager from '../managers/zoneManager'
|
|
||||||
import { httpLogger } from './logger'
|
import { httpLogger } from './logger'
|
||||||
import { getPublicPath } from './storage'
|
import { getPublicPath } from './storage'
|
||||||
|
|
||||||
@ -20,10 +17,13 @@ async function addHttpRoutes(app: Application) {
|
|||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
app.get('/assets/sprites', async (req: Request, res: Response) => {
|
app.get('/assets', async (req: Request, res: Response) => {
|
||||||
let assets: TAsset[] = []
|
let assets: TAsset[] = []
|
||||||
|
|
||||||
const sprites = await spriteRepository.getAll()
|
const sprites = await spriteRepository.getAll()
|
||||||
|
const tiles = await tileRepository.getAll()
|
||||||
|
const objects = await objectRepository.getAll()
|
||||||
|
|
||||||
// sprites all contain spriteActions, loop through these
|
// sprites all contain spriteActions, loop through these
|
||||||
sprites.forEach((sprite) => {
|
sprites.forEach((sprite) => {
|
||||||
sprite.spriteActions.forEach((spriteAction) => {
|
sprite.spriteActions.forEach((spriteAction) => {
|
||||||
@ -31,81 +31,37 @@ async function addHttpRoutes(app: Application) {
|
|||||||
key: sprite.id + '-' + spriteAction.action,
|
key: sprite.id + '-' + spriteAction.action,
|
||||||
url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
||||||
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites',
|
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites',
|
||||||
|
updatedAt: sprite.updatedAt,
|
||||||
frameCount: JSON.parse(JSON.stringify(spriteAction.sprites)).length,
|
frameCount: JSON.parse(JSON.stringify(spriteAction.sprites)).length,
|
||||||
frameWidth: spriteAction.frameWidth,
|
frameWidth: spriteAction.frameWidth,
|
||||||
frameHeight: spriteAction.frameHeight
|
frameHeight: spriteAction.frameHeight,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json(assets)
|
// Get all tiles
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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[] = []
|
|
||||||
tiles.forEach((tile) => {
|
tiles.forEach((tile) => {
|
||||||
assets.push({
|
assets.push({
|
||||||
key: tile.id,
|
key: tile.id,
|
||||||
url: '/assets/tiles/' + tile.id + '.png',
|
url: '/assets/tiles/' + tile.id + '.png',
|
||||||
group: 'tiles'
|
group: 'tiles',
|
||||||
|
updatedAt: tile.updatedAt
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Get all objects
|
||||||
objects.forEach((object) => {
|
objects.forEach((object) => {
|
||||||
assets.push({
|
assets.push({
|
||||||
key: object.id,
|
key: object.id,
|
||||||
url: '/assets/objects/' + object.id + '.png',
|
url: '/assets/objects/' + object.id + '.png',
|
||||||
group: 'objects'
|
group: 'objects',
|
||||||
|
updatedAt: object.updatedAt
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
res.json(assets)
|
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
|
* Get a specific asset
|
||||||
* @param req
|
* @param req
|
||||||
|
@ -25,6 +25,7 @@ export type TAsset = {
|
|||||||
key: string
|
key: string
|
||||||
url: string
|
url: string
|
||||||
group: 'tiles' | 'objects' | 'sprites' | 'sprite_animations' | 'sound' | 'music' | 'ui' | 'font' | 'other'
|
group: 'tiles' | 'objects' | 'sprites' | 'sprite_animations' | 'sound' | 'music' | 'ui' | 'font' | 'other'
|
||||||
|
updatedAt: Date
|
||||||
frameCount?: number
|
frameCount?: number
|
||||||
frameWidth?: number
|
frameWidth?: number
|
||||||
frameHeight?: number
|
frameHeight?: number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user