forked from noxious/server
Added logic that allows socket events to exist in sub directories, moved said events for better DX, added logics for tile management (upload & read), started working on (zone) object logics too
This commit is contained in:
37
src/app/events/gm/GmTileList.ts
Normal file
37
src/app/events/gm/GmTileList.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { Server } from "socket.io";
|
||||
import {TSocket} from "../../utilities/Types";
|
||||
import fs from 'fs';
|
||||
|
||||
interface IPayload {
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle game master list tiles event
|
||||
* @param socket
|
||||
* @param io
|
||||
*/
|
||||
export default function (socket: TSocket, io: Server) {
|
||||
socket.on('gm:tile:list', async (data: any, callback: (response: string[]) => void) => {
|
||||
|
||||
// get root path
|
||||
const root_folder = process.cwd();
|
||||
const folder = `${root_folder}/public/tiles`;
|
||||
|
||||
// list the files in the folder
|
||||
let tiles: string[] = [];
|
||||
|
||||
fs.readdir(folder, (err, files) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
|
||||
files.forEach(file => {
|
||||
tiles.push(file);
|
||||
});
|
||||
|
||||
// send over the list of tiles to the socket
|
||||
callback(tiles);
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user