From 2b9cbcf7170df9ea0b361049bd883de9ef12fac2 Mon Sep 17 00:00:00 2001 From: Thaum Date: Wed, 11 Mar 2015 09:43:45 +0000 Subject: [PATCH] Implemented enabling/disabling of features --- rpg-docs/Model/Character/Features.js | 10 ++++++ .../features/featureDialog/featureDialog.html | 11 +++++- .../features/featureDialog/featureDialog.js | 12 ++++++- .../views/character/features/features.css | 34 +++++++++++++++++++ .../views/character/features/features.html | 6 ++++ .../views/character/features/features.js | 15 ++++++++ .../client/views/character/spells/spells.html | 8 +++-- 7 files changed, 92 insertions(+), 4 deletions(-) diff --git a/rpg-docs/Model/Character/Features.js b/rpg-docs/Model/Character/Features.js index 327d51c5..782a6a8a 100644 --- a/rpg-docs/Model/Character/Features.js +++ b/rpg-docs/Model/Character/Features.js @@ -7,6 +7,7 @@ Schemas.Feature = new SimpleSchema({ uses: {type: String, optional: true, trim: false}, used: {type: Number, defaultValue: 0}, reset: {type: String, allowedValues: ["manual", "longRest", "shortRest"], defaultValue: "manual"}, + enabled: {type: String, allowedValues: ["enabled", "disabled", "alwaysEnabled"], defaultValue: "alwaysEnabled"}, color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"} }); @@ -21,8 +22,17 @@ Features.helpers({ } }); +//Delete effects where this the removed feature is source Features.before.remove(function (userId, feature) { Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){ Effects.remove(effect._id); }); }); + +//keep the effects up to date with enabled state +Features.after.update(function (userId, feature, fieldNames, modifier, options) { + var enabled = feature.enabled !== "disabled"; + Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){ + Effects.update(effect._id, { $set: {charId: feature.charId, enabled: enabled, name: feature.name} }); + }); +}, {fetchPrevious: false}); diff --git a/rpg-docs/client/views/character/features/featureDialog/featureDialog.html b/rpg-docs/client/views/character/features/featureDialog/featureDialog.html index c6114872..cf698f85 100644 --- a/rpg-docs/client/views/character/features/featureDialog/featureDialog.html +++ b/rpg-docs/client/views/character/features/featureDialog/featureDialog.html @@ -24,8 +24,17 @@ {{#if usesSet}} {{/if}} + + + + Always Enabled + Enabled + Disabled + + + - {{> effectsEditList sourceId=_id charId=charId type="feature"}} + {{> effectsEditList sourceId=_id charId=charId type="feature" name=name enabled=isEnabled}} {{/baseDialog}} {{/with}} \ No newline at end of file diff --git a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js index 7af79601..8445df3d 100644 --- a/rpg-docs/client/views/character/features/featureDialog/featureDialog.js +++ b/rpg-docs/client/views/character/features/featureDialog/featureDialog.js @@ -27,7 +27,14 @@ Template.featureDialog.events({ var value = event.target.value; var featureId = this._id; Features.update(featureId, {$set: {uses: value}}); - } + }, + "core-select #enabledDropdown": function(event){ + var detail = event.originalEvent.detail; + if(!detail.isSelected) return; + var value = detail.item.getAttribute("name"); + if (value === this.enabled) return; + Features.update(this._id, {$set: {enabled: value}}); + }, }); Template.featureDialog.helpers({ @@ -36,5 +43,8 @@ Template.featureDialog.helpers({ }, usesSet: function(){ return _.isString(this.uses); + }, + isEnabled: function(){ + return this.enabled !== "disabled"; } }); \ No newline at end of file diff --git a/rpg-docs/client/views/character/features/features.css b/rpg-docs/client/views/character/features/features.css index 633bc3be..6f97bac2 100644 --- a/rpg-docs/client/views/character/features/features.css +++ b/rpg-docs/client/views/character/features/features.css @@ -21,3 +21,37 @@ .resourceCards paper-shadow.healthCard { width: 100%; } + +/*To change the ink color for checked state:*/ +paper-checkbox.enabledCheckbox::shadow #ink[checked] { + color: #ffffff; +} + +/*To change the checkbox checked color:*/ +paper-checkbox.enabledCheckbox::shadow #checkbox.checked { + background-color: #ffffff; + background-color: rgba(255,255,255,0.27); + border-color: #ffffff; + border-color: rgba(255,255,255,0.27); +} + +/*ensure the checkmark is shown when ticked*/ +paper-checkbox.enabledCheckbox::shadow #checkbox.checked #checkmark { + display: initial; +} + +/*To change the ink color for unchecked state:*/ +paper-checkbox.enabledCheckbox::shadow #ink { + color: #ffffff; +} + +/*To change the checkbox unchecked color:*/ +paper-checkbox.enabledCheckbox::shadow #checkbox { + border-color: #ffffff; + border-color: rgba(255,255,255,0.54); +} + +/*ensure checkmark isn't shown early*/ +paper-checkbox.enabledCheckbox::shadow #checkbox #checkmark { + display: none; +} diff --git a/rpg-docs/client/views/character/features/features.html b/rpg-docs/client/views/character/features/features.html index 6222ca57..c98e54d1 100644 --- a/rpg-docs/client/views/character/features/features.html +++ b/rpg-docs/client/views/character/features/features.html @@ -65,9 +65,15 @@ {{#each features}}
+
{{name}}
{{#if hasUses}}
{{usesLeft}}/{{usesValue}}
{{/if}} + {{#if canEnable}} + + + + {{/if}}
{{#if description}}
{{description}}
{{/if}} {{#if hasUses}} diff --git a/rpg-docs/client/views/character/features/features.js b/rpg-docs/client/views/character/features/features.js index d43278c5..71778d39 100644 --- a/rpg-docs/client/views/character/features/features.js +++ b/rpg-docs/client/views/character/features/features.js @@ -24,6 +24,12 @@ Template.features.helpers({ characterProficiencies: function(){ var char = Characters.findOne(this._id); return char && char.proficiencies; + }, + canEnable: function(){ + return this.enabled !== "alwaysEnabled"; + }, + isEnabled: function(){ + return this.enabled !== "disabled"; } }); @@ -83,6 +89,15 @@ Template.features.events({ data: {charId: charId, field: "proficiencies", title: "Proficiencies", color: "q"}, heroId: this._id + "proficiencies" }); + }, + "tap .enabledCheckbox": function(event){ + event.stopPropagation(); + }, + "change .enabledCheckbox": function(event){ + var enabled; + if(this.enabled === "enabled") enabled = "disabled"; + else enabled = "enabled"; + Features.update(this._id, {$set: {enabled: enabled}}); } }); diff --git a/rpg-docs/client/views/character/spells/spells.html b/rpg-docs/client/views/character/spells/spells.html index 4dd28148..c9bfd8f0 100644 --- a/rpg-docs/client/views/character/spells/spells.html +++ b/rpg-docs/client/views/character/spells/spells.html @@ -42,9 +42,13 @@ {{#if settings.showUnprepared}} {{#if maxPrepared}}
{{numPrepared}} / {{evaluate charId maxPrepared}}
{{/if}} - + + + {{else}} - + + + {{/if}}