refreshAppId : Using a debounce to limit the bandwidth
This commit is contained in:
@@ -131,11 +131,11 @@
|
|||||||
"title": "GM ToolBox",
|
"title": "GM ToolBox",
|
||||||
"difficulty_hidden": "Modifier la visibilité de la difficulté",
|
"difficulty_hidden": "Modifier la visibilité de la difficulté",
|
||||||
"difficulty": "Modifier la difficulté (Clic Droit: ajout, Gauche: soustraction, Milieu: ND 2)",
|
"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.",
|
"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",
|
"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"
|
"reset_void_info": "Les points du vide ont été attribués"
|
||||||
},
|
},
|
||||||
"gm_monitor": {
|
"gm_monitor": {
|
||||||
|
|||||||
@@ -237,14 +237,14 @@ export class TwentyQuestionsDialog extends FormApplication {
|
|||||||
}
|
}
|
||||||
const stepKey = $(event.target).data("step");
|
const stepKey = $(event.target).data("step");
|
||||||
if (!stepKey) {
|
if (!stepKey) {
|
||||||
console.warn("event stepKey is undefined");
|
console.warn("L5R5E | Event stepKey is undefined");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Get item
|
// Get item
|
||||||
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
const item = await game.l5r5e.HelpersL5r5e.getDragnDropTargetObject(event);
|
||||||
if (item.documentName !== "Item" || !item) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
|||||||
(type !== "item" && item.data.type !== type) ||
|
(type !== "item" && item.data.type !== type) ||
|
||||||
(type === "item" && !["item", "weapon", "armor"].includes(item.data.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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,7 +269,9 @@ export class TwentyQuestionsDialog extends FormApplication {
|
|||||||
// School Ability
|
// School Ability
|
||||||
if (stepKey === "step3.school_ability") {
|
if (stepKey === "step3.school_ability") {
|
||||||
if (item.data.data.technique_type !== "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;
|
return;
|
||||||
}
|
}
|
||||||
} else if (!this.object.data.step3.allowed_techniques?.[item.data.data.technique_type]) {
|
} else if (!this.object.data.step3.allowed_techniques?.[item.data.data.technique_type]) {
|
||||||
@@ -283,37 +285,37 @@ export class TwentyQuestionsDialog extends FormApplication {
|
|||||||
switch (stepKey) {
|
switch (stepKey) {
|
||||||
case "step9.distinction":
|
case "step9.distinction":
|
||||||
if (item.data.data.peculiarity_type !== "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;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "step10.adversity":
|
case "step10.adversity":
|
||||||
if (item.data.data.peculiarity_type !== "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;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "step11.passion":
|
case "step11.passion":
|
||||||
if (item.data.data.peculiarity_type !== "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;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "step12.anxiety":
|
case "step12.anxiety":
|
||||||
if (item.data.data.peculiarity_type !== "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;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "step13.advantage":
|
case "step13.advantage":
|
||||||
if (!["distinction", "passion"].includes(item.data.data.peculiarity_type)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "step13.disadvantage":
|
case "step13.disadvantage":
|
||||||
if (!["adversity", "anxiety"].includes(item.data.data.peculiarity_type)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -326,7 +328,7 @@ export class TwentyQuestionsDialog extends FormApplication {
|
|||||||
|
|
||||||
this.submit();
|
this.submit();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn("L5R5E | ", err);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,11 +190,11 @@ export class GmToolbox extends FormApplication {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Left clic: controlled pc only, others: all actors
|
||||||
const isAll = event.which !== 1;
|
const isAll = event.which !== 1;
|
||||||
const type = $(event.currentTarget).data("type");
|
const type = $(event.currentTarget).data("type");
|
||||||
|
|
||||||
for await (const actor of game.actors.contents) {
|
for await (const actor of game.actors.contents) {
|
||||||
// only controlled pc
|
|
||||||
if (!isAll && (actor.data.type !== "character" || !actor.hasPlayerOwner)) {
|
if (!isAll && (actor.data.type !== "character" || !actor.hasPlayerOwner)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -240,12 +240,8 @@ export class GmToolbox extends FormApplication {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.notifications.info(game.i18n.localize(`l5r5e.gm_toolbox.${type}_info`));
|
ui.notifications.info(
|
||||||
|
` <i class="fas fa-user${isAll ? "s" : ""}"></i> ` + 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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -545,4 +545,42 @@ export class HelpersL5r5e {
|
|||||||
}
|
}
|
||||||
return "roll";
|
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 ****
|
// **** Embed Items, need to get the parents ****
|
||||||
const parentItem = this.getItemFromParentId();
|
const parentItem = this.getItemFromParentId();
|
||||||
if (!parentItem) {
|
if (!parentItem) {
|
||||||
console.warn(`Embed parentItem not found`);
|
console.warn(`L5R5E | Embed parentItem not found`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ export class SocketHandlerL5r5e {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -61,10 +61,12 @@ export class SocketHandlerL5r5e {
|
|||||||
* @param appId
|
* @param appId
|
||||||
*/
|
*/
|
||||||
refreshAppId(appId) {
|
refreshAppId(appId) {
|
||||||
|
game.l5r5e.HelpersL5r5e.debounce(appId, () => {
|
||||||
game.socket.emit(SocketHandlerL5r5e.SOCKET_NAME, {
|
game.socket.emit(SocketHandlerL5r5e.SOCKET_NAME, {
|
||||||
type: "refreshAppId",
|
type: "refreshAppId",
|
||||||
appId,
|
appId,
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
_onRefreshAppId(data) {
|
_onRefreshAppId(data) {
|
||||||
const app = Object.values(ui.windows).find((e) => e.id === data.appId);
|
const app = Object.values(ui.windows).find((e) => e.id === data.appId);
|
||||||
|
|||||||
Reference in New Issue
Block a user