diff --git a/css/bol.css b/css/bol.css index f2be19b..8c9ea6f 100644 --- a/css/bol.css +++ b/css/bol.css @@ -945,4 +945,40 @@ body.system-bol img#logo { } .dialog-button { max-height: 2rem; -} \ No newline at end of file +} +.xp-next { + color: darkgrey; + font-size: 1.0rem; + border: 1px solid #4b4a44; + box-shadow: 1px 1px 1px gray; + border-radius: 100px; + width: 1.25rem; + height: 1.25rem; +} + +/** Tooltip section */ +.tooltip-container { + position: relative; + display: inline-block; +} +.tooltip-container .tooltiptext { + text-align: center; + /* Position the tooltip text */ + position: absolute; + z-index: 1; + /* Fade in tooltip */ + visibility: hidden; + opacity: 0; + transition: opacity 0.3s; + background-color: #f2f3a2a0; + padding: 4px; + width: 4rem; + border-radius: 25%; + border-width: 1px; + transform: translate(-40%, -60%); +} +/* Show the tooltip text when you mouse over the tooltip container */ +.tooltip-container:hover .tooltiptext { + visibility: visible; + opacity: 1; +} diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index e9d3597..c1d2561 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -2,7 +2,7 @@ * Extend the basic ActorSheet with some very simple modifications * @extends {ActorSheet} */ -import {BoLRoll} from "../controllers/bol-rolls.js"; +import { BoLRoll } from "../controllers/bol-rolls.js"; import { BoLUtility } from "../system/bol-utility.js"; export class BoLActorSheet extends ActorSheet { @@ -42,23 +42,23 @@ export class BoLActorSheet extends ActorSheet { html.find('.create_item').click(ev => { this.actor.createEmbeddedDocuments('Item', [{ name: "Nouvel Equipement", type: "item" }], { renderSheet: true }); }); - + html.find(".toggle-fight-option").click((ev) => { const li = $(ev.currentTarget).parents(".item") - this.actor.toggleFightOption( li.data("itemId") ) + this.actor.toggleFightOption(li.data("itemId")) }) - + html.find(".inc-dec-btns-alchemy").click((ev) => { const li = $(ev.currentTarget).parents(".item"); - this.actor.spendAlchemyPoint( li.data("itemId"), 1) + this.actor.spendAlchemyPoint(li.data("itemId"), 1) }) // Incr./Decr. career ranks html.find(".inc-dec-btns").click((ev) => { const li = $(ev.currentTarget).parents(".item"); - if(li){ + if (li) { const item = this.actor.items.get(li.data("itemId")); - if(item){ + if (item) { const dataset = ev.currentTarget.dataset; const operator = dataset.operator; const target = dataset.target; @@ -66,18 +66,18 @@ export class BoLActorSheet extends ActorSheet { const min = parseInt(dataset.min) const max = parseInt(dataset.max) || 10000 const itemData = item.data; - let value = eval("itemData."+target) + let value = eval("itemData." + target) value = value || 0 console.log("IncDec", item, target, value, operator, min, max) - if(operator === "minus"){ - if(value >= min + incr) value -= incr; + if (operator === "minus") { + if (value >= min + incr) value -= incr; else value = min; } - if(operator === "plus") { - if(value <= max - incr) value += incr; + if (operator === "plus") { + if (value <= max - incr) value += incr; else value = max; } - let update = { [`${target}`]: value}; + let update = { [`${target}`]: value }; item.update(update); } } @@ -94,7 +94,7 @@ export class BoLActorSheet extends ActorSheet { this.actor.deleteEmbeddedDocuments("Item", [li.data("itemId")]) li.slideUp(200, () => this.render(false)); }, - no: () => {}, + no: () => { }, defaultYes: false, }); }); @@ -133,15 +133,15 @@ export class BoLActorSheet extends ActorSheet { formData.combat = this.actor.buildCombat() formData.features = this.actor.buildFeatures() formData.isGM = game.user.isGM - formData.options= this.options - formData.owner= this.document.isOwner - formData.editScore= this.options.editScore + formData.options = this.options + formData.owner = this.document.isOwner + formData.editScore = this.options.editScore formData.useBougette = BoLUtility.getUseBougette() formData.isSorcerer = this.actor.isSorcerer() formData.isAlchemist = this.actor.isAlchemist() formData.isPriest = this.actor.isPriest() - + formData.isGM = game.user.isGM console.log("ACTORDATA", formData) @@ -190,34 +190,44 @@ export class BoLActorSheet extends ActorSheet { */ _onRoll(event) { event.preventDefault(); - const element = event.currentTarget; - const dataset = element.dataset; - const actorData = this.getData(); - const rollType = dataset.rollType; - const li = $(event.currentTarget).closest(".item"); - switch(rollType) { - case "attribute" : + const element = event.currentTarget + const dataset = element.dataset + const actorData = this.getData() + const rollType = dataset.rollType + const li = $(event.currentTarget).closest(".item") + switch (rollType) { + case "attribute": BoLRoll.attributeCheck(this.actor, actorData, dataset, event); break; - case "aptitude" : + case "aptitude": BoLRoll.aptitudeCheck(this.actor, actorData, dataset, event); break; - case "weapon": + case "weapon": BoLRoll.weaponCheck(this.actor, actorData, dataset, event); break; - case "spell": + case "spell": BoLRoll.spellCheck(this.actor, actorData, dataset, event); break; - case "alchemy": + case "alchemy": BoLRoll.alchemyCheck(this.actor, actorData, dataset, event); break; - case "protection": + case "protection": this.actor.rollProtection(li.data("item-id")) break; - case "damage": + case "damage": this.actor.rollWeaponDamage(li.data("item-id")) break; - default : break; + case "aptitudexp": + this.actor.incAptitudeXP(dataset.key) + break; + case "attributexp": + this.actor.incAttributeXP(dataset.key) + break; + case "careerxp": + this.actor.incCareerXP( li.data("item-id")) + break; + + default: break; } } diff --git a/module/actor/actor.js b/module/actor/actor.js index af32d91..bf55938 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -98,7 +98,55 @@ export class BoLActor extends Actor { } return undefined } - + + /* -------------------------------------------- */ + incAttributeXP( key) { + let attr = duplicate(this.data.data.attributes[key]) + if (attr) { + let nextXP = (attr.value == -1) ? 2 : attr.value + (attr.value+1) + let xp = duplicate(this.data.data.xp) + if ( xp.total - xp.spent >= nextXP) { + attr.value += 1 + xp.spent += nextXP + this.update( { [`data.attributes.${key}`]: attr, [`data.xp`]: xp } ) + } else { + ui.notifications.warn("Pas assez de points d'expérience !") + } + } + } + + /* -------------------------------------------- */ + incAptitudeXP( key) { + let apt = duplicate(this.data.data.aptitudes[key]) + if (apt) { + let nextXP = (apt.value == -1) ? 1 : apt.value + 2 + let xp = duplicate(this.data.data.xp) + if ( xp.total - xp.spent >= nextXP) { + apt.value += 1 + xp.spent += nextXP + this.update( { [`data.aptitudes.${key}`]: apt, [`data.xp`]: xp } ) + } else { + ui.notifications.warn("Pas assez de points d'expérience !") + } + } + } + /* -------------------------------------------- */ + incCareerXP( itemId) { + let career = this.data.items.get( itemId ) + if (career) { + career = duplicate(career) + let nextXP = career.data.rank + 1 + let xp = duplicate(this.data.data.xp) + if ( xp.total - xp.spent >= nextXP) { + xp.spent += nextXP + this.update( { [`data.xp`]: xp } ) + this.updateEmbeddedDocuments( 'Item', [ { _id: career._id, 'data.rank': career.data.rank + 1 } ]) + } else { + ui.notifications.warn("Pas assez de points d'expérience !") + } + } + } + /* -------------------------------------------- */ async toggleFightOption( itemId) { let fightOption = this.data.items.get(itemId) diff --git a/module/system/helpers.js b/module/system/helpers.js index 7a8f485..cc56ba4 100644 --- a/module/system/helpers.js +++ b/module/system/helpers.js @@ -39,53 +39,49 @@ export const registerHandlebarsHelpers = function () { Handlebars.registerHelper('gt', function (val1, val2) { return val1 > val2; - }); + }) Handlebars.registerHelper('lt', function (val1, val2) { return val1 < val2; - }); + }) Handlebars.registerHelper('gte', function (val1, val2) { return val1 >= val2; - }); + }) Handlebars.registerHelper('lte', function (val1, val2) { return val1 <= val2; - }); + }) Handlebars.registerHelper('and', function (val1, val2) { return val1 && val2; - }); - + }) Handlebars.registerHelper('or', function (val1, val2) { return val1 || val2; - }); + }) Handlebars.registerHelper('or3', function (val1, val2, val3) { return val1 || val2 || val3; - }); + }) Handlebars.registerHelper('for', function(from, to, incr, block) { var accum = ''; for(var i = from; i < to; i += incr) accum += block.fn(i); return accum; - }); + }) Handlebars.registerHelper('not', function (cond) { return !cond; - }); - + }) Handlebars.registerHelper('count', function (list) { return list.length; - }); - + }) Handlebars.registerHelper('isEnabled', function (configKey) { return game.settings.get("bol", configKey); - }); - + }) Handlebars.registerHelper('split', function (str, separator, keep) { return str.split(separator)[keep]; - }); + }) // If you need to add Handlebars helpers, here are a few useful examples: Handlebars.registerHelper('concat', function () { @@ -96,32 +92,30 @@ export const registerHandlebarsHelpers = function () { } } return outStr; - }); + }) Handlebars.registerHelper('add', function (a, b) { return parseInt(a) + parseInt(b); }); - + Handlebars.registerHelper('mul', function (a, b) { + return parseInt(a) * parseInt(b); + }) Handlebars.registerHelper('sub', function (a, b) { return parseInt(a) - parseInt(b); - }); - + }) Handlebars.registerHelper('valueAtIndex', function (arr, idx) { return arr[idx]; - }); - + }) Handlebars.registerHelper('includesKey', function (items, type, key) { // console.log(items); return items.filter(i => i.type === type).map(i => i.data.key).includes(key); - }); - + }) Handlebars.registerHelper('includes', function (array, val) { return array.includes(val); - }); - + }) Handlebars.registerHelper('eval', function (expr) { return eval(expr); - }); + }) diff --git a/system.json b/system.json index f80191b..6b9abe3 100644 --- a/system.json +++ b/system.json @@ -7,7 +7,7 @@ "url": "https://github.com/ZigmundKreud/bol", "license": "LICENSE.txt", "flags": {}, - "version": "1.2.1", + "version": "1.2.2", "templateVersion": 22, "minimumCoreVersion": "0.8.6", "compatibleCoreVersion": "9", diff --git a/templates/actor/parts/tabs/actor-features.hbs b/templates/actor/parts/tabs/actor-features.hbs index caab5f5..09a5c09 100644 --- a/templates/actor/parts/tabs/actor-features.hbs +++ b/templates/actor/parts/tabs/actor-features.hbs @@ -19,6 +19,18 @@   {{item.data.rank}}  +     + + + + + {{#if (eq data.rank 0)}} + 1 XP + {{else}} + {{add data.rank 1}} XP + {{/if}} + + {{/if}}
diff --git a/templates/actor/parts/tabs/actor-stats.hbs b/templates/actor/parts/tabs/actor-stats.hbs index 9021767..1b96903 100644 --- a/templates/actor/parts/tabs/actor-stats.hbs +++ b/templates/actor/parts/tabs/actor-stats.hbs @@ -3,9 +3,20 @@


- - - + + + + + + + + {{#if (eq value -1)}} + 2 XP + {{else}} + {{add value (add value 1)}} XP + {{/if}} + +
{{/each}}
@@ -15,9 +26,20 @@


- - - + + + + + + + + {{#if (eq value -1)}} + 1 XP + {{else}} + {{add value 2}} XP + {{/if}} + +
{{/each}}