From a3fb328b7de08f4b4c05b4baed649175c2d006a4 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 3 May 2022 09:01:10 +0200 Subject: [PATCH] v10 migration, ongoing WIP --- module/actor-entite-sheet.js | 2 +- module/actor-sheet.js | 15 ++++---- module/actor.js | 7 ++-- module/chat-utility.js | 27 +++++--------- module/item-arme.js | 7 ++-- module/item-competence.js | 12 +++---- module/item-sheet.js | 4 +-- module/rdd-utility.js | 35 +++++++++---------- templates/actor-creature-sheet.html | 6 ++-- templates/actor-entite-sheet.html | 6 ++-- templates/actor-sheet-competence-partial.html | 4 +-- 11 files changed, 60 insertions(+), 65 deletions(-) diff --git a/module/actor-entite-sheet.js b/module/actor-entite-sheet.js index a087ab88..920c4ac5 100644 --- a/module/actor-entite-sheet.js +++ b/module/actor-entite-sheet.js @@ -48,7 +48,7 @@ export class RdDActorEntiteSheet extends ActorSheet { limited: this.object.limited, options: this.options, owner: this.document.isOwner, - itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i.data))), + itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i))), }; formData.options.isGM = game.user.isGM; diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 011ed1ea..4e6842d5 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -53,7 +53,7 @@ export class RdDActorSheet extends ActorSheet { limited: this.object.limited, options: this.options, owner: this.document.isOwner, - itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i.data))), + itemsByType: Misc.classify(this.object.items.map(i => foundry.utils.deepClone(i))), }; console.log("ACTOR DATA:", formData) @@ -79,11 +79,12 @@ export class RdDActorSheet extends ActorSheet { }; formData.competences.forEach(item => { - item.visible = this.options.cherchercompetence + console.log('Comp', item) + item.isVisible = this.options.cherchercompetence ? RdDItemCompetence.nomContientTexte(item, this.options.cherchercompetence) : (!this.options.showCompNiveauBase || !RdDItemCompetence.isNiveauBase(item)); - RdDItemCompetence.levelUp(item, formData.data.compteurs.experience.value); - }); + RdDItemCompetence.levelUp(item, formData.data.compteurs.experience.value) + }) Object.values(formData.data.carac).forEach(c => { RdDCarac.levelUp(c); @@ -386,9 +387,9 @@ export class RdDActorSheet extends ActorSheet { this.actor.updateCarac(caracName, parseInt(event.target.value)); }); html.find('.carac-xp').change(async event => { - let caracName = event.currentTarget.name.replace(".xp", "").replace("data.carac.", ""); - //console.log("Value changed :", event, caracName); - this.actor.updateCaracXP(caracName, parseInt(event.target.value)); + let caracName = event.currentTarget.name.replace(".xp", "").replace("system.carac.", "") + //console.log("Value changed :", event, caracName) + this.actor.updateCaracXP(caracName, parseInt(event.target.value)) }); // On competence change html.find('.competence-value').change(async event => { diff --git a/module/actor.js b/module/actor.js index 08ac5f41..1927ffaf 100644 --- a/module/actor.js +++ b/module/actor.js @@ -845,6 +845,7 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async updateCarac(caracName, caracValue) { + console.log("Carac change", caracName) if (caracName == "force") { if (Number(caracValue) > this.getTaille() + 4) { ui.notifications.warn("Votre FORCE doit être au maximum de TAILLE+4"); @@ -951,11 +952,11 @@ export class RdDActor extends Actor { if (competence) { const update = { _id: competence.id } if (fieldName == "niveau") - update['data.niveau'] = compValue; + update['system.niveau'] = compValue; else if (fieldName == "dommages") - update['data.dommages'] = compValue; + update['system.dommages'] = compValue; else - update['data.carac_value'] = compValue; + update['system.carac_value'] = compValue; await this.updateEmbeddedDocuments('Item', [update]); // updates one EmbeddedEntity } } diff --git a/module/chat-utility.js b/module/chat-utility.js index 976e1b0c..d2062edf 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -32,6 +32,7 @@ export class ChatUtility { } } + /* -------------------------------------------- */ static onNotifyUser(data) { if (game.user.id == data.userId) { switch (data.level) { @@ -46,28 +47,15 @@ export class ChatUtility { static onRemoveMessages(data) { if (Misc.isUniqueConnectedGM()) { if (data.part) { - const toDelete = game.messages.filter(it => it.data.content.includes(data.part)); - toDelete.forEach(it => it.delete()); + const toDelete = game.messages.filter(it => it.content.includes(data.part)) + toDelete.forEach(it => it.delete()) } if (data.messageId) { - game.messages.get(data.messageId)?.delete(); - } - } - } - - static onRemoveMessages(data) { - if (Misc.isUniqueConnectedGM()) { - if (data.part) { - const toDelete = game.messages.filter(it => it.data.content.includes(data.part)); - toDelete.forEach(it => it.delete()); - } - if (data.messageId) { - game.messages.get(data.messageId)?.delete(); + game.messages.get(data.messageId)?.delete() } } } /* -------------------------------------------- */ - static removeMessages(data) { if (Misc.isUniqueConnectedGM()) { ChatUtility.onRemoveMessages(data); @@ -90,7 +78,7 @@ export class ChatUtility { /* -------------------------------------------- */ static async createChatWithRollMode(name, chatOptions) { - return await ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions); + return await ChatUtility.createChatMessage(name, game.settings.get("core", "rollMode"), chatOptions) } /* -------------------------------------------- */ @@ -141,7 +129,7 @@ export class ChatUtility { /* -------------------------------------------- */ static getUsers(filter) { - return Misc.getUsers().filter(filter).map(user => user.data._id); + return Misc.getUsers().filter(filter).map(user => user.id) } /* -------------------------------------------- */ @@ -162,17 +150,20 @@ export class ChatUtility { } } + /* -------------------------------------------- */ static async setMessageData(chatMessage, key, data) { if (data) { await chatMessage.setFlag(SYSTEM_RDD, key, JSON.stringify(data)); } } + /* -------------------------------------------- */ static getMessageData(chatMessage, key) { const json = chatMessage.getFlag(SYSTEM_RDD, key); return json ? JSON.parse(json) : undefined; } + /* -------------------------------------------- */ static getChatMessage(event) { const chatMessageId = $(event.currentTarget).closest('.chat-message').attr('data-message-id'); return game.messages.get(chatMessageId); diff --git a/module/item-arme.js b/module/item-arme.js index 5b78597f..8e1e4806 100644 --- a/module/item-arme.js +++ b/module/item-arme.js @@ -20,8 +20,9 @@ const nomCategorieParade = { export class RdDItemArme extends Item { static isArme(itemData) { - itemData = Misc.data(itemData); - return (itemData.type == 'competencecreature' && itemData.data.iscombat) || itemData.type == 'arme'; + console.log("ARM", itemData) + //itemData = Misc.data(itemData) + return (itemData.type == 'competencecreature' && itemData.system.iscombat) || itemData.type == 'arme'; } /* -------------------------------------------- */ @@ -35,12 +36,14 @@ export class RdDItemArme extends Item { return RdDItemArme.mainsNues(); } + /* -------------------------------------------- */ static computeNiveauArmes(armes, competences) { for (const arme of armes) { arme.system.niveau = RdDItemArme.niveauCompetenceArme(arme, competences) } } + /* -------------------------------------------- */ static niveauCompetenceArme(arme, competences) { const compArme = competences.find(it => it.name == arme.system.competence); return compArme?.system.niveau ?? -8; diff --git a/module/item-competence.js b/module/item-competence.js index 2c24e3cb..02ae799c 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -133,12 +133,12 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static computeXP(competence) { - const itemData = Misc.data(competence); - const factor = itemData.name.includes('Thanatos') ? 2 : 1; // Thanatos compte double ! - const xpNiveau = RdDItemCompetence.computeDeltaXP(itemData.data.base, itemData.data.niveau ?? itemData.data.base); - const xp = itemData.data.xp ?? 0; - const xpSort = itemData.data.xp_sort ?? 0; - return factor * (xpNiveau + xp) + xpSort; + console.log("Competence", competence) + const factor = competence.name.includes('Thanatos') ? 2 : 1 // Thanatos compte double ! + const xpNiveau = RdDItemCompetence.computeDeltaXP(competence.system.base, competence.system.niveau ?? competence.system.base) + const xp = competence.system.xp ?? 0 + const xpSort = competence.system.xp_sort ?? 0 + return factor * (xpNiveau + xp) + xpSort } /* -------------------------------------------- */ diff --git a/module/item-sheet.js b/module/item-sheet.js index c283d19f..eaabf15e 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -227,8 +227,8 @@ export class RdDItemSheet extends ItemSheet { /* -------------------------------------------- */ get template() { - let type = this.object.data.type; - return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html`; + let type = this.object.type + return `systems/foundryvtt-reve-de-dragon/templates/item-${type}-sheet.html` } /* -------------------------------------------- */ diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 5ee377a4..1831720c 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -239,7 +239,7 @@ export class RdDUtility { if (b.name.includes("Extérieur")) return 1; return a.name.localeCompare(b.name); } - if (a.data.categorie.startsWith("melee") && b.data.categorie.startsWith("melee")) { + if (a.system.categorie.startsWith("melee") && b.system.categorie.startsWith("melee")) { if (a.name.includes("Corps")) return -1; if (b.name.includes("Corps")) return 1; if (a.name.includes("Dague")) return -1; @@ -414,38 +414,37 @@ export class RdDUtility { /* -------------------------------------------- */ static buildArbreDeConteneurs(conteneurs, objets) { - let objetVersConteneur = {}; + let objetVersConteneur = {} // Attribution des objets aux conteneurs for (let conteneur of conteneurs) { - conteneur.subItems = []; - for (let id of conteneur.data.contenu ?? []) { - let objet = objets.find(objet => (id == objet._id)); + conteneur.subItems = [] + for (let id of conteneur.system.contenu ?? []) { + let objet = objets.find(objet => (id == objet._id)) if (objet) { objet.estContenu = true; // Permet de filtrer ce qui est porté dans le template - objetVersConteneur[id] = conteneur._id; - conteneur.subItems.push(objet); + objetVersConteneur[id] = conteneur._id + conteneur.subItems.push(objet) } } } for (let conteneur of conteneurs) { - conteneur.data.encTotal = RdDUtility.calculEncContenu(conteneur, objets); + conteneur.system.encTotal = RdDUtility.calculEncContenu(conteneur, objets) } - return objetVersConteneur; + return objetVersConteneur } /* -------------------------------------------- */ static calculEncContenu(conteneur, objets) { - const itemData = Misc.data(conteneur); - const contenuDatas = (itemData.data.contenu ?? []).filter(id => id != undefined) - .map(id => Misc.data(objets.find(it => (id == it._id)))) - .filter(it => it); - let enc = Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1); - for (let itemData of contenuDatas) { - if (itemData.type == 'conteneur') { - enc += RdDUtility.calculEncContenu(itemData, objets); + const contenuDatas = (conteneur.system.contenu ?? []).filter(id => id != undefined) + .map(id => objets.find(it => (id == it._id)) ) + .filter(it => it) + let enc = Number(conteneur.system.encombrement ?? 0) * Number(conteneur.system.quantite ?? 1) + for (let subContenu of contenuDatas) { + if (subContenu.type == 'conteneur') { + enc += RdDUtility.calculEncContenu(subContenu, objets) } else { - enc += Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1); + enc += Number(subContenu.system.encombrement ?? 0) * Number(subContenu.system.quantite ?? 1) } } return enc; diff --git a/templates/actor-creature-sheet.html b/templates/actor-creature-sheet.html index 0556d602..ae2249fc 100644 --- a/templates/actor-creature-sheet.html +++ b/templates/actor-creature-sheet.html @@ -103,11 +103,11 @@ {{comp.name}} + value="{{comp.system.carac_value}}" data-dtype="number" /> + value="{{numberFormat comp.system.niveau decimals=0 sign=true}}" data-dtype="number" /> + value="{{numberFormat comp.system.dommages decimals=0 sign=true}}" data-dtype="number" />
diff --git a/templates/actor-entite-sheet.html b/templates/actor-entite-sheet.html index fb0dbcd3..04aa7108 100644 --- a/templates/actor-entite-sheet.html +++ b/templates/actor-entite-sheet.html @@ -99,11 +99,11 @@ {{comp.name}} + value="{{comp.system.carac_value}}" data-dtype="number" /> + value="{{numberFormat comp.system.niveau decimals=0 sign=true}}" data-dtype="number" /> + value="{{numberFormat comp.system.dommages decimals=0 sign=true}}" data-dtype="number" />
diff --git a/templates/actor-sheet-competence-partial.html b/templates/actor-sheet-competence-partial.html index e5a66c1d..4cd32545 100644 --- a/templates/actor-sheet-competence-partial.html +++ b/templates/actor-sheet-competence-partial.html @@ -1,4 +1,4 @@ -{{#if visible}} +{{#if isVisible}}
  • @@ -13,7 +13,7 @@ {{/if}}