forked from noxious/server
Continuation dynamic asset loading
This commit is contained in:
parent
f6bac403a2
commit
bd04dc2ab8
12
package-lock.json
generated
12
package-lock.json
generated
@ -719,9 +719,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "20.17.1",
|
"version": "20.17.3",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.3.tgz",
|
||||||
"integrity": "sha512-j2VlPv1NnwPJbaCNv69FO/1z4lId0QmGvpT41YxitRtWlg96g/j8qcv2RKsLKe2F6OJgyXhupN1Xo17b2m139Q==",
|
"integrity": "sha512-tSQrmKKatLDGnG92h40GD7FzUt0MjahaHwOME4VAFeeA/Xopayq5qLyQRy7Jg/pjgKIFBXuKcGhJo+UdYG55jQ==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"undici-types": "~6.19.2"
|
"undici-types": "~6.19.2"
|
||||||
@ -778,9 +778,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/acorn": {
|
"node_modules/acorn": {
|
||||||
"version": "8.13.0",
|
"version": "8.14.0",
|
||||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.13.0.tgz",
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz",
|
||||||
"integrity": "sha512-8zSiw54Oxrdym50NlZ9sUusyO1Z1ZchgRLWRaK6c86XJFClyCgFKetdowBg5bKxyp/u+CDBJG4Mpp0m3HLZl9w==",
|
"integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"acorn": "bin/acorn"
|
"acorn": "bin/acorn"
|
||||||
|
@ -2,7 +2,7 @@ import { Zone, ZoneEventTile, ZoneEventTileType, ZoneObject } from '@prisma/clie
|
|||||||
import prisma from '../utilities/prisma'
|
import prisma from '../utilities/prisma'
|
||||||
import { ZoneEventTileWithTeleport } from '../socketEvents/zone/characterMove'
|
import { ZoneEventTileWithTeleport } from '../socketEvents/zone/characterMove'
|
||||||
import { appLogger } from '../utilities/logger'
|
import { appLogger } from '../utilities/logger'
|
||||||
import { TAsset } from '../utilities/types'
|
import { AssetData } from '../utilities/types'
|
||||||
import tileRepository from './tileRepository'
|
import tileRepository from './tileRepository'
|
||||||
|
|
||||||
class ZoneRepository {
|
class ZoneRepository {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import prisma from '../utilities/prisma'
|
import prisma from '../utilities/prisma'
|
||||||
import { TAsset } from '../utilities/types'
|
import { AssetData } from '../utilities/types'
|
||||||
import tileRepository from '../repositories/tileRepository'
|
import tileRepository from '../repositories/tileRepository'
|
||||||
import zoneRepository from '../repositories/zoneRepository'
|
import zoneRepository from '../repositories/zoneRepository'
|
||||||
import { Object, Zone, ZoneObject } from '@prisma/client'
|
import { Object, Zone, ZoneObject } from '@prisma/client'
|
||||||
@ -38,8 +38,8 @@ class ZoneService {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
async getZoneAssets(zone: getZoneAsetsZoneType): Promise<TAsset[]> {
|
async getZoneAssets(zone: getZoneAsetsZoneType): Promise<AssetData[]> {
|
||||||
const assets: TAsset[] = []
|
const assets: AssetData[] = []
|
||||||
|
|
||||||
// zone.tiles is prisma jsonvalue
|
// zone.tiles is prisma jsonvalue
|
||||||
let tiles = JSON.parse(JSON.stringify(zone.tiles))
|
let tiles = JSON.parse(JSON.stringify(zone.tiles))
|
||||||
@ -52,10 +52,10 @@ class ZoneService {
|
|||||||
|
|
||||||
assets.push({
|
assets.push({
|
||||||
key: tileInfo.id,
|
key: tileInfo.id,
|
||||||
url: '/assets/tiles/' + tileInfo.id + '.png',
|
data: '/assets/tiles/' + tileInfo.id + '.png',
|
||||||
group: 'tiles',
|
group: 'tiles',
|
||||||
updatedAt: tileInfo?.updatedAt || new Date()
|
updatedAt: tileInfo?.updatedAt || new Date()
|
||||||
})
|
} as AssetData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add object assets
|
// Add object assets
|
||||||
@ -64,14 +64,14 @@ class ZoneService {
|
|||||||
|
|
||||||
assets.push({
|
assets.push({
|
||||||
key: zoneObject.object.id,
|
key: zoneObject.object.id,
|
||||||
url: '/assets/objects/' + zoneObject.object.id + '.png',
|
data: '/assets/objects/' + zoneObject.object.id + '.png',
|
||||||
group: 'objects',
|
group: 'objects',
|
||||||
updatedAt: zoneObject.object.updatedAt || new Date()
|
updatedAt: zoneObject.object.updatedAt || new Date()
|
||||||
})
|
} as AssetData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out duplicate assets
|
// Filter out duplicate assets
|
||||||
return assets.reduce((acc: TAsset[], current) => {
|
return assets.reduce((acc: AssetData[], current) => {
|
||||||
const x = acc.find((item) => item.key === current.key && item.group === current.group)
|
const x = acc.find((item) => item.key === current.key && item.group === current.group)
|
||||||
if (!x) {
|
if (!x) {
|
||||||
return acc.concat([current])
|
return acc.concat([current])
|
||||||
|
@ -7,7 +7,7 @@ import fs from 'fs'
|
|||||||
import { httpLogger } from './logger'
|
import { httpLogger } from './logger'
|
||||||
import { getPublicPath } from './storage'
|
import { getPublicPath } from './storage'
|
||||||
import TileRepository from '../repositories/tileRepository'
|
import TileRepository from '../repositories/tileRepository'
|
||||||
import { TAsset } from './types'
|
import { AssetData } from './types'
|
||||||
import ZoneRepository from '../repositories/zoneRepository'
|
import ZoneRepository from '../repositories/zoneRepository'
|
||||||
|
|
||||||
async function addHttpRoutes(app: Application) {
|
async function addHttpRoutes(app: Application) {
|
||||||
@ -61,21 +61,21 @@ async function addHttpRoutes(app: Application) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all tiles
|
* Get all tiles and serve as AssetData array
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
app.get('/assets/list_tiles', async (req: Request, res: Response) => {
|
app.get('/assets/list_tiles', async (req: Request, res: Response) => {
|
||||||
// Get all tiles
|
// Get all tiles
|
||||||
let assets: TAsset[] = []
|
let assets: AssetData[] = []
|
||||||
const tiles = await TileRepository.getAll()
|
const tiles = await TileRepository.getAll()
|
||||||
for (const tile of tiles) {
|
for (const tile of tiles) {
|
||||||
assets.push({
|
assets.push({
|
||||||
key: tile.id,
|
key: tile.id,
|
||||||
url: '/assets/tiles/' + tile.id + '.png',
|
data: '/assets/tiles/' + tile.id + '.png',
|
||||||
group: 'tiles',
|
group: 'tiles',
|
||||||
updatedAt: tile.updatedAt
|
updatedAt: tile.updatedAt
|
||||||
})
|
} as AssetData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the array
|
// Return the array
|
||||||
@ -83,7 +83,7 @@ async function addHttpRoutes(app: Application) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all tiles
|
* Get all tiles from a zone and serve as AssetData array
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
@ -102,15 +102,15 @@ async function addHttpRoutes(app: Application) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get all tiles
|
// Get all tiles
|
||||||
let assets: TAsset[] = []
|
let assets: AssetData[] = []
|
||||||
const tiles = await TileRepository.getByZoneId(parseInt(zoneId))
|
const tiles = await TileRepository.getByZoneId(parseInt(zoneId))
|
||||||
for (const tile of tiles) {
|
for (const tile of tiles) {
|
||||||
assets.push({
|
assets.push({
|
||||||
key: tile.id,
|
key: tile.id,
|
||||||
url: '/assets/tiles/' + tile.id + '.png',
|
data: '/assets/tiles/' + tile.id + '.png',
|
||||||
group: 'tiles',
|
group: 'tiles',
|
||||||
updatedAt: tile.updatedAt
|
updatedAt: tile.updatedAt
|
||||||
})
|
} as AssetData)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the array
|
// Return the array
|
||||||
@ -118,7 +118,7 @@ async function addHttpRoutes(app: Application) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a specific asset
|
* Download asset file
|
||||||
* @param req
|
* @param req
|
||||||
* @param res
|
* @param res
|
||||||
*/
|
*/
|
||||||
|
@ -21,9 +21,9 @@ export type ExtendedCharacter = Character & {
|
|||||||
resetMovement: boolean
|
resetMovement: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TAsset = {
|
export type AssetData = {
|
||||||
key: string
|
key: string
|
||||||
url: string
|
data: 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
|
updatedAt: Date
|
||||||
frameCount?: number
|
frameCount?: number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user