From bc0e30795980c8b688c06c14018f18815ccbc2ce Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 5 Jan 2021 11:47:22 +0100 Subject: [PATCH] #107 : Correction sur boucle de re-entrance sur la creation des monnaies --- module/actor.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/module/actor.js b/module/actor.js index 25cdd2fb..695a0e2d 100644 --- a/module/actor.js +++ b/module/actor.js @@ -45,6 +45,9 @@ export class RdDActor extends Actor { } // If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic if (data.items) { + if (data.type == "personnage") { + await RdDActor.checkMonnaiePresence( data.items ); + } return super.create(data, options); } @@ -107,45 +110,42 @@ export class RdDActor extends Actor { this.computeEncombrementTotalEtMalusArmure(); this.computeEtatGeneral(); // Sanity check - let newMonnaie = this.checkMonnaiePresence(); - if ( newMonnaie.length > 0 ) - await this.createOwnedItem( newMonnaie ); + RdDActor.checkMonnaiePresence(actorData.items); } /* -------------------------------------------- */ - checkMonnaiePresence( ) { // Ajout opportuniste si les pièces n'existent pas. - let newMonnaie = []; - let piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1); + static checkMonnaiePresence( items ) { // Ajout opportuniste si les pièces n'existent pas. + if( !items) return; // Sanity check during import + let piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1); if (!piece) { - newMonnaie.push( RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp" ) ); + items.push( RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp" ) ); } - piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10); + piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 10); if (!piece) { - newMonnaie.push(RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp") ); + items.push(RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp") ); } - piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100); + piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 100); if (!piece) { - newMonnaie.push(RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp")); + items.push(RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp")); } - piece = this.data.items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000); + piece = items.find( item => item.type =='monnaie' && Number(item.data.valeur_deniers) == 1000); if (!piece) { - newMonnaie.push(RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp") ); + items.push(RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp") ); } - return newMonnaie; } /* -------------------------------------------- */ static async ajouterMonnaie( items ) { // Creation auto à la création du personnage - let etain = RdDUtility.createMonnaie("Etain (1 denier)", 1); + let etain = RdDUtility.createMonnaie("Etain (1 denier)", 1, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp); items.push(etain); - let bronze = RdDUtility.createMonnaie("Bronze (10 deniers)", 10); + let bronze = RdDUtility.createMonnaie("Bronze (10 deniers)", 10, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp"); items.push(bronze); - let argent = RdDUtility.createMonnaie("Argent (1 sol)", 100); + let argent = RdDUtility.createMonnaie("Argent (1 sol)", 100, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp"); items.push(argent); - let or = RdDUtility.createMonnaie("Or (10 sols)", 1000); + let or = RdDUtility.createMonnaie("Or (10 sols)", 1000, "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp"); items.push(or); }