1
0
forked from noxious/server

object stuff

This commit is contained in:
2024-07-04 13:38:12 +02:00
parent 829a2ef726
commit 9c80efbb51
13 changed files with 67 additions and 52 deletions

View File

@ -0,0 +1,42 @@
import { Server } from "socket.io";
import {TSocket} from "../../../utilities/Types";
import fs from 'fs';
import path from "path";
interface IPayload {
}
/**
* Handle game master list object event
* @param socket
* @param io
*/
export default function (socket: TSocket, io: Server) {
socket.on('gm:tile:list', async (data: any, callback: (response: string[]) => void) => {
if (socket.character?.role !== 'gm') {
console.log(`---Character #${socket.character?.id} is not a game master.`);
return;
}
// get root path
const folder = path.join(process.cwd(), '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.replace('.png', ''));
});
// send over the list of object to the socket
callback(tiles);
});
});
}