forked from noxious/server
Partial fix, still missing functionality (like a lot)
This commit is contained in:
parent
7fb52732ab
commit
fce5c8dad0
@ -25,19 +25,26 @@ class ZoneManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For now only current zone.
|
// For now only current zone.
|
||||||
public async getAssetsNeeded(zone: Zone) {
|
public async getNeededAssets(zone: Zone) {
|
||||||
zone.tiles
|
const tiles = this.getUnique((JSON.parse(JSON.stringify(zone.tiles)) as string[][]).reduce((acc, val) => [...acc, ...val]));
|
||||||
const tiles = JSON.parse(zone.tiles as string) as string[][];
|
|
||||||
const objects = await zoneRepository.getObjects(zone.id);
|
const objects = await zoneRepository.getObjects(zone.id);
|
||||||
console.log(tiles);
|
let mappedObjects = this.getUnique(objects.map(x => x.objectId));
|
||||||
console.log(objects);
|
|
||||||
|
return {
|
||||||
|
tiles,
|
||||||
|
objects: mappedObjects
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private getUnique<T>(array: T[]) {
|
||||||
|
return [...new Set<T>(array)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to handle individual zoneEditor loading
|
// Method to handle individual zoneEditor loading
|
||||||
public async loadZone(zone: Zone) {
|
public async loadZone(zone: Zone) {
|
||||||
const loadedZone = new LoadedZone(zone)
|
const loadedZone = new LoadedZone(zone)
|
||||||
this.loadedZones.push(loadedZone)
|
this.loadedZones.push(loadedZone)
|
||||||
await this.getAssetsNeeded(zone);
|
await this.getNeededAssets(zone);
|
||||||
logger.info(`Zone ID ${zone.id} loaded`)
|
logger.info(`Zone ID ${zone.id} loaded`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ import objectRepository from '../repositories/objectRepository'
|
|||||||
import spriteRepository from '../repositories/spriteRepository'
|
import spriteRepository from '../repositories/spriteRepository'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import logger from './logger'
|
import logger from './logger'
|
||||||
|
import zoneRepository from '../repositories/zoneRepository'
|
||||||
|
import zoneManager from '../managers/zoneManager'
|
||||||
|
|
||||||
async function addHttpRoutes(app: Application) {
|
async function addHttpRoutes(app: Application) {
|
||||||
app.get('/assets', async (req: Request, res: Response) => {
|
app.get('/assets', async (req: Request, res: Response) => {
|
||||||
@ -49,6 +51,44 @@ async function addHttpRoutes(app: Application) {
|
|||||||
res.json(assets)
|
res.json(assets)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/assets/:zoneId', async (req: Request, res: Response) => {
|
||||||
|
const zoneId = req.params.zoneId
|
||||||
|
if(zoneId && parseInt(zoneId)) {
|
||||||
|
const zone = await zoneRepository.getById(parseInt(zoneId))
|
||||||
|
if(zone) {
|
||||||
|
const assets = await zoneManager.getNeededAssets(zone);
|
||||||
|
const sprites = await spriteRepository.getAll()
|
||||||
|
const spritesArray: TAsset[] = [];
|
||||||
|
sprites.forEach((sprite) => {
|
||||||
|
sprite.spriteActions.forEach((spriteAction) => {
|
||||||
|
spritesArray.push({
|
||||||
|
key: sprite.id + '-' + spriteAction.action,
|
||||||
|
url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
||||||
|
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites',
|
||||||
|
frameWidth: spriteAction.frameWidth,
|
||||||
|
frameHeight: spriteAction.frameHeight
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
res.json([
|
||||||
|
...spritesArray,
|
||||||
|
...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'
|
||||||
|
}})
|
||||||
|
]);
|
||||||
|
// res.json( );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.get('/assets/:type/:spriteId?/:file', (req: Request, res: Response) => {
|
app.get('/assets/:type/:spriteId?/:file', (req: Request, res: Response) => {
|
||||||
const assetType = req.params.type
|
const assetType = req.params.type
|
||||||
const spriteId = req.params.spriteId
|
const spriteId = req.params.spriteId
|
||||||
|
Loading…
x
Reference in New Issue
Block a user