Add foundations for the data request sockets
This commit is contained in:
parent
8632054e63
commit
ce6ac8a93b
8 changed files with 48 additions and 0 deletions
|
|
@ -31,6 +31,13 @@
|
|||
"system": "Text-Based Actors"
|
||||
}
|
||||
}
|
||||
},
|
||||
"notifs": {
|
||||
"error": {
|
||||
"invalid-socket": "Invalid socket data received, this means a module or system bug is present.",
|
||||
"unknown-socket-event": "An unknown socket event was received: {event}",
|
||||
"malformed-socket-payload": "Socket event \"{event}\" received with malformed payload. Details: {details}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import { __ID__ } from "../consts.mjs";
|
|||
import helpers from "../handlebarsHelpers/_index.mjs";
|
||||
import { Logger } from "../utils/Logger.mjs";
|
||||
import { registerCustomComponents } from "../apps/elements/_index.mjs";
|
||||
import { registerSockets } from "../sockets/_index.mjs";
|
||||
|
||||
Hooks.on(`init`, () => {
|
||||
Logger.debug(`Initializing`);
|
||||
|
|
@ -41,6 +42,7 @@ Hooks.on(`init`, () => {
|
|||
|
||||
registerWorldSettings();
|
||||
|
||||
registerSockets();
|
||||
registerCustomComponents();
|
||||
Handlebars.registerHelper(helpers);
|
||||
});
|
||||
|
|
|
|||
34
module/sockets/_index.mjs
Normal file
34
module/sockets/_index.mjs
Normal 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);
|
||||
});
|
||||
};
|
||||
1
module/sockets/cancelRequest.mjs
Normal file
1
module/sockets/cancelRequest.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export function cancelRequest() {};
|
||||
1
module/sockets/createNotif.mjs
Normal file
1
module/sockets/createNotif.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export function createNotif() {};
|
||||
1
module/sockets/dataRequest.mjs
Normal file
1
module/sockets/dataRequest.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export function dataRequest() {};
|
||||
1
module/sockets/submitRequest.mjs
Normal file
1
module/sockets/submitRequest.mjs
Normal file
|
|
@ -0,0 +1 @@
|
|||
export function submitRequest() {};
|
||||
|
|
@ -41,6 +41,7 @@
|
|||
},
|
||||
"Item": {}
|
||||
},
|
||||
"socket": true,
|
||||
"flags": {
|
||||
"hotReload": {
|
||||
"extensions": ["css", "hbs", "json", "js", "mjs", "svg"],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue