From 4b0da99276db7cc95743ebbc1369fe0ecd5d680e Mon Sep 17 00:00:00 2001 From: Peter Varaksin Date: Tue, 28 Apr 2020 15:19:50 +0300 Subject: [PATCH] Item Logic - Adds Item logic field - Adds Item Logic handlers --- module/blades-helpers.js | 68 +++++++++++++++++++++------------------ module/blades.js | 26 ++++++++++++--- module/crew-sheet.js | 7 ---- scss/mixin.scss | 6 ++-- scss/style.scss | 25 ++++++++++---- styles/blades.css | 29 +++++++++++++++++ template.json | 8 +++-- templates/crew-sheet.html | 46 +++++++++++++++++++++++--- 8 files changed, 155 insertions(+), 60 deletions(-) diff --git a/module/blades-helpers.js b/module/blades-helpers.js index 4b867e8..b8bb36b 100644 --- a/module/blades-helpers.js +++ b/module/blades-helpers.js @@ -3,20 +3,17 @@ export class BladesHelpers { /** * Removes a duplicate item type from charlist. * - * @param {string} item_type - * @param {Actor} actor + * @param {Object} item_data + * @param {Entity} actor */ - static removeDuplicatedItemType(item_type, actor) { + static removeDuplicatedItemType(item_data, actor) { - let distinct_types = ["class", "heritage", "background", "vice", "crew_type"]; - - if (distinct_types.indexOf(item_type) >= 0) { - actor.items.forEach(i => { - if (i.data.type === item_type) { - actor.deleteOwnedItem(i.id); - } - }); - } + // If the Item has the exact same name - remove it from list. + actor.items.forEach(i => { + if (i.data.name === item_data.name) { + actor.deleteOwnedItem(i.id); + } + }); } /** @@ -99,16 +96,18 @@ export class BladesHelpers { if ('logic' in item_data.data) { let logic = JSON.parse(item_data.data.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; - + 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; + + } } } @@ -125,22 +124,27 @@ export class BladesHelpers { if ('logic' in item_data.data) { let logic = JSON.parse(item_data.data.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; + 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; + } } } } - + /** + * Get a nested dynamic attribute. + * @param {Object} obj + * @param {string} property + */ static getNestedProperty(obj, property) { return property.split('.').reduce((r, e) => { return r[e]; diff --git a/module/blades.js b/module/blades.js index c1213e1..275b33d 100644 --- a/module/blades.js +++ b/module/blades.js @@ -63,17 +63,17 @@ Hooks.once("init", async function() { }); // Equals handlebar. - Handlebars.registerHelper('eq', function (a, b, options) { + Handlebars.registerHelper('eq', (a, b, options) => { return (a === b) ? options.fn(this) : ''; }); // NotEquals handlebar. - Handlebars.registerHelper('noteq', function (a, b, options) { + Handlebars.registerHelper('noteq', (a, b, options) => { return (a !== b) ? options.fn(this) : ''; }); // ReputationTurf handlebar. - Handlebars.registerHelper('repturf', function (turfs_amount, options) { + Handlebars.registerHelper('repturf', (turfs_amount, options) => { let html = options.fn(this); var turfs_amount_int = parseInt(turfs_amount); @@ -89,19 +89,37 @@ Hooks.once("init", async function() { return html; }); + Handlebars.registerHelper('crew_vault_coins', (max_coins, options) => { + + let html = options.fn(this); + for (let i = 1; i <= max_coins; i++) { + + html += ""; + } + + return html; + }); + }); /* * Hooks */ Hooks.on("preCreateOwnedItem", (parent_entity, child_data, options, userId) => { - BladesHelpers.removeDuplicatedItemType(child_data.type, parent_entity); + + BladesHelpers.removeDuplicatedItemType(child_data, parent_entity); + + return true; }); Hooks.on("createOwnedItem", (parent_entity, child_data, options, userId) => { + BladesHelpers.callItemLogic(child_data, parent_entity); + return true; }); Hooks.on("deleteOwnedItem", (parent_entity, child_data, options, userId) => { + BladesHelpers.undoItemLogic(child_data, parent_entity); + return true; }); diff --git a/module/crew-sheet.js b/module/crew-sheet.js index 0739fd0..4cf7cb8 100644 --- a/module/crew-sheet.js +++ b/module/crew-sheet.js @@ -80,13 +80,6 @@ export class BladesCrewSheet extends ActorSheet { /* -------------------------------------------- */ - /** @override */ - _updateObject(event, formData) { - - // Update the Actor - return this.object.update(formData); - } - /** override */ _getFormData(form) { const FD = BladesHelpers.getFormDataHelper(form, this.editors); diff --git a/scss/mixin.scss b/scss/mixin.scss index a7dff43..b595f4c 100644 --- a/scss/mixin.scss +++ b/scss/mixin.scss @@ -96,7 +96,7 @@ /* * Custom Radio Squared */ - @mixin custom_radio_square($width, $height) { + @mixin custom_radio_square($side) { display: flex; $default_color: white; @@ -106,8 +106,8 @@ label { & { - height: $height; - width: $width; + height: $side; + width: $side; background-color: $accent_color; vertical-align: middle; diff --git a/scss/style.scss b/scss/style.scss index 62e872a..e3e5579 100644 --- a/scss/style.scss +++ b/scss/style.scss @@ -302,13 +302,16 @@ $red: red; margin: 0px 30px; } + $coin_size: 15px; + $coin_margin: 3px; + .coins { - @include custom_radio_square(15px, 15px); + @include custom_radio_square($coin_size); flex-wrap: wrap; label { - margin-right: 3px; - margin-bottom: 3px; + margin-right: $coin_margin; + margin-bottom: $coin_margin; &[for$="0"] { border-width: 2px; @@ -324,11 +327,21 @@ $red: red; } } + + // Crew Coins + .crew-coins { + @include custom_radio_square($coin_size); + flex-wrap: wrap; + max-width: 4 * ($coin_size + $coin_margin); + + label { + margin-right: $coin_margin; + margin-bottom: $coin_margin; + } + } + // Reputation - - - // Stress #crew-reputation { border-top: 3px solid black; @include toothradio(17px, 50px, "assets/teeth/stresstooth-halfgrey.png", "assets/teeth/stresstooth-red.png"); diff --git a/styles/blades.css b/styles/blades.css index 10b55d5..2226ac4 100644 --- a/styles/blades.css +++ b/styles/blades.css @@ -472,6 +472,35 @@ * .coins.coins-stashed { width: 190px; } +* .crew-coins { + display: flex; + /* Hide the browser's default checkbox */ + flex-wrap: wrap; + max-width: 72px; +} +* .crew-coins label { + height: 15px; + width: 15px; + background-color: grey; + vertical-align: middle; + border: 1px solid black; +} +* .crew-coins label[for$="-0"] { + margin-right: 0px; +} +* .crew-coins input { + display: none; +} +* .crew-coins input:checked ~ label { + background-color: white; +} +* .crew-coins input:checked + label { + background-color: grey; +} +* .crew-coins label { + margin-right: 3px; + margin-bottom: 3px; +} * #crew-reputation { border-top: 3px solid black; display: flex; diff --git a/template.json b/template.json index f8277d8..fd05eb2 100644 --- a/template.json +++ b/template.json @@ -71,11 +71,13 @@ "hold": ["strong"], "experience": [0], "hold_types": ["weak", "strong"], - "coins": [0], + "coins": { + "max": 4, + "value": [0] + }, "vault": { "value": [0], - "max": 0, - "default": 0 + "max": 0 }, "turfs": [8], "features": [], diff --git a/templates/crew-sheet.html b/templates/crew-sheet.html index 860c3b3..72788ce 100644 --- a/templates/crew-sheet.html +++ b/templates/crew-sheet.html @@ -85,6 +85,47 @@
Turf
+ {{!-- Coins --}} +
+ +
+
+ +
+
+ {{#multiboxes data.coins.value}} + + + + + + + + + + {{/multiboxes}} +
+
+ + {{#if data.vault.max}} +
+ +
+ +
+
+ {{#multiboxes data.vault.value}} + + {{#crew_vault_coins data.vault.max}}{{/crew_vault_coins}} + {{/multiboxes}} +
+ +
+ {{/if}} + +
+ + {{!-- Heat/Wanted --}}
@@ -183,11 +224,6 @@ {{/each}}
-
-
-

-
-