diff --git a/src/app/events/AssetsDownload.ts b/src/app/events/AssetsDownload.ts index 5b28beb..f7a3ba3 100644 --- a/src/app/events/AssetsDownload.ts +++ b/src/app/events/AssetsDownload.ts @@ -1,23 +1,17 @@ import { Server } from "socket.io"; -import {TSocket} from "../utilities/Types"; +import {TSocket, TAsset} from "../utilities/Types"; import fs from "fs"; import path from "path"; -type Asset = { - key: string - value: string - type: 'base64' | 'link' -} - export default function (socket: TSocket, io: Server) { - socket.on('assets:download', async (data: any, callback: (response: Asset[]) => void) => { + socket.on('assets:download', async (data: any, callback: (response: TAsset[]) => void) => { console.log('assets:download requested'); - let assets: Asset[] = []; + let assets: TAsset[] = []; const tiles = listTiles(); tiles.forEach(tile => { - assets.push({key: tile, value: '/tiles/' + tile, type: 'link'}); + assets.push({key: 'tile_' + tile, value: '/tiles/' + tile, group: 'tiles', type: 'link'}); }); console.log('assets:download response', assets) diff --git a/src/app/events/gm/GmTileUpload.ts b/src/app/events/gm/GmTileUpload.ts index 34c1372..5f286b7 100644 --- a/src/app/events/gm/GmTileUpload.ts +++ b/src/app/events/gm/GmTileUpload.ts @@ -32,9 +32,9 @@ export default function (socket: TSocket, io: Server) { for (const key in data) { // the files in the folder are named 0.png, 1.png, 2.png etc... check the last file name and add 1 const files = fs.readdirSync(public_folder); - const lastFile = files[files.length - 1]; + const lastFile = files.reduce((a, b) => a > b ? a : b); const lastFileName = lastFile?.split('.')[0]; - const filename = `${parseInt(lastFileName ?? 0) + 1}.png`; + const filename = `${parseInt(lastFileName ?? '0') + 1}.png`; const finalFilePath = path.join(public_folder, filename); const tile = data[key]; diff --git a/src/app/utilities/Types.ts b/src/app/utilities/Types.ts index a44d8f9..af024cf 100644 --- a/src/app/utilities/Types.ts +++ b/src/app/utilities/Types.ts @@ -23,4 +23,11 @@ export type TCharacter = Socket & { export type TZoneCharacter = Character & { +} + +export type TAsset = { + key: string + value: string + group: 'tiles' | 'objects' | 'sound' | 'music' | 'ui' | 'font' | 'other' + type: 'base64' | 'link' } \ No newline at end of file