Add foundations for the data request sockets

This commit is contained in:
Eldritch-Oliver 2025-11-05 22:41:53 -07:00
parent 8632054e63
commit ce6ac8a93b
8 changed files with 48 additions and 0 deletions

34
module/sockets/_index.mjs Normal file
View file

@ -0,0 +1,34 @@
import { cancelRequest } from "./cancelRequest.mjs";
import { createNotif } from "./createNotif.mjs";
import { dataRequest } from "./dataRequest.mjs";
import { localizer } from "../utils/Localizer.mjs";
import { Logger } from "../utils/Logger.mjs";
import { submitRequest } from "./submitRequest.mjs";
const events = {
// Data Request sockets
cancelRequest,
createNotif,
dataRequest,
submitRequest,
};
export function registerSockets() {
Logger.info(`Setting up socket listener`);
game.socket.on(`system.taf`, (data, userID) => {
const { event, payload } = data ?? {};
if (event == null || payload === undefined) {
ui.notifications.error(localizer(`taf.notifs.error.invalid-socket`));
return;
};
if (events[event] == null) {
ui.notifications.error(localizer(`taf.notifs.error.unknown-socket-event`, { event }));
return;
};
const user = game.users.get(userID);
events[event](payload, user);
});
};