From 4f236adbecad167efb43fe18adcad70975e4ef36 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Thu, 14 Jan 2021 15:29:47 +0100 Subject: [PATCH] XP fix avec tooltip --- module/actor-sheet.js | 12 ++--- module/actor.js | 22 ++++++++-- module/item-sheet.js | 3 +- module/rdd-utility.js | 2 +- styles/simple.css | 11 +++++ system.json | 2 +- templates/actor-sheet.html | 90 ++++++++++++++++++++++++++++++++++---- 7 files changed, 119 insertions(+), 23 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 0b85db12..293f4f47 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -46,8 +46,9 @@ export class RdDActorSheet extends ActorSheet { data.itemsByType.competence, item => item.data.categorie, item => { - item.data.isLevelUp = item.data.xp >= RdDItemCompetence.getCompetenceNextXp(item.data.niveau); // Flag de niveau à MAJ - this.actor.checkCompetenceXP(item.name); // Petite vérification experience + item.data.xpNext = RdDItemCompetence.getCompetenceNextXp(item.data.niveau); + item.data.isLevelUp = item.data.xp >= item.data.xpNext; // Flag de niveau à MAJ + //this.actor.checkCompetenceXP(item.name); // Petite vérification experience item.data.showCompetence = !data.data.showCompNiveauBase || (Number(item.data.niveau) != Number(RdDUtility.getLevelCategory(item.data.categorie))); // Ignorer les compétences 'troncs' à ce stade competenceXPTotal += RdDItemCompetence.isTronc(item.name) ? 0 : RdDItemCompetence.computeCompetenceXPCost(item); @@ -61,9 +62,10 @@ export class RdDActorSheet extends ActorSheet { for (let caracName in data.data.carac) { let currentCarac = data.data.carac[caracName]; if (!currentCarac.derivee) { - sum += parseInt(currentCarac.value); + sum += parseInt(currentCarac.value); } - currentCarac.isLevelUp = (currentCarac.xp >= RdDUtility.getCaracNextXp(currentCarac.value)); + currentCarac.xpNext = RdDUtility.getCaracNextXp(currentCarac.value); + currentCarac.isLevelUp = (currentCarac.xp >= currentCarac.xpNext); } data.data.caracSum = sum; @@ -512,7 +514,6 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ - /** @override */ setPosition(options = {}) { const position = super.setPosition(options); @@ -524,7 +525,6 @@ export class RdDActorSheet extends ActorSheet { /* -------------------------------------------- */ - /** @override */ _updateObject(event, formData) { // Update the Actor diff --git a/module/actor.js b/module/actor.js index 7dba22ec..f8ff181b 100644 --- a/module/actor.js +++ b/module/actor.js @@ -621,6 +621,7 @@ export class RdDActor extends Actor { async updateCompetenceXP(compName, compValue) { let comp = this.getCompetence(compName); if (comp) { + this.checkCompetenceXP(compName, compValue); const update = { _id: comp._id, 'data.xp': compValue }; const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity } else { @@ -1461,14 +1462,19 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async checkCompetenceXP(compName) { + async checkCompetenceXP(compName, newXP = undefined) { let competence = RdDItemCompetence.findCompetence(this.data.items, compName); - if (competence && competence.data.xp > 0) { + if ( competence && newXP && newXP == competence.data.xp ) { // Si édition, mais sans changement XP + return; + } + newXP = (newXP) ? newXP : competence.data.xp; + if (competence && newXP > 0) { let xpNeeded = RdDItemCompetence.getCompetenceNextXp(competence.data.niveau); - if (competence.data.xp >= xpNeeded) { + if (newXP >= xpNeeded) { let newCompetence = duplicate(competence); newCompetence.data.niveau += 1; - + newCompetence.data.xp = newXP; + let xpData = { alias: this.name, competence: newCompetence.name, @@ -2698,4 +2704,12 @@ export class RdDActor extends Actor { await this.createEmbeddedEntity('ActiveEffect', effet, options); this.applyActiveEffects(); } + + /* -------------------------------------------- */ + async updateEmbeddedEntity(embeddedName, data, options) { + if ( data && data['data.defaut_carac'] && data['data.xp'] ) { // C'est une compétence + this.checkCompetenceXP(data['name'], data['data.xp'] ); + } + return super.updateEmbeddedEntity(embeddedName, data, options); + } } diff --git a/module/item-sheet.js b/module/item-sheet.js index 837bfdb9..ee0cee01 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -121,10 +121,9 @@ export class RdDItemSheet extends ItemSheet { /** @override */ _updateObject(event, formData) { - // Données de bonus de cases ? formData = RdDItemSort.buildBonusCaseStringFromFormData( formData ); - + return this.object.update(formData); } } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 707a8dd0..be776021 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -362,7 +362,7 @@ export class RdDUtility { //console.log("OBJ:", objet); let str = Handlebars.partials['systems/foundryvtt-reve-de-dragon/templates/actor-inventaire-conteneur.html']({ item: objet }); if (objet.type == 'conteneur') { - console.log("ITEM DISPLAYED", objet ); + //console.log("ITEM DISPLAYED", objet ); if (this.getAfficheContenu(objet._id)) { str = str + "