1
0
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:
2024-06-22 21:00:24 +02:00
parent 1851df8059
commit f5191aa81f
17 changed files with 270 additions and 71 deletions

View 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);
});
});
}