diff --git a/module/actor-entite-sheet.js b/module/actor-entite-sheet.js index 41f444c0..b7a02afd 100644 --- a/module/actor-entite-sheet.js +++ b/module/actor-entite-sheet.js @@ -71,14 +71,14 @@ export class RdDActorEntiteSheet extends ActorSheet { // Update Inventory Item html.find('.item-edit').click(ev => { const li = $(ev.currentTarget).parents(".item"); - const item = this.actor.getOwnedItem(li.data("itemId")); + const item = this.actor.getEmbeddedDocuments('Item', li.data("itemId")); item.sheet.render(true); }); // Delete Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); - this.actor.deleteOwnedItem(li.data("itemId")); + this.actor.deleteEmbeddedDocuments('Item', [li.data("itemId")]); li.slideUp(200, () => this.render(false)); }); diff --git a/module/actor-vehicule-sheet.js b/module/actor-vehicule-sheet.js index 10ef7aaf..c6c62235 100644 --- a/module/actor-vehicule-sheet.js +++ b/module/actor-vehicule-sheet.js @@ -87,7 +87,7 @@ export class RdDActorVehiculeSheet extends ActorSheet { // Update Inventory Item html.find('.item-edit').click(ev => { const li = $(ev.currentTarget).parents(".item"); - const item = this.actor.getOwnedItem(li.data("itemId")); + const item = this.actor.getEmbeddedDocuments('Item', li.data("itemId")); item.sheet.render(true); }); // Delete Inventory Item diff --git a/module/actor.js b/module/actor.js index e0fbc1d5..6822a9d6 100644 --- a/module/actor.js +++ b/module/actor.js @@ -39,12 +39,14 @@ export class RdDActor extends Actor { static init() { Hooks.on("deleteActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onDeleteActiveEffect(effect, options)); Hooks.on("createActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onCreateActiveEffect(effect, options)); - Hooks.on("createOwnedItem", (item, options, id) => RdDActor.getParentActor(item)?.onCreateOwnedItem(item, options, id)); - Hooks.on("deleteOwnedItem", (item, options, id) => RdDActor.getParentActor(item)?.onDeleteOwnedItem(item, options, id)); + + Hooks.on("preUpdateItem", (item, change, options, id) => RdDActor.getParentActor(item)?.onPreUpdateItem(item, change, options, id)); + Hooks.on("createItem", (item, options, id) => RdDActor.getParentActor(item)?.onCreateItem(item, options, id)); + Hooks.on("deleteItem", (item, options, id) => RdDActor.getParentActor(item)?.onDeleteItem(item, options, id)); Hooks.on("updateActor", (actor, change, options, actorId) => actor.onUpdateActor(change, options, actorId)); } - static getParentActor(document){ + static getParentActor(document) { return document?.parent instanceof Actor ? document.parent : undefined } @@ -241,10 +243,10 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ getObjet(id) { - return id ? this.items.find(it => it._id == id) : undefined; + return id ? this.data.items.find(it => it.id == id) : undefined; } - getItemOfType(type, id) { - return id ? this.items.find(it => it._id == id && it.type == type) : undefined; + getItemOfType(id, type) { + return id ? this.data.items.find(it => it.id == id && it.type == type) : undefined; } getMonnaie(id) { return this.getItemOfType(id, 'monnaie'); @@ -266,7 +268,7 @@ export class RdDActor extends Actor { return this.getItemOfType(id, 'musique'); } getOeuvre(id, type = 'oeuvre') { - return this.getItemOfType(type, id); + return this.getItemOfType(id, type); } getJeu(id) { return this.getItemOfType(id, 'jeu'); @@ -685,7 +687,7 @@ export class RdDActor extends Actor { else update['data.carac_value'] = compValue; //console.log(update); - const updated = await this.updateEmbeddedDocuments("Item", update); // Updates one EmbeddedEntity + const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity } } @@ -706,7 +708,7 @@ export class RdDActor extends Actor { }); } const update = { _id: comp.id, 'data.niveau': nouveauNiveau }; - await this.updateEmbeddedDocuments("Item", update); // Updates one EmbeddedEntity + await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity } else { console.log("Competence not found", compName); } @@ -719,7 +721,7 @@ export class RdDActor extends Actor { compValue = compValue ?? 0; this.checkCompetenceXP(compName, compValue); const update = { _id: comp.id, 'data.xp': compValue }; - await this.updateEmbeddedDocuments("OwnedItem", update); // Updates one EmbeddedEntity + await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity } else { console.log("Competence not found", compName); } @@ -732,7 +734,7 @@ export class RdDActor extends Actor { if (comp) { compValue = compValue ?? 0; const update = { _id: comp.id, 'data.xp_sort': compValue }; - await this.updateEmbeddedDocuments("OwnedItem", update); // Updates one EmbeddedEntity + await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity } else { console.log("Competence not found", compName); } @@ -744,7 +746,7 @@ export class RdDActor extends Actor { if (comp) { compValue = compValue ?? 0; const update = { _id: comp.id, 'data.niveau_archetype': compValue }; - await this.updateEmbeddedDocuments("OwnedItem", update); // Updates one EmbeddedEntity + await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity } else { console.log("Competence not found", compName); } @@ -860,10 +862,7 @@ export class RdDActor extends Actor { let list = []; list.push({ id: itemId, conteneurId: undefined }); // Init list this.buildSubConteneurObjetList(itemId, list); - //console.log("List to delete", list); - for (let item of list) { - await this.deleteOwnedItem(item.id); - } + await this.deleteEmbeddedDocuments('Item', list.map(it => it.id)); } /* -------------------------------------------- */ @@ -880,7 +879,7 @@ export class RdDActor extends Actor { contenu.splice(index, 1); index = contenu.indexOf(itemId); } - await this.updateEmbeddedDocuments("OwnedItem", data2use); + await this.updateEmbeddedDocuments('Item', [data2use]); } } @@ -892,7 +891,7 @@ export class RdDActor extends Actor { if (conteneur?.type == 'conteneur') { let data2use = duplicate(Misc.data(conteneur)); data2use.data.contenu.push(itemId); - await this.updateEmbeddedDocuments("OwnedItem", data2use); + await this.updateEmbeddedDocuments('Item', [data2use]); } } @@ -907,7 +906,7 @@ export class RdDActor extends Actor { } } if (conteneurFixedList.length > 0) - await this.updateOwnedItem(conteneurFixedList); + await this.updateEmbeddedDocuments('Item', conteneurFixedList); } /* -------------------------------------------- */ @@ -935,11 +934,11 @@ export class RdDActor extends Actor { console.log('New conteneur filling!', newConteneur, newItemId, item); let contenu = duplicate(newConteneur.data.contenu); contenu.push(newItemId); - await this.updateOwnedItem({ _id: newConteneurId, 'data.contenu': contenu }); + await this.updateEmbeddedDocuments('Item', [{ _id: newConteneurId, 'data.contenu': contenu }]); } } for (let item of itemsList) { - await sourceActor.deleteOwnedItem(item.id); + await sourceActor.deleteEmbeddedDocuments('Item', [item.id]); } } @@ -1837,7 +1836,7 @@ export class RdDActor extends Actor { if (rencSpecial) { rencSpecial = duplicate(rencSpecial); // To keep it if (rencSpecial.type != 'souffle') { - this.deleteOwnedItem(rencSpecial._id); // Suppression dans la liste des queues + this.deleteEmbeddedDocuments('Item', [rencSpecial._id]); // Suppression dans la liste des queues addMsg = " La queue a été supprimée de votre fiche automatiquement"; } else { addMsg = " Vous devez gérer manuellement le décompte de mauvaises rencontres manuellement."; @@ -2075,7 +2074,7 @@ export class RdDActor extends Actor { async _tacheResult(rollData) { // Mise à jour de la tache rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache; - this.updateEmbeddedDocuments("OwnedItem", rollData.tache); + this.updateEmbeddedDocuments('Item', [rollData.tache]); this.santeIncDec("fatigue", rollData.tache.data.fatigue); RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html'); @@ -2084,7 +2083,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _tacheETotal(rollData) { rollData.tache.data.difficulte--; - this.updateEmbeddedDocuments("OwnedItem", rollData.tache); + this.updateEmbeddedDocuments('Item', [rollData.tache]); } /* -------------------------------------------- */ @@ -2249,7 +2248,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _meditationETotal(meditationData) { meditationData.meditation.data.malus--; - this.updateEmbeddedDocuments("OwnedItem", meditationData.meditation); + this.updateEmbeddedDocuments('Item', [meditationData.meditation]); } /* -------------------------------------------- */ @@ -2352,7 +2351,7 @@ export class RdDActor extends Actor { xpComp = xp - xpCarac; competence = duplicate(competence); competence.data.xp = Misc.toInt(competence.data.xp) + xpComp; - await this.updateEmbeddedDocuments("OwnedItem", competence); + await this.updateEmbeddedDocuments('Item', [competence]); } else { xpCarac = Math.max(xpCarac, 1); } @@ -2386,12 +2385,12 @@ export class RdDActor extends Actor { name: "Nombre Astral", type: "nombreastral", data: { value: data.nbAstral, istrue: data.isvalid, jourindex: Number(data.date), jourlabel: game.system.rdd.calendrier.getDateFromIndex(Number(data.date)) } }; - await this.createEmbeddedDocuments("OwnedItem", [item]); + await this.createEmbeddedDocuments("Item", [item]); // Suppression des anciens nombres astraux let toDelete = this.data.items.filter(it => it.data.jourindex < game.system.rdd.calendrier.getCurrentDayIndex()); const deletions = toDelete.map(it => it._id); - await this.deleteEmbeddedDocuments("OwnedItem", deletions); + await this.deleteEmbeddedDocuments("Item", deletions); // Affichage Dialog this.astrologieNombresAstraux(); @@ -2533,7 +2532,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ getArmeParade(armeParadeId) { - const item = armeParadeId ? this.getOwnedItem(armeParadeId) : undefined; + const item = armeParadeId ? this.getEmbeddedDocuments('Item', armeParadeId) : undefined; return RdDItemArme.getArmeData(item); } @@ -2550,12 +2549,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async equiperObjet(itemID) { - let item = this.getOwnedItem(itemID); + let item = this.getEmbeddedDocuments('Item', itemID); if (item?.data?.data) { let itemData = Misc.itemData(item); const isEquipe = !itemData.data.equipe; let update = { _id: item._id, "data.equipe": isEquipe }; - await this.updateEmbeddedDocuments("OwnedItem", update); + await this.updateEmbeddedDocuments('Item', [update]); this.computeEncombrementTotalEtMalusArmure(); // Mise à jour encombrement this.computePrixTotalEquipement(); // Mis à jour du prix total de l'équipement if (isEquipe) @@ -2595,7 +2594,7 @@ export class RdDActor extends Actor { if (!ReglesOptionelles.isUsing('deteriorationArmure')) { return; } - let itemData = duplicate(Misc.itemData(item)); + let itemData = duplicate(Misc.data(item)); itemData.data.deterioration = (itemData.data.deterioration ?? 0) + dmg; if (itemData.data.deterioration >= 10) { itemData.data.deterioration = 0; @@ -2612,7 +2611,7 @@ export class RdDActor extends Actor { } ChatMessage.create({ content: "Votre armure s'est détériorée, elle protège maintenant de " + itemData.data.protection }); } - this.updateEmbeddedDocuments("OwnedItem", itemData); + this.updateEmbeddedDocuments('Item', [itemData]); } /* -------------------------------------------- */ @@ -2857,17 +2856,18 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async optimizeArgent(sumDenier, monnaies) { - let parValeur = Misc.classifyFirst(monnaies, it => it.data.valeur_deniers); + let parValeur = Misc.classifyFirst(monnaies, it => Misc.templateData(it).valeur_deniers); let fortune = { 1000: Math.floor(sumDenier / 1000), // or 100: Math.floor(sumDenier / 100) % 10, // argent 10: Math.floor(sumDenier / 10) % 10, // bronze 1: sumDenier % 10 // étain } + let updates = [] for (const [valeur, nombre] of Object.entries(fortune)) { - let piece = parValeur[valeur]; - await this.updateEmbeddedDocuments("OwnedItem", { _id: piece._id, 'data.quantite': nombre }); + updates.push( { _id: parValeur[valeur]._id, 'data.quantite': nombre }); } + await this.updateEmbeddedDocuments('Item', updates); } /* -------------------------------------------- */ @@ -2881,8 +2881,8 @@ export class RdDActor extends Actor { sumDenier = Number(sumDenier); let denierDisponible = 0; - for (let piece of monnaies) { - denierDisponible += piece.data.valeur_deniers * Number(piece.data.quantite); + for (let pieceData of monnaies.map(m => Misc.data(m))) { + denierDisponible += pieceData.data.valeur_deniers * Number(pieceData.data.quantite); } console.log("DENIER", game.user.character, sumDenier, denierDisponible); @@ -2916,7 +2916,7 @@ export class RdDActor extends Actor { let monnaie = this.getMonnaie(id); if (monnaie) { const quantite = Math.max(0, Misc.templateData(monnaie).quantite + value); - await this.updateEmbeddedDocuments("OwnedItem", { _id: monnaie.id, 'data.quantite': quantite }); + await this.updateEmbeddedDocuments('Item', [{ _id: monnaie.id, 'data.quantite': quantite }]); } } @@ -3138,15 +3138,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async updateEmbeddedDocuments(embeddedName, data, options) { - if (data?.type == 'competence' && data['data.defaut_carac'] && data['data.xp']) { // C'est une compétence - this.checkCompetenceXP(data['name'], data['data.xp']); - } - return super.updateEmbeddedDocuments(embeddedName, [data], options); - } - - /* -------------------------------------------- */ - async onCreateOwnedItem(item, options, id) { + async onCreateItem(item, options, id) { switch (item.type) { case 'tete': case 'queue': @@ -3157,7 +3149,14 @@ export class RdDActor extends Actor { } } - async onDeleteOwnedItem(item, options, id) { + async onPreUpdateItem(item, change, options, id) { + const itemData = Misc.data(item); + if (itemData.type == 'competence' && itemData.data.defaut_carac && itemData.data.xp) { + await this.checkCompetenceXP(itemData.name, itemData.data.xp); + } + } + + async onDeleteItem(item, options, id) { switch (item.type) { case 'tete': case 'queue': diff --git a/module/hook-renderChatLog.js b/module/hook-renderChatLog.js index c34d03d8..64dec8c0 100644 --- a/module/hook-renderChatLog.js +++ b/module/hook-renderChatLog.js @@ -3,7 +3,7 @@ import { RdDUtility } from "./rdd-utility.js"; /* -------------------------------------------- */ // Activate chat listeners defined -Hooks.on('renderChatLog', (log, html, data) => { - RdDUtility.chatListeners(html); -}); +// Hooks.on('renderChatLog', (log, html, data) => { +// RdDUtility.chatListeners(html); +// }); diff --git a/module/item-sort.js b/module/item-sort.js index 3c0afa72..eeeaf634 100644 --- a/module/item-sort.js +++ b/module/item-sort.js @@ -106,7 +106,7 @@ export class RdDItemSort extends Item { // Sauvegarde/update let bonuscase = StringList.toString(); //console.log("Bonus cae :", bonuscase); - actor.updateEmbeddedDocuments("OwnedItem", { _id: sort._id, 'data.bonuscase': bonuscase } ); + actor.updateEmbeddedDocuments('Item', [{ _id: sort._id, 'data.bonuscase': bonuscase }] ); } /* -------------------------------------------- */ diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 7f53d402..f9788418 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -104,7 +104,7 @@ export class RdDCombatManager extends Combat { const roll = super._getInitiativeRoll(c, rollFormula); if (roll.total <= 0) roll.total = 0.00; console.log("Compute init for", rollFormula, roll.total); - await this.updateEmbeddedDocuments("Combatant", { _id: c._id, initiative: roll.total }); + await this.updateEmbeddedDocuments("Combatant", [{ _id: c._id, initiative: roll.total }]); // Send a chat message let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode"); @@ -334,8 +334,8 @@ export class RdDCombat { static init() { this.initStorePasseArmes(); - Hooks.on("updateCombat", (combat, data) => { RdDCombat.onUpdateCombat(combat, data) }); - Hooks.on("preDeleteCombat", (combat, options) => { RdDCombat.onPreDeleteCombat(combat, options); }); + Hooks.on("updateCombat", (combat, change, options, userId) => { RdDCombat.onUpdateCombat(combat, change, options, userId) }); + Hooks.on("preDeleteCombat", (combat, options, userId) => { RdDCombat.onPreDeleteCombat(combat, options, userId); }); } /* -------------------------------------------- */ @@ -357,14 +357,14 @@ export class RdDCombat { } /* -------------------------------------------- */ - static onUpdateCombat(combat, data) { + static onUpdateCombat(combat, change, options, userId) { if (combat.data.round != 0 && combat.turns && combat.data.active) { RdDCombat.combatNouveauTour(combat); } } /* -------------------------------------------- */ - static onPreDeleteCombat(combat, options) { + static onPreDeleteCombat(combat, options, userId) { if (game.user.isGM) { combat.cleanItemUse(); ChatUtility.removeChatMessageContaining(`
`) @@ -1130,7 +1130,7 @@ export class RdDCombat { resistance -= perteResistance; defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise' : 'perte'; defenderRoll.show.perteResistance = perteResistance; - this.defender.updateEmbeddedDocuments("OwnedItem", { _id: defenderRoll.arme._id, 'data.resistance': resistance }); + this.defender.updateEmbeddedDocuments('Item', [{ _id: defenderRoll.arme._id, 'data.resistance': resistance }]); } } } else { @@ -1147,7 +1147,7 @@ export class RdDCombat { resistance -= dmg; defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise' : 'perte'; defenderRoll.show.perteResistance = dmg; - this.defender.updateEmbeddedDocuments("OwnedItem", { _id: defenderRoll.arme._id, 'data.resistance': resistance }); + this.defender.updateEmbeddedDocuments('Item', [{ _id: defenderRoll.arme._id, 'data.resistance': resistance }]); } } // Si l'arme de parade n'est pas un bouclier, jet de désarmement (p.132) diff --git a/module/rdd-main.js b/module/rdd-main.js index 0f147060..8802a03e 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -153,6 +153,7 @@ Hooks.once("init", async function () { CONFIG.Combat.documentClass = RdDCombatManager; // préparation des différents modules + RdDUtility.init(); RdDCommands.init(); RdDCombat.init(); RdDCombatManager.init(), @@ -224,8 +225,3 @@ Hooks.on("chatMessage", (html, content, msg) => { return true; }); - -/* -------------------------------------------- */ -Hooks.on("renderChatMessage", async (app, html, msg) => { - RdDUtility.onRenderChatMessage(app, html, msg); -}); diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js index fc4932ce..7c9d6a21 100644 --- a/module/rdd-tmr-dialog.js +++ b/module/rdd-tmr-dialog.js @@ -130,14 +130,16 @@ export class RdDTMRDialog extends Dialog { return EffetsDraconiques.rencontre.token(this.pixiTMR, rencontre, () => rencontre.coord); } _tokenCaseSpeciale(casetmr) { - const draconique = Draconique.get(casetmr.data.specific); - return draconique?.token(this.pixiTMR, casetmr, () => casetmr.data.coord); + const caseData = Misc.data(casetmr); + const draconique = Draconique.get(caseData.data.specific); + return draconique?.token(this.pixiTMR, caseData, () => caseData.data.coord); } _tokenSortEnReserve(sortEnReserve) { return EffetsDraconiques.sortReserve.token(this.pixiTMR, sortEnReserve.sort, () => sortEnReserve.coord); } _tokenDemiReve() { - return EffetsDraconiques.demiReve.token(this.pixiTMR, this.actor, () => Misc.data(this.actor).data.reve.tmrpos.coord); + const actorData = Misc.data(this.actor); + return EffetsDraconiques.demiReve.token(this.pixiTMR, actorData, () => actorData.data.reve.tmrpos.coord); } _updateDemiReve() { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 502447cf..743dde39 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -92,6 +92,13 @@ const definitionsEncaissement = { /* -------------------------------------------- */ export class RdDUtility { + + /* -------------------------------------------- */ + static async init() { + Hooks.on("renderChatMessage", async (app, html, msg) => RdDUtility.onRenderChatMessage(app, html, msg)); + Hooks.on('renderChatLog', (log, html, data) => RdDUtility.chatListeners(html)); + } + /* -------------------------------------------- */ static async preloadHandlebarsTemplates() { const templatePaths = [ @@ -544,7 +551,7 @@ export class RdDUtility { actor.tmrApp.lancerSortEnReserve(coord, sortId); }); // Gestion du bouton payer - html.on("click", '#payer-button', event => { + html.on("click", '.payer-button', event => { let sumdenier = event.currentTarget.attributes['data-somme-denier'].value; let quantite = 1; if (event.currentTarget.attributes['data-quantite']) { @@ -595,7 +602,7 @@ export class RdDUtility { let sumtotald = sumd + (sums * 100); let msgPayer = "La somme de " + sums + " Sols et " + sumd + " Deniers est à payer, cliquer sur le lien ci-dessous si besoin.
"; - msgPayer += "Payer" + msgPayer += "Payer" ChatMessage.create({ content: msgPayer }); } @@ -658,7 +665,7 @@ export class RdDUtility { label: "Supprimer l'objet", callback: () => { console.log("Delete : ", itemId); - actorSheet.actor.deleteOwnedItem(itemId); + actorSheet.actor.deleteEmbeddedDocuments('Item', [itemId]); li.slideUp(200, () => actorSheet.render(false)); } }, diff --git a/module/tmr/conquete.js b/module/tmr/conquete.js index ba7dffeb..09bf1eef 100644 --- a/module/tmr/conquete.js +++ b/module/tmr/conquete.js @@ -29,14 +29,14 @@ export class Conquete extends Draconique { } async _creerConquete(actor, queue) { - let existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); + let existants = actor.data.items.filter(it => this.isCase(it)).map(it => Misc.data(it).data.coord); let possibles = TMRUtility.filterTMR(tmr => !TMRUtility.isCaseHumide(tmr) && !existants.includes(tmr.coord)); let conquete = Misc.rollOneOf(possibles); - await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue._id); + await this.createCaseTmr(actor, 'Conquête: ' + conquete.label, conquete, queue.id); } async onActorDeleteCaseTmr(actor, casetmr) { - await actor.deleteOwnedItem(casetmr.data.sourceid); + await actor.deleteEmbeddedDocuments('Item', [casetmr.data.sourceid]); } } diff --git a/module/tmr/debordement.js b/module/tmr/debordement.js index 21e5a5fd..90362f29 100644 --- a/module/tmr/debordement.js +++ b/module/tmr/debordement.js @@ -14,7 +14,7 @@ export class Debordement extends Draconique { async onActorCreateOwned(actor, souffle) { const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); const tmr = TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord))); - await this.createCaseTmr(actor, 'Debordement: ' + tmr.label, tmr, souffle._id); + await this.createCaseTmr(actor, 'Debordement: ' + tmr.label, tmr, souffle.id); } code() { return 'debordement' } diff --git a/module/tmr/desorientation.js b/module/tmr/desorientation.js index 1dcec96a..0fc1d46c 100644 --- a/module/tmr/desorientation.js +++ b/module/tmr/desorientation.js @@ -43,7 +43,7 @@ export class Desorientation extends Draconique { const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); let tmrs = TMRUtility.filterTMR(it => it.type == type && !existants.includes(it.coord)); for (let tmr of tmrs) { - await this.createCaseTmr(actor, 'Désorientation: ' + tmr.label, tmr, souffle._id); + await this.createCaseTmr(actor, 'Désorientation: ' + tmr.label, tmr, souffle.id); } } diff --git a/module/tmr/draconique.js b/module/tmr/draconique.js index 6061d7d9..9ca5848e 100644 --- a/module/tmr/draconique.js +++ b/module/tmr/draconique.js @@ -1,3 +1,4 @@ +import { Misc } from "../misc.js"; import { TMRUtility } from "../tmr-utility.js"; import { PixiTMR } from "./pixi-tmr.js"; @@ -8,11 +9,11 @@ const registeredEffects = [ * Définition des informations d'une "draconique" (queue, ombre, tête, souffle) qui influence les TMR */ export class Draconique { - static isCaseTMR(element) { return element.type == 'casetmr'; } - static isQueueDragon(element) { return element.type == 'queue' || element.type == 'ombre'; } - static isSouffleDragon(element) { return element.type == 'souffle'; } - static isTeteDragon(element) { return element.type == 'tete'; } - static isQueueSouffle(it) { return Draconique.isQueueDragon(it) || Draconique.isSouffleDragon(it); } + static isCaseTMR(itemData) { return itemData.type == 'casetmr'; } + static isQueueDragon(itemData) { return itemData.type == 'queue' || itemData.type == 'ombre'; } + static isSouffleDragon(itemData) { return itemData.type == 'souffle'; } + static isTeteDragon(itemData) { return itemData.type == 'tete'; } + static isQueueSouffle(itemData) { return Draconique.isQueueDragon(itemData) || Draconique.isSouffleDragon(itemData); } tmrLabel(linkData) { return TMRUtility.getTMRLabel(linkData.data.coord); } @@ -37,7 +38,8 @@ export class Draconique { * @returns true si l'item correspond */ match(item) { - return Draconique.isQueueDragon(item) || Draconique.isSouffleDragon(item) || Draconique.isTeteDragon(item); + const itemData = Misc.data(item); + return Draconique.isQueueDragon(itemData) || Draconique.isSouffleDragon(itemData) || Draconique.isTeteDragon(itemData); } /** @@ -110,35 +112,40 @@ export class Draconique { /** * - * @param {*} it un item à tester + * @param {*} item un item à tester * @param {*} coord les coordonnées d'une case. Si undefined toute case du type correspondra, */ - isCase(it, coord = undefined) { - return Draconique.isCaseTMR(it) && it.data.specific == this.code() && (coord ? it.data.coord == coord : true); + isCase(item, coord = undefined) { + const itemData = Misc.data(item); + return Draconique.isCaseTMR(itemData) && itemData.data.specific == this.code() && (coord ? itemData.data.coord == coord : true); } - + find(list, coord = undefined) { - return list.find(c => this.isCase(c, coord)); + return list.find(c => this.isCase(Misc.data(c), coord)); } - + async createCaseTmr(actor, label, tmr, sourceId = undefined) { - await actor.createEmbeddedDocuments('Item',[{ - name: label, type: 'casetmr', img: this.img(), _id: randomID(16), + const casetmrData = { + name: label, type: 'casetmr', img: this.img(), data: { coord: tmr.coord, specific: this.code(), sourceid: sourceId } - }]); + }; + await actor.createEmbeddedDocuments('Item', [casetmrData]); } - + async deleteCasesTmr(actor, draconique) { - let caseTmrs = actor.data.items.filter(it => this.isCase(it) && it.data.sourceid == draconique._id); - for (let casetmr of caseTmrs) { - await actor.deleteOwnedItem(casetmr._id); - } + let caseTmrs = actor.data.items.filter(it => this.isCaseForSource(it, draconique)); + await actor.deleteEmbeddedDocuments('Item', caseTmrs.map(it => it.id)); + } + + isCaseForSource(item, draconique) { + const itemData = Misc.data(item); + return Draconique.isCaseTMR(itemData) && itemData.data.specific == this.code() && itemData.data.sourceid == draconique.id; } async onVisiteSupprimer(actor, tmr, onRemoveToken) { let existants = actor.data.items.filter(it => this.isCase(it, tmr.coord)); + await actor.deleteEmbeddedDocuments('Item', existants.map(it => it.id)); for (let casetmr of existants) { - await actor.deleteOwnedItem(casetmr._id); onRemoveToken(tmr, casetmr); } } diff --git a/module/tmr/fermeture-cites.js b/module/tmr/fermeture-cites.js index 8d695ae6..457d4a7b 100644 --- a/module/tmr/fermeture-cites.js +++ b/module/tmr/fermeture-cites.js @@ -32,7 +32,7 @@ export class FermetureCites extends Draconique { let existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); let ouvertes = TMRUtility.filterTMR(it => it.type == 'cite' && !existants.includes(it.coord)); for (let tmr of ouvertes) { - await this.createCaseTmr(actor, 'Fermeture: ' + tmr.label, tmr, souffle._id); + await this.createCaseTmr(actor, 'Fermeture: ' + tmr.label, tmr, souffle.id); } } } diff --git a/module/tmr/pelerinage.js b/module/tmr/pelerinage.js index ec9e4010..6a950478 100644 --- a/module/tmr/pelerinage.js +++ b/module/tmr/pelerinage.js @@ -14,7 +14,7 @@ export class Pelerinage extends Draconique { async onActorCreateOwned(actor, queue) { let tmr = TMRUtility.getTMRAleatoire(); - await this.createCaseTmr(actor, 'Pèlerinage: ' + tmr.label, tmr, queue._id); + await this.createCaseTmr(actor, 'Pèlerinage: ' + tmr.label, tmr, queue.id); } @@ -32,7 +32,7 @@ export class Pelerinage extends Draconique { } async onActorDeleteCaseTmr(actor, casetmr) { - await actor.deleteOwnedItem(casetmr.data.sourceid); + await actor.deleteEmbeddedDocuments('Item', [casetmr.data.sourceid]); } } diff --git a/module/tmr/periple.js b/module/tmr/periple.js index feba1a2b..30434196 100644 --- a/module/tmr/periple.js +++ b/module/tmr/periple.js @@ -16,7 +16,7 @@ export class Periple extends Draconique { let terrain = new Roll("1d2").evaluate().total == 1 ? 'sanctuaire' : 'necropole'; let tmrs = TMRUtility.getListTMR(terrain); for (let tmr of tmrs) { - await this.createCaseTmr(actor, 'Périple: ' + tmr.label, tmr, souffle._id); + await this.createCaseTmr(actor, 'Périple: ' + tmr.label, tmr, souffle.id); } } diff --git a/module/tmr/pont-impraticable.js b/module/tmr/pont-impraticable.js index 8470a939..1bde95fd 100644 --- a/module/tmr/pont-impraticable.js +++ b/module/tmr/pont-impraticable.js @@ -14,7 +14,7 @@ export class PontImpraticable extends Draconique { async onActorCreateOwned(actor, souffle) { const ponts = TMRUtility.getListTMR('pont'); for (let tmr of ponts) { - await this.createCaseTmr(actor, 'Pont impraticable: ' + tmr.label, tmr, souffle._id); + await this.createCaseTmr(actor, 'Pont impraticable: ' + tmr.label, tmr, souffle.id); } } diff --git a/module/tmr/present-cites.js b/module/tmr/present-cites.js index c6967b94..d3c992a7 100644 --- a/module/tmr/present-cites.js +++ b/module/tmr/present-cites.js @@ -40,7 +40,7 @@ export class PresentCites extends Draconique { else { let cites = TMRUtility.filterTMR(it => it.type == 'cite'); for (let tmr of cites) { - await this.createCaseTmr(actor, 'Présent: ' + tmr.label, tmr, tete._id); + await this.createCaseTmr(actor, 'Présent: ' + tmr.label, tmr, tete.id); } } } @@ -60,6 +60,6 @@ export class PresentCites extends Draconique { } async ouvrirLePresent(actor, casetmr) { - await actor.deleteOwnedItem(casetmr._id); + await actor.deleteEmbeddedDocuments('Item', [casetmr.id]); } } diff --git a/module/tmr/quete-eaux.js b/module/tmr/quete-eaux.js index df9866cd..95f92e9c 100644 --- a/module/tmr/quete-eaux.js +++ b/module/tmr/quete-eaux.js @@ -11,7 +11,7 @@ export class QueteEaux extends Draconique { match(item) { return Draconique.isTeteDragon(item) && Grammar.toLowerCaseNoAccent(item.name).includes("quete des eaux"); } manualMessage() { return "Vous devrez re-configurer votre Quête des Eaux une fois un lac ou marais vaincu" } async onActorCreateOwned(actor, tete) { - await this.createCaseTmr(actor, "Quête des eaux à déterminer", { coord: 'A0' }, tete._id); + await this.createCaseTmr(actor, "Quête des eaux à déterminer", { coord: 'A0' }, tete.id); } code() { return 'maitrisee' } diff --git a/module/tmr/reserve-extensible.js b/module/tmr/reserve-extensible.js index cc51420e..6ee92d7f 100644 --- a/module/tmr/reserve-extensible.js +++ b/module/tmr/reserve-extensible.js @@ -13,7 +13,7 @@ export class ReserveExtensible extends Draconique { async onActorCreateOwned(actor, tete) { const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); const tmr = TMRUtility.getTMRAleatoire(it => !(it.type == 'fleuve' || existants.includes(it.coord))); - await this.createCaseTmr(actor, "Nouvelle Réserve extensible", tmr, tete._id); + await this.createCaseTmr(actor, "Nouvelle Réserve extensible", tmr, tete.id); } code() { return 'reserve_extensible' } diff --git a/module/tmr/terre-attache.js b/module/tmr/terre-attache.js index 2a6fb686..c5c85ef9 100644 --- a/module/tmr/terre-attache.js +++ b/module/tmr/terre-attache.js @@ -12,7 +12,7 @@ export class TerreAttache extends Draconique { manualMessage() { return "Vous pouvez re-configurer votre Terre d'Attache" } async onActorCreateOwned(actor, tete) { - await this.createCaseTmr(actor, "Terre d'attache à déterminer", { coord: 'A0' }, tete._id); + await this.createCaseTmr(actor, "Terre d'attache à déterminer", { coord: 'A0' }, tete.id); } code() { return 'attache' } diff --git a/module/tmr/trou-noir.js b/module/tmr/trou-noir.js index 10b86012..95a09e04 100644 --- a/module/tmr/trou-noir.js +++ b/module/tmr/trou-noir.js @@ -14,7 +14,7 @@ export class TrouNoir extends Draconique { async onActorCreateOwned(actor, souffle) { const existants = actor.data.items.filter(it => this.isCase(it)).map(it => it.data.coord); const tmr = TMRUtility.getTMRAleatoire(it => !(TMRUtility.isCaseHumide(it) || existants.includes(it.coord))); - await this.createCaseTmr(actor, 'Trou noir: ' + tmr.label, tmr, souffle._id); + await this.createCaseTmr(actor, 'Trou noir: ' + tmr.label, tmr, souffle.id); } code() { return 'trounoir' } diff --git a/module/tmr/urgence-draconique.js b/module/tmr/urgence-draconique.js index 1b43d1f3..9a6bad38 100644 --- a/module/tmr/urgence-draconique.js +++ b/module/tmr/urgence-draconique.js @@ -23,20 +23,20 @@ export class UrgenceDraconique extends Draconique { whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), content: `En l'absence de sorts en réserve, l'urgence draconique de ${actor.name} se transforme en ${ideeFixe.name}` }); - await actor.createEmbeddedDocuments('Item',[ideeFixe]); - await actor.deleteOwnedItem(queue._id); + await actor.createEmbeddedDocuments('Item', [ideeFixe]); + await actor.deleteEmbeddedDocuments('Item', [queue.id]); return; } else { const demiReve = actor.getDemiReve(); coordSortsReserve.sort(Misc.ascending(t => TMRUtility.distanceTMR(t, demiReve))); const tmr = TMRUtility.getTMR(coordSortsReserve[0]); - await this.createCaseTmr(actor, 'Urgence draconique: ' + tmr.label, tmr, queue._id); + await this.createCaseTmr(actor, 'Urgence draconique: ' + tmr.label, tmr, queue.id); } } async onActorDeleteCaseTmr(actor, casetmr) { - await actor.deleteOwnedItem(casetmr.data.sourceid); + await actor.deleteEmbeddedDocuments('Item', [casetmr.data.sourceid]); } code() { return 'urgence' } diff --git a/system.json b/system.json index 87a6205c..19c1932e 100644 --- a/system.json +++ b/system.json @@ -31,7 +31,7 @@ "name": "Fab" } ], - "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], + "esmodules": [ "module/rdd-main.js"], "styles": ["styles/simple.css"], "media": [ { diff --git a/templates/item-casetmr-sheet.html b/templates/item-casetmr-sheet.html index 96e33db7..6e17106d 100644 --- a/templates/item-casetmr-sheet.html +++ b/templates/item-casetmr-sheet.html @@ -15,7 +15,7 @@
diff --git a/templates/item-jeu-sheet.html b/templates/item-jeu-sheet.html index 68d7fe97..130bd8cf 100644 --- a/templates/item-jeu-sheet.html +++ b/templates/item-jeu-sheet.html @@ -11,7 +11,7 @@
- {{#select item.data.competence}} + {{#select data.competence}} {{#each competences as |competence key|}} {{/each}} @@ -29,7 +29,7 @@
@@ -49,7 +49,7 @@
@@ -58,7 +58,7 @@ {{#if isGM}} - {{#select item.data.default_carac}} + {{#select data.default_carac}} {{>"systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html"}} {{/select}} @@ -19,7 +19,7 @@