From 4f91fab3d5acb554f690709b520dac9c06faf4e6 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 26 Nov 2021 00:45:21 +0100 Subject: [PATCH 1/8] Executions une seule fois MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix sur les actions à faire une seule fois en cas de plusieurs GM Quand plusieurs GM ou assistant GM sont connectés, ils exécutaient tous certaines actions. Conséquence: ajout de casetmr en doublon, détermination de 2 chiffres astraux, modification d'initiative de premier tour en double --- module/actor.js | 12 ++++++------ module/chat-utility.js | 6 +++--- module/misc.js | 20 ++++++++++++++++---- module/rdd-astrologie-joueur.js | 6 +++--- module/rdd-calendrier.js | 11 ++++------- module/rdd-combat.js | 12 ++++++------ module/rdd-main.js | 3 ++- 7 files changed, 40 insertions(+), 30 deletions(-) diff --git a/module/actor.js b/module/actor.js index 3ca22631..ae849614 100644 --- a/module/actor.js +++ b/module/actor.js @@ -63,7 +63,7 @@ export class RdDActor extends Actor { } static remoteActorCall(data) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueConnectedGM()) { RdDActor.onRemoteActorCall(data); } else { @@ -72,7 +72,7 @@ export class RdDActor extends Actor { } static onRemoteActorCall(data) { - if (Misc.isElectedUser()) { // Seul le joueur choisi effectue l'appel + if (Misc.isUniqueConnectedGM()) { // Seul le joueur choisi effectue l'appel const actor = game.actors.get(data?.actorId); if (!actor) { console.info("RdDActor.onRemoteActorCall: Pas d'Actor disponible ", data); @@ -3685,7 +3685,7 @@ export class RdDActor extends Actor { ui.notifications.info("Inutile de se vendre à soi-même"); return; } - if (!Misc.isElectedUser()) { + if (!Misc.isUniqueConnectedGM()) { RdDActor.remoteActorCall({actorId: achat.vendeurId ?? achat.acheteurId, method: 'achatVente', args: [achat]}); return; } @@ -4172,7 +4172,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async onCreateOwnedDraconique(item, options, id) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueConnectedGM()) { let draconique = Draconique.all().find(it => it.match(item)); if (draconique) { draconique.onActorCreateOwned(this, item) @@ -4183,7 +4183,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async onDeleteOwnedDraconique(item, options, id) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueConnectedGM()) { let draconique = Draconique.all().find(it => it.match(item)); if (draconique) { draconique.onActorDeleteOwned(this, item) @@ -4193,7 +4193,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async onDeleteOwnedCaseTmr(item, options, id) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueConnectedGM()) { let draconique = Draconique.all().find(it => it.isCase(item)); if (draconique) { draconique.onActorDeleteCaseTmr(this, Misc.data(item)) diff --git a/module/chat-utility.js b/module/chat-utility.js index dd80bb55..224b2d2b 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -41,7 +41,7 @@ export class ChatUtility { /* -------------------------------------------- */ static onRemoveMessages(data) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueConnectedGM()) { if (data.part) { const toDelete = game.messages.filter(it => it.data.content.includes(data.part)); toDelete.forEach(it => it.delete()); @@ -53,7 +53,7 @@ export class ChatUtility { } static onRemoveMessages(data) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueConnectedGM()) { if (data.part) { const toDelete = game.messages.filter(it => it.data.content.includes(data.part)); toDelete.forEach(it => it.delete()); @@ -66,7 +66,7 @@ export class ChatUtility { /* -------------------------------------------- */ static removeMessages(data) { - if (Misc.isElectedUser()){ + if (Misc.isUniqueConnectedGM()){ ChatUtility.onRemoveMessages(data); } else { diff --git a/module/misc.js b/module/misc.js index f6e0c7f1..83918a00 100644 --- a/module/misc.js +++ b/module/misc.js @@ -126,12 +126,24 @@ export class Misc { if (ownerId && game.user.id == ownerId) { return ownerId; } - return (game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id) ?? game.user.id; - } - static isElectedUser() { - return game.user.id == Misc.connectedGMOrUser(); + return Misc.firstConnectedGM()?.id ?? game.user.id; } + static getActiveUser(id){ + return game.users.entities.find(u => u.id == id && u.active); + } + + static firstConnectedGM() { + return game.users.entities.sort(Misc.ascending(u => u.id)).find(u => u.isGM && u.active); + } + + /** + * @returns true pour un seul utilisateur: le premier GM connecté par ordre d'id + */ + static isUniqueConnectedGM() { + return game.user.id == Misc.firstConnectedGM()?.id; + } + /* -------------------------------------------- */ static findPlayer(name) { return Misc.findFirstLike(name, game.users, { description: 'joueur' }); diff --git a/module/rdd-astrologie-joueur.js b/module/rdd-astrologie-joueur.js index dd5ae006..bf0c3692 100644 --- a/module/rdd-astrologie-joueur.js +++ b/module/rdd-astrologie-joueur.js @@ -68,9 +68,10 @@ export class RdDAstrologieJoueur extends Dialog { etat: this.dataNombreAstral.etat, astrologie: this.dataNombreAstral.astrologie, conditions: $("#diffConditions").val(), - date: $("#joursAstrologie").val() + date: $("#joursAstrologie").val(), + userId: game.user.id } - if (game.user.isGM) { + if (Misc.isUniqueConnectedGM()) { game.system.rdd.calendrier.requestNombreAstral(data); } else { game.socket.emit("system.foundryvtt-reve-de-dragon", { @@ -83,7 +84,6 @@ export class RdDAstrologieJoueur extends Dialog { /* -------------------------------------------- */ quitDialog() { - } /* -------------------------------------------- */ diff --git a/module/rdd-calendrier.js b/module/rdd-calendrier.js index 4807f485..aa923569 100644 --- a/module/rdd-calendrier.js +++ b/module/rdd-calendrier.js @@ -82,12 +82,9 @@ export class RdDCalendrier extends Application { this.calendrier.annee = this.calendrier.annee ?? Math.floor((this.calendrier.moisRdD ?? 0) / RDD_MOIS_PAR_AN); this.calendrier.moisRdD = (this.calendrier.moisRdD ?? 0) % RDD_MOIS_PAR_AN; - if (game.user.isGM) { // Uniquement si GM + if (Misc.isUniqueConnectedGM()) { // Uniquement si GM game.settings.set(SYSTEM_RDD, "calendrier", this.calendrier); - } - // nombre astral - if (game.user.isGM) { this.listeNombreAstral = this.getListeNombreAstral(); this.rebuildListeNombreAstral(false); // Ensure always up-to-date } @@ -189,7 +186,7 @@ export class RdDCalendrier extends Application { /* -------------------------------------------- */ async rebuildListeNombreAstral(showDice = true) { - if (game.user.isGM) { + if (Misc.isUniqueConnectedGM()) { console.log("rebuildListeNombreAstral", showDice); let jourCourant = this.getCurrentDayIndex(); let newList = []; @@ -320,7 +317,7 @@ export class RdDCalendrier extends Application { /* -------------------------------------------- */ async requestNombreAstral(request) { - if (game.user.isGM) { // Only GM + if (Misc.isUniqueConnectedGM()) { // Only once console.log(request); let jourDiff = this.getLectureAstrologieDifficulte(request.date); let niveau = Number(request.astrologie.data.niveau) + Number(request.conditions) + Number(jourDiff) + Number(request.etat); @@ -343,7 +340,7 @@ export class RdDCalendrier extends Application { game.settings.set(SYSTEM_RDD, "liste-nombre-astral", this.listeNombreAstral); } request.nbAstral = nbAstral; - if (game.user.isGM) { + if (Misc.getActiveUser(request.userId)?.isGM) { RdDUtility.responseNombreAstral(request); } else { game.socket.emit("system.foundryvtt-reve-de-dragon", { diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 4fb9e504..6826fcf6 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -227,7 +227,7 @@ export class RdDCombatManager extends Combat { /* -------------------------------------------- */ static processPremierRoundInit() { // Check if we have the whole init ! - if (game.user.isGM && game.combat.current.round == 1) { + if (Misc.isUniqueConnectedGM() && game.combat.current.round == 1) { let initMissing = game.combat.data.combatants.find(it => !it.initiative); if (!initMissing) { // Premier round ! for (let combatant of game.combat.data.combatants) { @@ -422,7 +422,7 @@ export class RdDCombat { /* -------------------------------------------- */ static combatNouveauTour(combat) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueSingleUser()) { let turn = combat.turns.find(t => t.token?.id == combat.current.tokenId); if (turn?.actor) { RdDCombat.displayActorCombatStatus(combat, turn.actor); @@ -540,7 +540,7 @@ export class RdDCombat { /* -------------------------------------------- */ static onMsgEncaisser(data) { - if (Misc.isElectedUser()) { + if (Misc.isUniqueSingleUser()) { let attackerRoll = RdDCombat._getAttaque(data.attackerId); // Retrieve the rolldata from the store let attacker = data.attackerId ? game.actors.get(data.attackerId) : null; let defender = canvas.tokens.get(data.defenderTokenId).actor; @@ -555,7 +555,7 @@ export class RdDCombat { /* -------------------------------------------- */ static onMsgDefense(msg) { let defenderToken = canvas.tokens.get(msg.defenderTokenId); - if (defenderToken && Misc.isElectedUser()) { + if (defenderToken && Misc.isUniqueSingleUser()) { const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId); if (rddCombat) { const defenderRoll = msg.defenderRoll; @@ -913,7 +913,7 @@ export class RdDCombat { dmg: attackerRoll.dmg, }; - if (!Misc.isElectedUser()) { + if (!Misc.isUniqueSingleUser()) { this._socketSendMessageDefense(paramChatDefense, defenderRoll); } else { @@ -1286,7 +1286,7 @@ export class RdDCombat { this._onEchecTotal(defenderRoll); } - if (Misc.isElectedUser()) { + if (Misc.isUniqueSingleUser()) { attackerRoll.attackerId = this.attackerId; attackerRoll.defenderTokenId = defenderTokenId; diff --git a/module/rdd-main.js b/module/rdd-main.js index 63680276..175dfc2f 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -34,6 +34,7 @@ import { RdDItem } from "./item.js"; import { RdDDice } from "./rdd-dice.js"; import { RdDPossession } from "./rdd-possession.js"; import { RdDSigneDraconiqueItemSheet } from "./item-signedraconique-sheet.js"; +import { Misc } from "./misc.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -254,7 +255,7 @@ Hooks.once("ready", async function () { user: game.user.id }); } - if (game.user.isGM) { + if (Misc.isUniqueConnectedGM()) { messageDeBienvenue(); } }); From 05398a74f0213124ae45258b6321c6fc81337812 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 26 Nov 2021 00:46:26 +0100 Subject: [PATCH 2/8] Fix: ajout de stress avec personnage ouvert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L'ajout de stress prennait le stress d'un personnage ouvert au lieu de la saisie dans la fenêtre d'ajout de stress --- module/dialog-stress.js | 6 +++--- templates/dialog-stress.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/module/dialog-stress.js b/module/dialog-stress.js index 210b9918..cc136977 100644 --- a/module/dialog-stress.js +++ b/module/dialog-stress.js @@ -46,9 +46,9 @@ export class DialogStress extends Dialog { validerStress() { - this.dialogData.motif = $("[name='motif']").val(); - this.dialogData.stress = $("[name='stress']").val(); - this.dialogData.immediat = $("[name='immediat']").prop("checked");; + this.dialogData.motif = $("form.rdddialogstress input[name='motif']").val(); + this.dialogData.stress = $("form.rdddialogstress input[name='stress']").val(); + this.dialogData.immediat = $("form.rdddialogstress input[name='immediat']").prop("checked");; } /* -------------------------------------------- */ diff --git a/templates/dialog-stress.html b/templates/dialog-stress.html index 4273ab70..12a6608f 100644 --- a/templates/dialog-stress.html +++ b/templates/dialog-stress.html @@ -1,4 +1,4 @@ -
+
From 2ea69c40774baca87829044acd75a6bfbb273531 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 26 Nov 2021 01:00:28 +0100 Subject: [PATCH 3/8] Minor: format +/- MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Utiliser des classes pour formattage commun plutôt que des ids --- module/actor-entite-sheet.js | 4 ++-- module/actor-sheet.js | 20 +++++++++---------- styles/simple.css | 2 +- templates/actor-sheet-inventaire-monnaie.html | 5 ++++- templates/actor-sheet.html | 20 +++++++++---------- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/module/actor-entite-sheet.js b/module/actor-entite-sheet.js index 8508c7ee..aa836cbf 100644 --- a/module/actor-entite-sheet.js +++ b/module/actor-entite-sheet.js @@ -108,11 +108,11 @@ export class RdDActorEntiteSheet extends ActorSheet { this.actor.rollCompetence( compName ); }); - html.find('#endurance-plus').click((event) => { + html.find('.endurance-plus').click((event) => { this.actor.santeIncDec("endurance", 1); this.render(true); }); - html.find('#endurance-moins').click((event) => { + html.find('.endurance-moins').click((event) => { this.actor.santeIncDec("endurance", -1); this.render(true); }); diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 3306bb30..1eec4a57 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -468,10 +468,10 @@ export class RdDActorSheet extends ActorSheet { this.actor.jetEthylisme(); }); - html.find('#jet-vie').click(async event => { + html.find('.jet-vie').click(async event => { this.actor.jetVie(); }); - html.find('#jet-endurance').click(async event => { + html.find('.jet-endurance').click(async event => { this.actor.jetEndurance(); }); @@ -484,28 +484,28 @@ export class RdDActorSheet extends ActorSheet { this.actor.monnaieIncDec(li.data("item-id"), -1); }); - html.find('#vie-plus').click(async event => { + html.find('.vie-plus').click(async event => { this.actor.santeIncDec("vie", 1); }); - html.find('#vie-moins').click(async event => { + html.find('.vie-moins').click(async event => { this.actor.santeIncDec("vie", -1); }); - html.find('#endurance-plus').click(async event => { + html.find('.endurance-plus').click(async event => { this.actor.santeIncDec("endurance", 1); }); - html.find('#endurance-moins').click(async event => { + html.find('.endurance-moins').click(async event => { this.actor.santeIncDec("endurance", -1); }); - html.find('#ptreve-actuel-plus').click(async event => { + html.find('.ptreve-actuel-plus').click(async event => { this.actor.reveActuelIncDec(1); }); - html.find('#ptreve-actuel-moins').click(async event => { + html.find('.ptreve-actuel-moins').click(async event => { this.actor.reveActuelIncDec(-1); }); - html.find('#fatigue-plus').click(async event => { + html.find('.fatigue-plus').click(async event => { this.actor.santeIncDec("fatigue", 1); }); - html.find('#fatigue-moins').click(async event => { + html.find('.fatigue-moins').click(async event => { this.actor.santeIncDec("fatigue", -1); }); } diff --git a/styles/simple.css b/styles/simple.css index c9e26778..e3a37cbe 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -644,7 +644,7 @@ section.sheet-body:after { max-width: 90%; } -#vie-plus, #vie-moins, #endurance-plus, #endurance-moins, #fatigue-plus, #fatigue-moins, #ptreve-actuel-plus, #ptreve-actuel-moins, .monnaie-plus, .monnaie-moins { +.plus-moins { display: inline-block; width: 1.25rem; background: rgba(30, 25, 20, 1); diff --git a/templates/actor-sheet-inventaire-monnaie.html b/templates/actor-sheet-inventaire-monnaie.html index 58166551..d73224b2 100644 --- a/templates/actor-sheet-inventaire-monnaie.html +++ b/templates/actor-sheet-inventaire-monnaie.html @@ -5,7 +5,10 @@ {{piece.name}} {{piece.data.quantite}} - +- + + + + - +
diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 09eb6f74..d4884cb3 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -11,39 +11,39 @@
From addfc46069e71655c5d5d60b1748f41ed7d1d61c Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 26 Nov 2021 01:01:57 +0100 Subject: [PATCH 4/8] =?UTF-8?q?Titres=20de=20colonnes=20en=20vue=20d=C3=A9?= =?UTF-8?q?taill=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout des titres des colonnes de compétences en vue détaillée --- ...r-sheet-categorie-competences-partial.html | 19 +++++++++++++++++++ templates/actor-sheet-competence-partial.html | 2 ++ 2 files changed, 21 insertions(+) diff --git a/templates/actor-sheet-categorie-competences-partial.html b/templates/actor-sheet-categorie-competences-partial.html index 8a20a5e5..75ea7bd4 100644 --- a/templates/actor-sheet-categorie-competences-partial.html +++ b/templates/actor-sheet-categorie-competences-partial.html @@ -2,6 +2,25 @@ {{categorie}}