forked from noxious/server
object stuff
This commit is contained in:
42
src/app/events/gm/tile/GmTileList.ts
Normal file
42
src/app/events/gm/tile/GmTileList.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user