diff --git a/CHANGELOG.txt b/CHANGELOG.txt index fbabb0f..e2ff1c9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,7 @@ +v.3.12 +- Fix cohort scale and quality calculation #161 +- Removed itemLogic calls #160 + v.3.11 - Fix the version number diff --git a/module/blades-helpers.js b/module/blades-helpers.js index ebadb0e..a2f5dc7 100644 --- a/module/blades-helpers.js +++ b/module/blades-helpers.js @@ -25,111 +25,6 @@ export class BladesHelpers { return dupe_list; } - /** - * Add item modification if logic exists. - * @param {Object} item_data - * @param {Document} entity - */ - static async callItemLogic(item_data, entity) { - - if ('logic' in item_data.data && item_data.data.logic !== '') { - let logic = JSON.parse(item_data.data.logic); - - // Should be an array to support multiple expressions - if (!Array.isArray(logic)) { - logic = [logic]; - } - - if (logic) { - let logic_update = { "_id": entity.id }; - logic.forEach(expression => { - - // Different logic behav. dep on operator. - switch (expression.operator) { - - // Add when creating. - case "addition": - foundry.utils.mergeObject( - logic_update, - {[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, prefix + expression.attribute)) + expression.value}, - {insertKeys: true} - ); - break; - - // Change name property. - case "attribute_change": - foundry.utils.mergeObject( - logic_update, - {[expression.attribute]: expression.value}, - {insertKeys: true} - ); - break; - - } - }); - await Actor.updateDocuments( logic_update ); - } - - } - - } - - /** - * Undo Item modifications when item is removed. - * @todo - * - Remove all items and then Add them back to - * sustain the logic mods - * @param {Object} item_data - * @param {Document} entity - */ - static async undoItemLogic(item_data, entity) { - - if ('logic' in item_data.data && item_data.data.logic !== '') { - let logic = JSON.parse(item_data.data.logic) - - // Should be an array to support multiple expressions - if (!Array.isArray(logic)) { - logic = [logic]; - } - - if (logic) { - let logic_update = { "_id": entity.id }; - var entity_data = entity.data; - - logic.forEach(expression => { - // Different logic behav. dep on operator. - switch (expression.operator) { - - // Subtract when removing. - case "addition": - foundry.utils.mergeObject( - logic_update, - {[expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, expression.attribute)) - expression.value}, - {insertKeys: true} - ); - break; - - // Change name back to default. - case "attribute_change": - // Get the array path to take data. - let default_expression_attribute_path = expression.attribute + '_default'; - let default_name = default_expression_attribute_path.split(".").reduce((o, i) => o[i], entity_data); - - foundry.utils.mergeObject( - logic_update, - {[expression.attribute]: default_name}, - {insertKeys: true} - ); - - break; - } - }); - await Actor.updateDocuments( logic_update ); - } - } - - } - /** * Get a nested dynamic attribute. * @param {Object} obj diff --git a/module/blades-item.js b/module/blades-item.js index e9ec920..979552e 100644 --- a/module/blades-item.js +++ b/module/blades-item.js @@ -24,46 +24,18 @@ export class BladesItem extends Item { /* -------------------------------------------- */ - /** @override */ - async _onCreate( data, options, userId ) { - super._onCreate( data, options, userId ); - - if( userId === game.user.id ) { - let actor = this.parent ? this.parent : null; - - if( ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) { - await BladesHelpers.callItemLogic( data, actor ); - } - } - } - - /* -------------------------------------------- */ - - /** @override */ - async _onDelete( options, userId ) { - super._onDelete( options, userId ); - - let actor = this.parent ? this.parent : null; - let data = this.data; - if ( ( actor?.documentName === "Actor" ) && ( actor?.permission >= CONST.ENTITY_PERMISSIONS.OWNER ) ) { - await BladesHelpers.undoItemLogic( data, actor ); - } - } - - /* -------------------------------------------- */ - /* override */ prepareData() { super.prepareData(); - + const item_data = this.data; const data = item_data.data; if (item_data.type === "cohort") { - + this._prepareCohort(data); - + } if (item_data.type === "faction") { @@ -80,7 +52,7 @@ export class BladesItem extends Item { /** * Prepares Cohort data * - * @param {object} data + * @param {object} data */ _prepareCohort(data) { @@ -88,22 +60,22 @@ export class BladesItem extends Item { let scale = 0; // Adds Scale and Quality - if (this.actor) { - switch (data.cohort[0]) { + if (this.actor.data) { + switch (data.cohort) { case "Gang": - scale = parseInt(this.actor.data.data.tier[0]); - quality = parseInt(this.actor.data.data.tier[0]); + scale = parseInt(this.actor.data.data.tier); + quality = parseInt(this.actor.data.data.tier); break; case "Expert": - scale = 1; - quality = parseInt(this.actor.data.data.tier[0]) + 1; + scale = 0; + quality = parseInt(this.actor.data.data.tier) + 1; break; } } data.scale = scale; data.quality = quality; - + this.data.data = data; } } diff --git a/system.json b/system.json index c80411f..9bdc1e2 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "blades-in-the-dark", "title": "Blades in the Dark", "description": "Blades in the dark game system.", - "version": "3.11", + "version": "3.12", "minimumCoreVersion": "0.8.5", "compatibleCoreVersion": "0.8.9", "templateVersion": 1, @@ -47,7 +47,7 @@ ], "url": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/", "manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/master/system.json", - "download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/3.11.zip", + "download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/3.12.zip", "packs": [ { "name": "class", diff --git a/template.json b/template.json index 88abeb0..781092b 100644 --- a/template.json +++ b/template.json @@ -136,7 +136,7 @@ "name": "", "reputation": [0], "lair": "", - "tier": [0], + "tier": "", "deity": "", "hold": ["strong"], "experience": [0], diff --git a/templates/items/cohort.html b/templates/items/cohort.html index 88bc1b8..6533cae 100644 --- a/templates/items/cohort.html +++ b/templates/items/cohort.html @@ -6,7 +6,7 @@

- +
{{localize "BITD.Information"}}
@@ -56,11 +56,13 @@
{{!-- Scale and Quality if attached to Actor --}} - {{#if data.quality}} + {{#if (eq document.parent.documentName "Actor")}}
{{localize "BITD.ScaleAndQuality"}}
-
{{localize "BITD.Quality"}}: {{data.quality}}
-
{{localize "BITD.Scale"}}: {{data.scale}}
+
+ {{localize "BITD.Quality"}}: {{data.quality}} + {{localize "BITD.Scale"}}: {{data.scale}} +
{{/if}} @@ -97,7 +99,7 @@ - +
{{localize "BITD.Harm"}}
@@ -110,7 +112,7 @@
-
+