From 41bb5ca91943a599f232be0f038da2f525a55e40 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 28 May 2021 00:55:22 +0200 Subject: [PATCH] Ajout bouton augmenter niveau --- module/actor-sheet.js | 10 ++++- module/actor.js | 40 +++++++++++++++++-- module/rdd-utility.js | 2 +- styles/simple.css | 10 ++--- templates/actor-sheet-competence-partial.html | 17 +++++--- templates/actor-sheet.html | 25 +++++++----- 6 files changed, 78 insertions(+), 26 deletions(-) diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 2d35c04c..1549246e 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -440,7 +440,15 @@ export class RdDActorSheet extends ActorSheet { RdDUtility.toggleAfficheContenu(myID); this.render(true); }); - + html.find('.carac-xp-augmenter').click((event) => { + let caracName = event.currentTarget.name.replace("augmenter.", ""); + this.actor.updateCaracXPAuto(caracName); + }); + html.find('.competence-xp-augmenter').click((event) => { + let compName = event.currentTarget.attributes.compname.value; + this.actor.updateCompetenceXPAuto(compName); + }); + if (this.options.editCaracComp) { // On carac change html.find('.carac-value').change((event) => { diff --git a/module/actor.js b/module/actor.js index cdd90a49..b5454eb1 100644 --- a/module/actor.js +++ b/module/actor.js @@ -793,6 +793,40 @@ export class RdDActor extends Actor { await this.update({ [`data.carac.${caracName}.xp`]: caracXP ?? 0 }); this.checkCaracXP(caracName); } + async updateCaracXPAuto(caracName) { + if (caracName == 'Taille') { + return; + } + let carac = RdDActor._findCaracByName(Misc.templateData(this).carac, caracName); + if (carac) { + carac = duplicate(carac); + let xp = Number(carac.xp); + let value = Number(carac.value); + while (xp >= RdDCarac.getCaracNextXp(value) && xp > 0) { + xp -= RdDCarac.getCaracNextXp(value); + value++; + } + carac.xp = xp; + carac.value = value; + await this.update({ [`data.carac.${caracName}`]: carac }); + } + } + async updateCompetenceXPAuto(compName) { + let competence = this.getCompetence(compName); + if (competence) { + let compData = Misc.data(competence); + let xp = Number(compData.data.xp); + let niveau = Number(compData.data.niveau); + while (xp >= RdDItemCompetence.getCompetenceNextXp(niveau) && xp > 0) { + xp -= RdDItemCompetence.getCompetenceNextXp(niveau); + niveau++; + } + competence.update({ + "data.xp": xp, + "data.niveau": niveau, + }); + } + } /* -------------------------------------------- */ async updateCreatureCompetence(compName, fieldName, compValue) { @@ -2002,7 +2036,7 @@ export class RdDActor extends Actor { value: niveauSuivant, xp: carac.xp } - if (display){ + if (display) { ChatUtility.createChatMessage(this.name, "default", { content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html`, checkXp) }); @@ -2812,7 +2846,7 @@ export class RdDActor extends Actor { await this._xpCarac(xpData); return xpData; } - + /* -------------------------------------------- */ async _xpCompetence(xpData) { if (xpData.competence) { @@ -2823,7 +2857,7 @@ export class RdDActor extends Actor { this.updateExperienceLog("XP", xpData.xp, "XP gagné en " + xpData.competence.name); } } - + /* -------------------------------------------- */ async _xpCarac(xpData) { if (xpData.xpCarac > 0) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 44f5708a..75cca74b 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -219,7 +219,7 @@ export class RdDUtility { Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord)); Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); Handlebars.registerHelper('typeTmr-name', coord => TMRUtility.typeTmrName(coord)); - Handlebars.registerHelper('equals', (a, b) => a == b); + Handlebars.registerHelper('sortCompetence', competences => competences.sort((a, b) => { if (a.name.startsWith("Survie") && b.name.startsWith("Survie")) { if (a.name.includes("Cité")) return -1; diff --git a/styles/simple.css b/styles/simple.css index 13fa3dc3..951bb8ba 100644 --- a/styles/simple.css +++ b/styles/simple.css @@ -471,15 +471,15 @@ table {border: 1px solid #7a7971;} .rdd-roll-part{ align-items: center; border-radius: 6px; padding: 3px; - background:linear-gradient(30deg, rgba(191, 149, 63, 0.3), rgba(252, 246, 186, 0.3), rgba(179, 135, 40, 0.3), rgba(251, 245, 183, 0.3), rgba(170, 119, 28, 0.3)); + background: linear-gradient(30deg, rgba(191, 149, 63, 0.3), rgba(252, 246, 186, 0.3), rgba(179, 135, 40, 0.3), rgba(251, 245, 183, 0.3), rgba(170, 119, 28, 0.3)); } .rdd-roll-sign{ border-radius: 6px; padding: 3px; - background:linear-gradient(30deg, rgba(61, 55, 93, 0.3), rgba(178, 179, 196, 0.3), rgba(59, 62, 63, 0.6), rgba(206, 204, 199, 0.3), rgba(61, 46, 49, 0.3)); + background: linear-gradient(30deg, rgba(61, 55, 93, 0.3), rgba(178, 179, 196, 0.3), rgba(59, 62, 63, 0.6), rgba(206, 204, 199, 0.3), rgba(61, 46, 49, 0.3)); } .rdd-roll-norm{ border-radius: 6px; padding: 3px; - background:linear-gradient(30deg, rgba(7, 76, 0, 0.3), rgba(66, 163, 65, 0.2), rgba(184, 226, 163, 0.1), rgba(66, 163, 65, 0.2), rgba(184, 226, 163, 0.3)); + background: linear-gradient(30deg, rgba(7, 76, 0, 0.3), rgba(66, 163, 65, 0.2), rgba(184, 226, 163, 0.1), rgba(66, 163, 65, 0.2), rgba(184, 226, 163, 0.3)); } .rdd-roll-notSign, .rdd-roll-echec{ border-radius: 6px; padding: 3px; @@ -714,7 +714,7 @@ ul, li { border-radius: 0.25rem; padding: 0.125rem; flex: 1 1 5rem; - background: rgba(195, 152, 22, 0.5) !important; + background: linear-gradient(30deg, rgba(191, 149, 63, 0.5), rgba(252, 246, 186, 0.5), rgba(179, 135, 40, 0.5), rgba(251, 245, 183, 0.5), rgba(170, 119, 28, 0.3)) !important; } .blessures-list ul { @@ -1473,7 +1473,7 @@ display: inline-flex; .tooltip .ttt-xp { width: 250px; - background: rgba(220,220,210,0.95); + background: rgba(220,220,210,0.95) !important; border-radius: 6px; font-size: 0.9rem; padding: 3px 0; diff --git a/templates/actor-sheet-competence-partial.html b/templates/actor-sheet-competence-partial.html index ec217cf9..65120cbf 100644 --- a/templates/actor-sheet-competence-partial.html +++ b/templates/actor-sheet-competence-partial.html @@ -4,6 +4,12 @@ {{name}} + {{#if data.isLevelUp}} + Vous pouvez dépenser {{data.xpNext}} points d'Experience pour augmenter de 1 votre compétence {{name}} + + + + {{/if}} @@ -20,12 +26,11 @@ value="{{numberFormat data.niveau_archetype decimals=0 sign=true}}" data-dtype="number" {{#unless @root.options.editCaracComp}}disabled{{/unless}} /> {{/if}} - {{#if data.isLevelUp}} - Vous pouvez dépenser {{data.xpNext}} points d'Experience pour augmenter de 1 votre compétence {{name}} - {{/if}} -
- - + {{#unless @root.options.hideControls}} +
+ +
+ {{/unless}} {{/if}} \ No newline at end of file diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 114020e1..66ac8dbf 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -121,7 +121,7 @@