refreshAppId : Using a debounce to limit the bandwidth
This commit is contained in:
@@ -131,11 +131,11 @@
|
||||
"title": "GM ToolBox",
|
||||
"difficulty_hidden": "Modifier la visibilité de la difficulté",
|
||||
"difficulty": "Modifier la difficulté (Clic Droit: ajout, Gauche: soustraction, Milieu: ND 2)",
|
||||
"sleep": "Repos confortable pour tous les personnages (Enlève Eau x2 de fatigue. Clic Droit: Personnage contrôlé uniquement. Gauche: Tous)",
|
||||
"sleep": "Repos confortable pour tous les personnages (Enlève Eau x2 de fatigue. Clic Droit: Personnages contrôlés uniquement. Gauche: Tous)",
|
||||
"sleep_info": "Les personnages ont passé une bonne nuit de sommeil.",
|
||||
"scene_end": "Fin de scène (Conflit et Fatigue à moitié pour tous les personnages dont la valeur dépasse ce seuil. Clic Droit: Personnage contrôlé uniquement. Gauche: Tous)",
|
||||
"scene_end": "Fin de scène (Conflit et Fatigue à moitié pour tous les personnages dont la valeur dépasse ce seuil. Clic Droit: Personnages contrôlés uniquement. Gauche: Tous)",
|
||||
"scene_end_info": "La tension de la scène retombe enfin",
|
||||
"reset_void": "Début de partie : Réinitialiser les points du vide des joueurs (Clic Droit: Personnage contrôlé uniquement. Gauche: Tous)",
|
||||
"reset_void": "Début de partie : Réinitialiser les points du vide des joueurs (Clic Droit: Personnages contrôlés uniquement. Gauche: Tous)",
|
||||
"reset_void_info": "Les points du vide ont été attribués"
|
||||
},
|
||||
"gm_monitor": {
|
||||
|
||||
@@ -237,14 +237,14 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
}
|
||||
const stepKey = $(event.target).data("step");
|
||||
if (!stepKey) {
|
||||
console.warn("event stepKey is undefined");
|
||||
console.warn("L5R5E | Event stepKey is undefined");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Get item
|
||||
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
||||
if (item.documentName !== "Item" || !item) {
|
||||
console.warn(`forbidden item for this drop zone ${type} : ${item.data.type}`);
|
||||
console.warn(`L5R5E | Forbidden item for this drop zone ${type} : ${item.data.type}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
(type !== "item" && item.data.type !== type) ||
|
||||
(type === "item" && !["item", "weapon", "armor"].includes(item.data.type))
|
||||
) {
|
||||
console.warn(`forbidden item for this drop zone ${type} : ${item.data.type}`);
|
||||
console.warn(`L5R5E | Forbidden item for this drop zone ${type} : ${item.data.type}`);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -269,7 +269,9 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
// School Ability
|
||||
if (stepKey === "step3.school_ability") {
|
||||
if (item.data.data.technique_type !== "school_ability") {
|
||||
console.warn(`This technique is not a school ability : ${item.data.data.technique_type}`);
|
||||
console.warn(
|
||||
`L5R5E | This technique is not a school ability : ${item.data.data.technique_type}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else if (!this.object.data.step3.allowed_techniques?.[item.data.data.technique_type]) {
|
||||
@@ -283,37 +285,37 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
switch (stepKey) {
|
||||
case "step9.distinction":
|
||||
if (item.data.data.peculiarity_type !== "distinction") {
|
||||
console.warn("Wrong type", item.data.data.peculiarity_type);
|
||||
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "step10.adversity":
|
||||
if (item.data.data.peculiarity_type !== "adversity") {
|
||||
console.warn("Wrong type", item.data.data.peculiarity_type);
|
||||
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "step11.passion":
|
||||
if (item.data.data.peculiarity_type !== "passion") {
|
||||
console.warn("Wrong type", item.data.data.peculiarity_type);
|
||||
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "step12.anxiety":
|
||||
if (item.data.data.peculiarity_type !== "anxiety") {
|
||||
console.warn("Wrong type", item.data.data.peculiarity_type);
|
||||
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "step13.advantage":
|
||||
if (!["distinction", "passion"].includes(item.data.data.peculiarity_type)) {
|
||||
console.warn("Wrong type", item.data.data.peculiarity_type);
|
||||
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case "step13.disadvantage":
|
||||
if (!["adversity", "anxiety"].includes(item.data.data.peculiarity_type)) {
|
||||
console.warn("Wrong type", item.data.data.peculiarity_type);
|
||||
console.warn("L5R5E | Wrong type", item.data.data.peculiarity_type);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -326,7 +328,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
||||
|
||||
this.submit();
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
console.warn("L5R5E | ", err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -190,11 +190,11 @@ export class GmToolbox extends FormApplication {
|
||||
return;
|
||||
}
|
||||
|
||||
// Left clic: controlled pc only, others: all actors
|
||||
const isAll = event.which !== 1;
|
||||
const type = $(event.currentTarget).data("type");
|
||||
|
||||
for await (const actor of game.actors.contents) {
|
||||
// only controlled pc
|
||||
if (!isAll && (actor.data.type !== "character" || !actor.hasPlayerOwner)) {
|
||||
continue;
|
||||
}
|
||||
@@ -240,12 +240,8 @@ export class GmToolbox extends FormApplication {
|
||||
});
|
||||
}
|
||||
|
||||
ui.notifications.info(game.i18n.localize(`l5r5e.gm_toolbox.${type}_info`));
|
||||
|
||||
// Refresh gm-monitor
|
||||
Object.values(ui.windows)
|
||||
.find((e) => e.id === "l5r5e-gm-monitor")
|
||||
?.refresh();
|
||||
game.l5r5e.sockets.refreshAppId("l5r5e-gm-monitor");
|
||||
ui.notifications.info(
|
||||
` <i class="fas fa-user${isAll ? "s" : ""}"></i> ` + game.i18n.localize(`l5r5e.gm_toolbox.${type}_info`)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,4 +545,42 @@ export class HelpersL5r5e {
|
||||
}
|
||||
return "roll";
|
||||
}
|
||||
|
||||
/**
|
||||
* Isolated Debounce by Id
|
||||
*
|
||||
* Usage : game.l5r5e.HelpersL5r5e.debounce('appId', (text) => { console.log(text) })('my text');
|
||||
*
|
||||
* @param id Named id
|
||||
* @param callback Callback function
|
||||
* @param timeout Wait time (500ms by default)
|
||||
* @param leading If true the callback will be executed only at the first debounced-function call,
|
||||
* otherwise the callback will only be executed `delay` milliseconds after the last debounced-function call
|
||||
* @return {(function(...[*]=): void)|*}
|
||||
*/
|
||||
static debounce(id, callback, timeout = 500, leading = false) {
|
||||
/* eslint-disable no-undef */
|
||||
if (!debounce.timeId) {
|
||||
debounce.timeId = {};
|
||||
}
|
||||
return (...args) => {
|
||||
if (leading) {
|
||||
// callback will be executed only at the first debounced-function call
|
||||
if (!debounce.timeId[id]) {
|
||||
callback.apply(this, args);
|
||||
}
|
||||
clearTimeout(debounce.timeId[id]);
|
||||
debounce.timeId[id] = setTimeout(() => {
|
||||
debounce.timeId[id] = undefined;
|
||||
}, timeout);
|
||||
} else {
|
||||
// callback will only be executed `delay` milliseconds after the last debounced-function call
|
||||
clearTimeout(debounce.timeId[id]);
|
||||
debounce.timeId[id] = setTimeout(() => {
|
||||
callback.apply(this, args);
|
||||
}, timeout);
|
||||
}
|
||||
};
|
||||
/* eslint-enable no-undef */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export class ItemL5r5e extends Item {
|
||||
// **** Embed Items, need to get the parents ****
|
||||
const parentItem = this.getItemFromParentId();
|
||||
if (!parentItem) {
|
||||
console.warn(`Embed parentItem not found`);
|
||||
console.warn(`L5R5E | Embed parentItem not found`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ export class SocketHandlerL5r5e {
|
||||
break;
|
||||
|
||||
default:
|
||||
console.warn(new Error("This socket event is not supported"), data);
|
||||
console.warn(new Error("L5R5E | This socket event is not supported"), data);
|
||||
break;
|
||||
}
|
||||
});
|
||||
@@ -61,10 +61,12 @@ export class SocketHandlerL5r5e {
|
||||
* @param appId
|
||||
*/
|
||||
refreshAppId(appId) {
|
||||
game.l5r5e.HelpersL5r5e.debounce(appId, () => {
|
||||
game.socket.emit(SocketHandlerL5r5e.SOCKET_NAME, {
|
||||
type: "refreshAppId",
|
||||
appId,
|
||||
});
|
||||
})();
|
||||
}
|
||||
_onRefreshAppId(data) {
|
||||
const app = Object.values(ui.windows).find((e) => e.id === data.appId);
|
||||
|
||||
Reference in New Issue
Block a user