Merge branch 'v1.4-fix-socket-loop' into 'v1.4'

Fix: boucle infinie de messages

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!254
This commit is contained in:
Leratier Bretonnien 2021-05-27 05:37:57 +00:00
commit 3793563a2c
11 changed files with 75 additions and 62 deletions

View File

@ -14,7 +14,7 @@
"TypeNombreastral": "Nombre astral",
"TypeTarot": "Carte de tarot",
"TypeCasetmr": "TMR spéciale",
"TypeRencontresTMR": "Rencontre TMR",
"TypeRencontrestmr": "Rencontre TMR",
"TypeMunition": "Munition",
"TypeMonnaie": "Monnaie",
"TypeHerbe": "Herbe ou plante",

View File

@ -56,14 +56,17 @@ export class RdDActor extends Actor {
}
}
static remoteActorCall(options) {
console.log("remoteActorCall ", options)
options.userId = options.userId ?? Misc.connectedGMOrUser();
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: options });
static remoteActorCall(data) {
if (Misc.isElectedUser()){
RdDActor.onRemoteActorCall(data);
}
else{
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: data });
}
}
static onRemoteActorCall(data) {
if (game.user.id == data.userId) { // Seul le joueur choisi effectue l'appel
if (Misc.isElectedUser()) { // 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);
@ -2400,8 +2403,9 @@ export class RdDActor extends Actor {
let rollData = {
competence: compData,
tache: tacheData,
diffConditions: tacheData.data.difficulte,
use: { libre: false, conditions: false },
diffLibre: tacheData.data.difficulte,
diffConditions: 0,
use: { libre: false, conditions: true },
carac: {}
};
rollData.carac[tacheData.data.carac] = duplicate(actorData.data.carac[tacheData.data.carac]); // Single carac
@ -3425,8 +3429,7 @@ export class RdDActor extends Actor {
}
if (!Misc.isElectedUser()) {
RdDActor.remoteActorCall({
userId: Misc.connectedGMOrUser(),
actorId: this.vendeur?.id ?? this.acheteur?.id,
actorId: vendeurId ?? acheteurId,
method: 'achatVente', args: [vendeurId, acheteurId, venteData, chatMessageIdVente]
});
return;

View File

@ -23,19 +23,24 @@ export class ChatUtility {
game.messages.get(data.messageId)?.delete();
}
}
}
static removeMessages(data) {
if (Misc.isElectedUser()){
ChatUtility.onRemoveMessages(data);
}
else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_delete_chat_message", data: data });
}
}
/* -------------------------------------------- */
static removeChatMessageContaining(part) {
ChatUtility.onRemoveMessages({ part: part });
ChatUtility.removeMessages({ part: part });
}
static removeChatMessageId(messageId) {
ChatUtility.onRemoveMessages({ messageId: messageId });
ChatUtility.removeMessages({ messageId: messageId });
}
/* -------------------------------------------- */

View File

@ -37,17 +37,23 @@ const MAX_NOMBRE_ASTRAL = 12;
/* -------------------------------------------- */
export class RdDCalendrier extends Application {
getCalendrier(index) {
let calendrier = {
heureRdD: 0, // Index dans heuresList
minutesRelative: 0,
moisRdD: Math.floor(index / 28) % 12,
jour: (index - (month * 28)) + 1
}
return calendrier;
}
/* -------------------------------------------- */
async initCalendrier() {
// Calendrier
this.calendrier = duplicate(game.settings.get("foundryvtt-reve-de-dragon", "calendrier"));
//console.log("CALENDRIER", this.calendrier);
if (this.calendrier == undefined || this.calendrier.moisRdD == undefined) {
this.calendrier = {};
this.calendrier.heureRdD = 0; // Index dans heuresList
this.calendrier.minutesRelative = 0;
this.calendrier.moisRdD = 0; // Index dans heuresList
this.calendrier.jour = 0;
this.calendrier = this.getCalendrier(0);
if (game.user.isGM) { // Uniquement si GM
game.settings.set("foundryvtt-reve-de-dragon", "calendrier", this.calendrier);
}
@ -86,8 +92,8 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
getDateFromIndex(index = undefined) {
if (!index) index = this.getCurrentDayIndex();
getDateFromIndex(index) {
index = index ?? this.getCurrentDayIndex();
let month = Math.floor(index / 28);
let day = (index - (month * 28)) + 1;
return day + " " + heuresList[month];
@ -131,6 +137,11 @@ export class RdDCalendrier extends Application {
/* -------------------------------------------- */
async ajouterNombreAstral(index) {
const nombreAstral = await RdDDice.rollTotal("1dh", { showDice: true, rollMode: "selfroll" });
const dateFuture = this.getDateFromIndex(index);
ChatMessage.create({
whisper: ChatMessage.getWhisperRecipients("GM"),
content: `Le chiffre astrologique du ${dateFuture} sera le ${nombreAstral}`
});
return {
nombreAstral: nombreAstral,
valeursFausses: [],
@ -139,9 +150,9 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
async getCurrentNombreAstral() {
getCurrentNombreAstral() {
let indexDate = this.getCurrentDayIndex();
return await this.getNombreAstral(indexDate);
return this.getNombreAstral(indexDate);
}
/* -------------------------------------------- */
@ -151,14 +162,13 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
async getNombreAstral(indexDate) {
getNombreAstral(indexDate) {
const liste = this.listeNombreAstral ?? this._loadListNombreAstral();
let astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
if (!astralData?.nombreAstral) {
await this.rebuildListeNombreAstral();
astralData = liste.find((nombreAstral, i) => nombreAstral.index == indexDate);
this.rebuildListeNombreAstral();
}
return astralData?.nombreAstral ?? "N/A";
return astralData?.nombreAstral;
}
/* -------------------------------------------- */
@ -217,7 +227,7 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
async incrementerJour() {
incrementerJour() {
this.calendrier.jour += 1;
if (this.calendrier.jour >= RDD_JOUR_PAR_MOIS) {
this.calendrier.jour -= RDD_JOUR_PAR_MOIS;
@ -226,13 +236,13 @@ export class RdDCalendrier extends Application {
this.calendrier.moisRdD += 1;
// Reconstruire les nombres astraux
}
await this.rebuildListeNombreAstral();
this.rebuildListeNombreAstral();
}
/* -------------------------------------------- */
async syncPlayerTime(calendrier) {
syncPlayerTime(calendrier) {
this.calendrier = duplicate(calendrier); // Local copy update
await this.updateDisplay();
this.updateDisplay();
}
/* -------------------------------------------- */
@ -287,7 +297,7 @@ export class RdDCalendrier extends Application {
showDice: false
};
await RdDResolutionTable.rollData(rollData);
let nbAstral = await this.getNombreAstral(request.date);
let nbAstral = this.getNombreAstral(request.date);
request.rolled = rollData.rolled;
request.isValid = true;
if (!request.rolled.isSuccess) {
@ -311,11 +321,11 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
async getAjustementAstrologique(heureNaissance, name = 'inconnu') {
getAjustementAstrologique(heureNaissance, name = 'inconnu') {
let heure = Grammar.toLowerCaseNoAccent(heureNaissance);
if (heure && heuresDef[heure]) {
let hn = heuresDef[heure].heure;
let chiffreAstral = await this.getCurrentNombreAstral();
let chiffreAstral = this.getCurrentNombreAstral() ?? 0;
let heureCourante = this.calendrier.heureRdD;
let ecartChance = (hn + chiffreAstral - heureCourante) % 12;
switch (ecartChance) {
@ -362,12 +372,12 @@ export class RdDCalendrier extends Application {
}
/* -------------------------------------------- */
async updateDisplay() {
updateDisplay() {
let data = this.fillCalendrierData();
// Rebuild data
let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`;
let dateHTML = `Jour ${data.jourMois} de ${data.nomMois} (${data.nomSaison})`
if (game.user.isGM) {
dateHTML = dateHTML + " - NA: " + await this.getCurrentNombreAstral();
dateHTML = dateHTML + " - NA: " + (this.getCurrentNombreAstral() ?? "indéterminé");
}
for (let handle of document.getElementsByClassName("calendar-date-rdd")) {
handle.innerHTML = dateHTML;
@ -393,7 +403,7 @@ export class RdDCalendrier extends Application {
await this.rebuildListeNombreAstral();
await this.updateDisplay();
this.updateDisplay();
}
/* -------------------------------------------- */

View File

@ -491,20 +491,14 @@ export class RdDCombat {
/* -------------------------------------------- */
static onMsgDefense(msg) {
let defenderToken = canvas.tokens.get(msg.defenderTokenId);
if (defenderToken) {
if (!game.user.isGM && !game.user.character) { // vérification / sanity check
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
return;
}
if (Misc.isElectedUser()) {
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
if (rddCombat) {
const defenderRoll = msg.defenderRoll;
RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
RdDCombat._storeDefense(defenderRoll);
rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
rddCombat._chatMessageDefense(msg.paramChatDefense);
}
if (defenderToken && Misc.isElectedUser()) {
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
if (rddCombat) {
const defenderRoll = msg.defenderRoll;
RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
RdDCombat._storeDefense(defenderRoll);
rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
rddCombat._chatMessageDefense(msg.paramChatDefense);
}
}
}

View File

@ -143,6 +143,8 @@ Hooks.once("init", async function () {
/* -------------------------------------------- */
game.socket.on("system.foundryvtt-reve-de-dragon", sockmsg => {
console.log(">>>>> MSG RECV", sockmsg);
RdDUtility.onSocketMesssage(sockmsg);
RdDCombat.onSocketMessage(sockmsg);
ChatUtility.onSocketMessage(sockmsg);

View File

@ -547,7 +547,6 @@ export class RdDUtility {
/* -------------------------------------------- */
static onSocketMesssage(sockmsg) {
console.log(">>>>> MSG RECV", sockmsg);
switch (sockmsg.msg) {
case "msg_gm_chat_message":
return ChatUtility.handleGMChatMessage(sockmsg.data);
@ -602,9 +601,6 @@ export class RdDUtility {
let actor = RdDUtility.getSelectedActor("Pour effectuer le paiement:");
if (actor) {
actor.depenserDeniers(sumdenier, objData, quantite, fromActorId);
// TODO: diminuer la quantité ou supprimer le message
// message: => document.querySelector("#chat-log > li:nth-child(61) > div > div > span > a")
// => ../../../..[@data-message-id]
let chatMessageId = RdDUtility.findChatMessageId(event.currentTarget);
if (chatMessageId) {
ChatUtility.removeChatMessageId(chatMessageId);

View File

@ -14,7 +14,9 @@
<span class="item-quantite">{{numberFormat item.data.encTotal decimals=2}}</span>
<div class="item-controls flex-grow">
{{#unless item.estContenu}}
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-hand-rock"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a>
{{#if (ne item.type 'conteneur')}}
<a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-hand-rock"></i>{{else}}<i class="far fa-hand-paper"></i>{{/if}}</a>
{{/if}}
{{/unless}}
<a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a>
<a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>

View File

@ -610,13 +610,14 @@
</li>
{{#each objets as |item id|}}
{{#unless item.estContenu}}
{{#if (eq item.type 'conteneur')}}
{{buildConteneur this}}
{{else}}
{{#if (ne item.type 'conteneur')}}
{{> "systems/foundryvtt-reve-de-dragon/templates/actor-sheet-inventaire-conteneur.html" item=item }}
{{/if}}
{{/unless}}
{{/each}}
{{#each conteneurs as |conteneur id|}}
{{buildConteneur this}}
{{/each}}
</ul>
<span class="item-name"><h4>Montures</h4></span>

View File

@ -1,8 +1,8 @@
<div id="calendar-time-container">
<div class="calendar">
{{#if isGM}}
<i class="calendar-btn-edit fas fa-cog" title="Editer"></i>
<i class="astrologie-btn-edit fas fa-cog" title="Astrologie"></i>
<i class="calendar-btn calendar-btn-edit fas fa-cog" title="Editer"></i>
<i class="calendar-btn astrologie-btn-edit fas fa-cog" title="Astrologie"></i>
{{/if}}
<div class="calendar-hdr">
<p id="calendar-move-handle" class="calendar-date-rdd" title="Deplacer">Jour {{jourMois}} de {{nomMois}} ({{nomSaison}})</p>

View File

@ -1,5 +1,5 @@
<div class="post-item" data-transfer="{{transfer}}">
<h3>{{#if alias}}{{alias}} propose:{{else}}Acheter {{/if}}{{item.name}}</h3>
<h3>{{#if alias}}{{alias}} propose: {{else}}Acheter {{/if}}{{item.name}}</h3>
{{#if item.img}}
<img src="{{item.img}}" title="{{item.name}}" />
{{/if}}