From ffaa9e4c191cb3904276a41ad89ec1c8968cf832 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 27 Sep 2022 20:31:01 +0200 Subject: [PATCH] Fix #61 --- modules/pegasus-actor-sheet.js | 2 +- modules/pegasus-actor.js | 25 +++++++++++++++++++++++-- modules/pegasus-item-sheet.js | 9 ++++++--- modules/pegasus-utility.js | 8 ++++++++ templates/actor-sheet.html | 5 ++--- templates/item-perk-sheet.html | 1 + templates/item-power-sheet.html | 6 +++--- templates/partial-item-description.html | 2 +- 8 files changed, 45 insertions(+), 13 deletions(-) diff --git a/modules/pegasus-actor-sheet.js b/modules/pegasus-actor-sheet.js index b5e3cb4..125ad93 100644 --- a/modules/pegasus-actor-sheet.js +++ b/modules/pegasus-actor-sheet.js @@ -47,7 +47,7 @@ export class PegasusActorSheet extends ActorSheet { armors: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getArmors())), shields: this.actor.checkAndPrepareEquipments( duplicate(this.actor.getShields()) ), equipments: this.actor.checkAndPrepareEquipments(duplicate(this.actor.getEquipmentsOnly()) ), - perks: duplicate(this.actor.getPerks()), + perks: this.actor.getPerks(), abilities: duplicate(this.actor.getAbilities()), activePerks: duplicate(this.actor.getActivePerks()), powers: duplicate(this.actor.getPowers()), diff --git a/modules/pegasus-actor.js b/modules/pegasus-actor.js index 96c89c2..22309d3 100644 --- a/modules/pegasus-actor.js +++ b/modules/pegasus-actor.js @@ -120,6 +120,7 @@ export class PegasusActor extends Actor { this.computeNRGHealth(); this.system.encCapacity = this.getEncumbranceCapacity() this.buildContainerTree() + this.updatePPP() } if (this.type == 'vehicle') { this.computeVehicleStats(); @@ -149,8 +150,13 @@ export class PegasusActor extends Actor { return ab; } /* -------------------------------------------- */ - getPerks() { - let comp = this.items.filter(item => item.type == 'perk'); + getPerks() { + let comp = duplicate(this.items.filter(item => item.type == 'perk') || []) + for (let perk of comp) { + if (perk.system.features.range.flag) { + perk.rangeText = PegasusUtility.getRangeText( perk.system.features.range.value) + } + } return comp; } /* -------------------------------------------- */ @@ -356,6 +362,21 @@ export class PegasusActor extends Actor { await this.updateEmbeddedDocuments('Item', [update]) // Updates one EmbeddedEntity } } + + /* -------------------------------------------- */ + updatePPP() { + let ppp = 0 + for(let power of this.items) { + if (power.type == "power") { + ppp += Number(power.system.powerlevelcost) + } + } + console.log("PPP update", ppp) + if ( ppp != this.system.ppp.spentPPP) { + console.log("PPP update2", ppp) + this.update( { 'system.ppp.spentPPP': ppp} ) + } + } /* -------------------------------------------- */ async activatePower(itemId) { diff --git a/modules/pegasus-item-sheet.js b/modules/pegasus-item-sheet.js index f46900b..0935e38 100644 --- a/modules/pegasus-item-sheet.js +++ b/modules/pegasus-item-sheet.js @@ -62,14 +62,19 @@ export class PegasusItemSheet extends ItemSheet { optionsDiceList: PegasusUtility.getOptionsDiceList(), optionsStatusList: PegasusUtility.getOptionsStatusList(), data: itemData.system, + description: await TextEditor.enrichHTML(this.object.system.description, {async: true}), limited: this.object.limited, options: this.options, owner: this.document.isOwner, mr: (this.object.type == 'specialisation'), isGM: game.user.isGM } + if (this.object.type == "power") { + formData.effects = await TextEditor.enrichHTML(this.object.system.effects, {async: true}) + formData.purchasedeffects = await TextEditor.enrichHTML(this.object.system.purchasedeffects, {async: true}) + } - this.options.editable = true //!(this.object.isEmbedded) + this.options.editable = true console.log("ITEM DATA", formData, this); return formData; } @@ -425,7 +430,6 @@ export class PegasusItemSheet extends ItemSheet { let data = event.dataTransfer.getData('text/plain') let dataItem = JSON.parse( data) - console.log("DROP", event, dataItem ) let item = fromUuidSync(dataItem.uuid) if (item.pack) { item = await PegasusUtility.searchItem(item) @@ -434,7 +438,6 @@ export class PegasusItemSheet extends ItemSheet { ui.notifications.warn("Unable to find relevant item - Aborting drag&drop " + data.uuid) return } - console.log("DROP REULT", this.object.type, item.type) if (this.object.type == 'virtue' ) { if (item.type == 'effect') { diff --git a/modules/pegasus-utility.js b/modules/pegasus-utility.js index 2200f98..8e31c5e 100644 --- a/modules/pegasus-utility.js +++ b/modules/pegasus-utility.js @@ -8,6 +8,9 @@ import { PegasusRollDialog } from "./pegasus-roll-dialog.js"; const __level2Dice = ["d0", "d4", "d6", "d8", "d10", "d12"] const __name2DiceValue = { "0": 0, "d0": 0, "d4": 4, "d6": 6, "d8": 8, "d10": 10, "d12": 12 } const __dice2Level = { "d0": 0, "d4": 1, "d6": 2, "d8": 3, "d10": 4, "d12": 5 } +const __rangeKeyToText = { notapplicable: "N/A", touch: "Self Only", touchself: "Touch/Self", tz: "Threat Zone", close: "Close", medium: "Medium", + long: "Long", extreme: "Extreme", sight: "Lineof Sight", tz_close: "TZ/Close", close_medium: "Close/Medium", medium_long: "Medium/Long", + long_extreme: "Long/Extreme"} /* -------------------------------------------- */ export class PegasusUtility { @@ -98,6 +101,11 @@ export class PegasusUtility { options.push({ name: "Apply -10", condition: true, icon: '', callback: target => { PegasusCombat.decInitBy10(target.data('combatant-id'), -10); } }) } + /* -------------------------------------------- */ + static getRangeText( rangeKey) { + return __rangeKeyToText[rangeKey] || "N/A" + } + /* -------------------------------------------- */ static getDiceList() { return [{ key: "d4", level: 1, img: "systems/fvtt-pegasus-rpg/images/dice/d4.webp" }, { key: "d6", level: 2, img: "systems/fvtt-pegasus-rpg/images/dice/d6.webp" }, diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index d9fc646..2350b67 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -208,7 +208,7 @@ {{perk.system.level}} {{#if perk.system.features.range.flag}} - {{perk.system.features.range.value}} + {{perk.rangeText}} {{else}}  -  @@ -402,8 +402,7 @@ data-dtype="Number" />    Spent PPP + class="padd-right input-numeric-short" name="system.ppp.spentPPP" value="{{data.ppp.spentPPP}}" disabled data-dtype="Number" /> diff --git a/templates/item-perk-sheet.html b/templates/item-perk-sheet.html index 5090bb4..1f9e038 100644 --- a/templates/item-perk-sheet.html +++ b/templates/item-perk-sheet.html @@ -9,6 +9,7 @@ {{!-- Sheet Body --}}
+ {{> systems/fvtt-pegasus-rpg/templates/partial-item-description.html}}
diff --git a/templates/item-power-sheet.html b/templates/item-power-sheet.html index 1ee01af..016780a 100644 --- a/templates/item-power-sheet.html +++ b/templates/item-power-sheet.html @@ -14,15 +14,15 @@
- {{editor data.description target="system.description" button=true owner=owner editable=editable}} + {{editor description target="system.description" button=true owner=owner editable=editable}}
- {{editor data.effects target="system.effects" button=true owner=owner editable=editable}} + {{editor effects target="system.effects" button=true owner=owner editable=editable}}
- {{editor data.purchasedeffects target="system.purchasedeffects" button=true owner=owner + {{editor purchasedeffects target="system.purchasedeffects" button=true owner=owner editable=editable}}
diff --git a/templates/partial-item-description.html b/templates/partial-item-description.html index c97c210..26c9623 100644 --- a/templates/partial-item-description.html +++ b/templates/partial-item-description.html @@ -2,7 +2,7 @@
- {{editor data.description target="system.description" button=true owner=owner editable=editable}} + {{editor description target="system.description" button=true owner=owner editable=editable}}