ArmorStack use as User query

This commit is contained in:
Dapoolp 2025-07-08 19:38:02 +02:00
parent 7d7fb88035
commit e23ca28418
7 changed files with 101 additions and 57 deletions

View file

@ -1,4 +1,4 @@
export function handleSocketEvent({ action = null, data = {} } = {}) {
export function handleSocketEvent({ action = null, data = {} } = {}, ...args) {
switch (action) {
case socketEvent.GMUpdate:
Hooks.callAll(socketEvent.GMUpdate, data);
@ -63,21 +63,28 @@ export const registerSocketHooks = () => {
});
};
export const emitAsGM = async (eventName, callback, args) => {
export const emitAsGM = async (eventName, callback, update, uuid = null) => {
if(!game.user.isGM) {
return new Promise(async (resolve, reject) => {
try {
const response = await game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.GMUpdate,
data: {
action: eventName,
update: args
}
});
resolve(response);
} catch (error) {
reject(error);
return await game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.GMUpdate,
data: {
action: eventName,
uuid,
update
}
})
} else return callback(args);
});
} else return callback(update);
}
export const emitAsOwner = (eventName, userId, args) => {
if(userId === game.user.id) return;
if(!eventName || !userId) return false;
game.socket.emit(`system.${CONFIG.DH.id}`, {
action: eventName,
data: {
userId,
...args
}
});
return false;
}