From 357446de0c0d2dc91a6851b5c1f24ecbac317bff Mon Sep 17 00:00:00 2001 From: Megastruktur Date: Fri, 21 Aug 2020 18:03:37 +0300 Subject: [PATCH] attribute_change logic and trauma refactoring --- CHANGELOG.txt | 2 + README.md | 1 + module/blades-crew-sheet.js | 1 - module/blades-helpers.js | 84 ++++++++++++++++++++++++--------- module/blades.js | 7 ++- module/migration.js | 1 + system.json | 6 +-- template.json | 1 + templates/actor-sheet.html | 24 +++++----- templates/parts/attributes.html | 1 - 10 files changed, 87 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 899809a..189e55b 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -4,6 +4,8 @@ v2.0 - Added Ghost - Added Vampire - Added Logic field to Item, Class and Ability +- Removed dice icons on Attributes +- Added new logic operator "name_change" v1.2 - Non-Turf claims are no longer counted against Rep-Turf limit diff --git a/README.md b/README.md index 318e06d..d077f73 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ Logic field is a json with params which allows to implement some logic when the ### Operators list - `addition` - is added when item is attached and substracted when removed +- `attribute_change` - changes the "attribute" to value and when removed - uses the "attribute_default" to restore ## To be done in the nearest future - Friends/rivals section diff --git a/module/blades-crew-sheet.js b/module/blades-crew-sheet.js index e5e1f38..9d2e0de 100644 --- a/module/blades-crew-sheet.js +++ b/module/blades-crew-sheet.js @@ -32,7 +32,6 @@ export class BladesCrewSheet extends BladesSheet { if (item.type === "crew_type") { // Object.entries(item.data.turfs).forEach(turf => {turfs_amount += (turf.value === true) ? 1 : 0}); Object.entries(item.data.turfs).forEach(([key, turf]) => { - console.log(turf); if (turf.name === 'BITD.Turf') { turfs_amount += (turf.value === true) ? 1 : 0; } diff --git a/module/blades-helpers.js b/module/blades-helpers.js index 822a4be..b97ee64 100644 --- a/module/blades-helpers.js +++ b/module/blades-helpers.js @@ -97,21 +97,37 @@ export class BladesHelpers { */ static callItemLogic(item_data, entity) { - if ('logic' in item_data.data) { + 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) { - // Different logic behav. dep on operator. - switch (logic.operator) { - - // Add when creating. - case "addition": - entity.update({ - [logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) + logic.value - }); - break; - - } + + logic.forEach(expression => { + + // Different logic behav. dep on operator. + switch (expression.operator) { + + // Add when creating. + case "addition": + entity.update({ + [expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + expression.attribute)) + expression.value + }); + break; + + // Change name property. + case "attribute_change": + entity.update({ + [expression.attribute]: expression.value + }); + break; + + } + }); } } @@ -128,20 +144,42 @@ export class BladesHelpers { */ static undoItemLogic(item_data, entity) { - if ('logic' in item_data.data) { + if ('logic' in item_data.data && item_data.data.logic !== '') { let logic = JSON.parse(item_data.data.logic) - if (logic) { - // Different logic behav. dep on operator. - switch (logic.operator) { - // Subtract when removing. - case "addition": - entity.update({ - [logic.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + logic.attribute)) - logic.value - }); - break; + // Should be an array to support multiple expressions + if (!Array.isArray(logic)) { + logic = [logic]; + } - } + if (logic) { + + var entity_data = entity.data; + + logic.forEach(expression => { + // Different logic behav. dep on operator. + switch (expression.operator) { + + // Subtract when removing. + case "addition": + entity.update({ + [expression.attribute]: Number(BladesHelpers.getNestedProperty(entity, "data." + expression.attribute)) - expression.value + }); + break; + + // Change name back to default. + case "attribute_change": + console.log(entity); + // 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); + + entity.update({ + [expression.attribute]: default_name + }); + break; + } + }); } } diff --git a/module/blades.js b/module/blades.js index 165c596..3d734b7 100644 --- a/module/blades.js +++ b/module/blades.js @@ -52,6 +52,11 @@ Hooks.once("init", async function() { let html = options.fn(this); + // Fix for single non-array values. + if ( !Array.isArray(selected) ) { + selected = [selected]; + } + if (typeof selected !== 'undefined') { selected.forEach(selected_value => { if (selected_value !== false) { @@ -153,7 +158,7 @@ Hooks.once("ready", function() { // Determine whether a system migration is required const currentVersion = game.settings.get("bitd", "systemMigrationVersion"); - const NEEDS_MIGRATION_VERSION = 1.2; + const NEEDS_MIGRATION_VERSION = 2.0; let needMigration = (currentVersion < NEEDS_MIGRATION_VERSION) || (currentVersion === null); diff --git a/module/migration.js b/module/migration.js index 53fb3db..3fc4852 100644 --- a/module/migration.js +++ b/module/migration.js @@ -78,6 +78,7 @@ function _migrateActor(actor) { // Migrate Trauma to Array if (typeof actor.data.trauma === 'undefined') { updateData[`data.trauma.list`] = actor.data.traumas; + updateData[`data.trauma.value`] = [actor.data.traumas.length]; updateData[`data.trauma.max`] = 4; updateData[`data.trauma.max_default`] = 4; updateData[`data.trauma.name_default`] = "BITD.Trauma"; diff --git a/system.json b/system.json index f369662..0be8376 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": "1.2", + "version": "2.0", "minimumCoreVersion": "0.5.3", "compatibleCoreVersion": "0.7.2", "templateVersion": 1, @@ -26,8 +26,8 @@ } ], "url": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/", - "manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/1.2/system.json", - "download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/1.2.zip", + "manifest": "https://raw.githubusercontent.com/megastruktur/foundryvtt-blades-in-the-dark/2.0/system.json", + "download": "https://github.com/megastruktur/foundryvtt-blades-in-the-dark/archive/2.0.zip", "packs": [ { "name": "class", diff --git a/template.json b/template.json index 05e7e69..659774d 100644 --- a/template.json +++ b/template.json @@ -13,6 +13,7 @@ "trauma": { "max": 4, "max_default": 4, + "value": [0], "name": "BITD.Trauma", "name_default": "BITD.Trauma", "list": [0] diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index 873512c..3aa59ba 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -94,11 +94,11 @@
{{#multiboxes data.stress.value}} - + {{#times_from_1 data.stress.max}} - + {{/times_from_1}} @@ -110,10 +110,10 @@
- + {{#times_from_1 data.trauma.max}} - + {{/times_from_1}}
@@ -124,35 +124,35 @@
{{#multiboxes data.trauma.list}} {{/multiboxes}} diff --git a/templates/parts/attributes.html b/templates/parts/attributes.html index 43c347d..5e92fc2 100644 --- a/templates/parts/attributes.html +++ b/templates/parts/attributes.html @@ -6,7 +6,6 @@
-
{{#multiboxes attribute.exp}}