forked from noxious/server
Loading sprites and animations now works
This commit is contained in:
@ -1,7 +1,3 @@
|
||||
/**
|
||||
* Resources:
|
||||
* https://stackoverflow.com/questions/76131891/what-is-the-best-method-for-socket-io-authentication
|
||||
*/
|
||||
import { Application, Request, Response } from 'express'
|
||||
import UserService from '../services/UserService'
|
||||
import jwt from 'jsonwebtoken'
|
||||
@ -11,6 +7,7 @@ import path from 'path'
|
||||
import { TAsset } from './Types'
|
||||
import tileRepository from '../repositories/TileRepository'
|
||||
import objectRepository from '../repositories/ObjectRepository'
|
||||
import spriteRepository from '../repositories/SpriteRepository'
|
||||
|
||||
async function addHttpRoutes(app: Application) {
|
||||
app.get('/assets', async (req: Request, res: Response) => {
|
||||
@ -20,7 +17,7 @@ async function addHttpRoutes(app: Application) {
|
||||
assets.push({
|
||||
key: tile.id,
|
||||
url: '/assets/tiles/' + tile.id + '.png',
|
||||
group: 'tiles',
|
||||
group: 'tiles'
|
||||
})
|
||||
})
|
||||
|
||||
@ -29,7 +26,19 @@ async function addHttpRoutes(app: Application) {
|
||||
assets.push({
|
||||
key: object.id,
|
||||
url: '/assets/objects/' + object.id + '.png',
|
||||
group: 'objects',
|
||||
group: 'objects'
|
||||
})
|
||||
})
|
||||
|
||||
const sprites = await spriteRepository.getAll()
|
||||
// sprites all contain spriteActions, loop through these
|
||||
sprites.forEach((sprite) => {
|
||||
sprite.spriteActions.forEach((spriteAction) => {
|
||||
assets.push({
|
||||
key: spriteAction.id,
|
||||
url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
||||
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites'
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -26,5 +26,7 @@ export type TZoneCharacter = Character & {}
|
||||
export type TAsset = {
|
||||
key: string
|
||||
url: string
|
||||
group: 'tiles' | 'objects' | 'sound' | 'music' | 'ui' | 'font' | 'other' | 'sprite'
|
||||
group: 'tiles' | 'objects' | 'sprites' | 'sprite_animations' | 'sound' | 'music' | 'ui' | 'font' | 'other'
|
||||
frameWidth?: number
|
||||
frameHeight?: number
|
||||
}
|
||||
|
Reference in New Issue
Block a user