From b034a925411472bee8ef4cefa72e496d002f635b Mon Sep 17 00:00:00 2001 From: sladecraven Date: Mon, 3 Jan 2022 00:09:27 +0100 Subject: [PATCH] Fix auto-compute --- module/actor/actor-sheet.js | 46 ++++++++++++++++++++---------------- module/actor/actor.js | 33 ++++++++++++++++---------- module/system/bol-utility.js | 25 -------------------- system.json | 3 ++- template.json | 2 ++ 5 files changed, 50 insertions(+), 59 deletions(-) diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 384bc5c..d4e98e4 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -108,27 +108,32 @@ export class BoLActorSheet extends ActorSheet { /** @override */ getData(options) { const data = super.getData(options); - const actorData = data.data; - data.config = game.bol.config; - data.data = actorData.data; - data.details = this.actor.details; - data.attributes = this.actor.attributes; - data.aptitudes = this.actor.aptitudes; - data.resources = this.actor.resources; - data.equipment = this.actor.equipment; - data.weapons = this.actor.weapons; - data.protections = this.actor.protections; - data.containers = this.actor.containers; - data.treasure = this.actor.treasure; - data.vehicles = this.actor.vehicles; - data.ammos = this.actor.ammos; - data.misc = this.actor.misc; - data.combat = this.actor.buildCombat(); - data.features = this.actor.buildFeatures(); - data.isGM = game.user.isGM; + const actorData = duplicate(data.data); + let formData = duplicate(data) + formData.config = game.bol.config; + formData.data = actorData.data; + formData.details = this.actor.details; + formData.attributes = this.actor.attributes; + formData.aptitudes = this.actor.aptitudes; + formData.resources = this.actor.resources; + formData.equipment = this.actor.equipment; + formData.weapons = this.actor.weapons; + formData.protections = this.actor.protections; + formData.containers = this.actor.containers; + formData.treasure = this.actor.treasure; + formData.vehicles = this.actor.vehicles; + formData.ammos = this.actor.ammos; + formData.misc = this.actor.misc; + 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.isGM= game.user.isGM - console.log("ACTORDATA", data); - return data; + console.log("ACTORDATA", formData); + return formData; } /* -------------------------------------------- */ @@ -159,7 +164,6 @@ export class BoLActorSheet extends ActorSheet { return this.actor.createEmbeddedDocuments("Item", [itemData]); } - _onToggleEquip(event) { event.preventDefault(); const li = $(event.currentTarget).closest(".item"); diff --git a/module/actor/actor.js b/module/actor/actor.js index c3d98e5..1eeda1d 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -6,32 +6,41 @@ export class BoLActor extends Actor { /** @override */ prepareData() { - super.prepareData(); const actorData = this.data; // console.log(actorData); // const data = actorData.data; // const flags = actorData.flags; // Make separate methods for each Actor type (character, npc, etc.) to keep things organized. if (actorData.type === 'character') { - this._prepareCharacterData(actorData); + //this._prepareCharacterData(actorData); } + super.prepareData(); } - /** - * Prepare Character type specific data - */ - _prepareCharacterData(actorData) { - let newVitality = 10 + this.data.data.attributes.vigor.value; - if ( newVitality != this.data.data.resources.hp.max) { - this.data.data.resources.hp.max = newVitality; - this.update( { 'data.resources.hp.max': newVitality}); + /* -------------------------------------------- */ + //_onUpdate(changed, options, user) { + // + //} + + /* -------------------------------------------- */ + updateResourcesData( ) { + let newVitality = 10 + this.data.data.attributes.vigor.value + this.data.data.resources.hp.bonus + if ( this.data.data.resources.hp.max != newVitality) { + this.update( {'data.resources.hp.max': newVitality} ); + } + let newPower = 10 + this.data.data.attributes.mind.value + this.data.data.resources.power.bonus + if ( this.data.data.resources.power.max != newPower) { + this.update( {'data.resources.power.max': newPower} ); } } /* -------------------------------------------- */ - _onUpdate() { - this.manageHealthState() + prepareDerivedData() { + super.prepareDerivedData() + this.updateResourcesData() + this.manageHealthState(); } + /* -------------------------------------------- */ get itemData(){ return Array.from(this.data.items.values()).map(i => i.data); diff --git a/module/system/bol-utility.js b/module/system/bol-utility.js index 1dcfe97..0a1a82e 100644 --- a/module/system/bol-utility.js +++ b/module/system/bol-utility.js @@ -393,31 +393,6 @@ export class BoLUtility { let formula = nbDice + "d" + res[2] + postForm + ((res[modIndex]) ? res[modIndex] : ""); return formula; } - /* -------------------------------------------- */ - static async showDiceSoNice(roll, rollMode) { - if (game.modules.get("dice-so-nice")?.active) { - if (game.dice3d) { - let whisper = null; - let blind = false; - rollMode = rollMode ?? game.settings.get("core", "rollMode"); - switch (rollMode) { - case "blindroll": //GM only - blind = true; - case "gmroll": //GM + rolling player - whisper = BoLUtility.getUsers(user => user.isGM); - break; - case "roll": //everybody - whisper = BoLUtility.getUsers(user => user.active); - break; - case "selfroll": - whisper = [game.user.id]; - break; - } - await game.dice3d.showForRoll(roll, game.user, true, whisper, blind); - } - } - } - /* -------------------------------------------- */ static async confirmDelete(actorSheet, li) { let itemId = li.data("item-id"); diff --git a/system.json b/system.json index 611ad13..6e551a4 100644 --- a/system.json +++ b/system.json @@ -7,7 +7,8 @@ "url": "https://github.com/ZigmundKreud/bol", "license": "LICENSE.txt", "flags": {}, - "version": "0.8.9.1", + "version": "0.8.9.2", + "templateVersion": 10, "minimumCoreVersion": "0.8.6", "compatibleCoreVersion": "9", "scripts": [], diff --git a/template.json b/template.json index 8d590c2..08af517 100644 --- a/template.json +++ b/template.json @@ -111,12 +111,14 @@ "faith": { "key" : "faith", "label" : "BOL.resources.faith", + "bonus": 0, "value": 0, "max": 0 }, "power": { "key" : "power", "label" : "BOL.resources.power", + "bonus": 0, "value": 0, "max": 0 } -- 2.35.3