import { Server } from "socket.io"; import {TSocket} from "../../utilities/Types"; import {writeFile} from "node:fs"; import {randomUUID} from "node:crypto"; import path from "path"; import fs from "fs"; interface IPayload { tile: string; } /** * Handle game master remove tile event * @param socket * @param io */ export default function (socket: TSocket, io: Server) { socket.on('gm:tile:remove', async (data: IPayload, callback: (response: boolean) => void) => { if (socket.character?.role !== 'gm') { return; } // get root path const public_folder = path.join(process.cwd(), 'public', 'tiles'); // remove the tile from the disk const finalFilePath = path.join(public_folder, data.tile); fs.unlink(finalFilePath, (err) => { if (err) { console.log(err); callback(false); return; } callback(true); }); }); }