From a8960e26eceb6ef5bc1e9d32a6a5b123c093164b Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 6 Mar 2017 14:50:46 +0200 Subject: [PATCH] Fixed issue with health bars clamping to 100 --- rpg-docs/client/lib/bindProperty.js | 24 +++++++++++++++++++ .../stats/healthCard/healthCard.html | 2 -- .../character/stats/healthCard/healthCard.js | 23 ++++++++++++++++++ .../paper-diff-slider/paper-diff-slider.html | 15 ++++-------- 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 rpg-docs/client/lib/bindProperty.js diff --git a/rpg-docs/client/lib/bindProperty.js b/rpg-docs/client/lib/bindProperty.js new file mode 100644 index 00000000..b2de2e00 --- /dev/null +++ b/rpg-docs/client/lib/bindProperty.js @@ -0,0 +1,24 @@ +/** + * Take in a map like this: + * { + * "#someId": { + * proprty1() { return someReactiveValue()} + * } + * } + * and bind the properties to the DOM on autorun. + * + * Useful for polymer components where you need to set the order of property updating + * or alter properties that don't bind well to their attributes + */ +Blaze.Template.prototype.binding = function(bindingMap){ + this.onRendered(function(){ + _.each(bindingMap, (propertyMap, cssPattern) => { + node = this.find(cssPattern); + _.each(propertyMap, (func, property) => { + this.autorun(() => { + node[property] = func && func.call && func.call(this, node); + }); + }); + }); + }); +}; diff --git a/rpg-docs/client/views/character/stats/healthCard/healthCard.html b/rpg-docs/client/views/character/stats/healthCard/healthCard.html index 3309c710..95421510 100644 --- a/rpg-docs/client/views/character/stats/healthCard/healthCard.html +++ b/rpg-docs/client/views/character/stats/healthCard/healthCard.html @@ -13,8 +13,6 @@
diff --git a/rpg-docs/client/views/character/stats/healthCard/healthCard.js b/rpg-docs/client/views/character/stats/healthCard/healthCard.js index 364b4dd5..86b93574 100644 --- a/rpg-docs/client/views/character/stats/healthCard/healthCard.js +++ b/rpg-docs/client/views/character/stats/healthCard/healthCard.js @@ -1,3 +1,26 @@ +const currentId = () => Template.currentData()._id; + +// Use binding to ensure max is always set before value to prevent value clamping poorly +Template.healthCard.binding({ + "#hitPointSlider": { + max: () => Characters.calculate.attributeBase(currentId() , "hitPoints"), + value: () => Characters.calculate.attributeValue(currentId() , "hitPoints"), + } +}); + +// Reset the old value between characters so that we don't get red health lost +// bar when changing character +Template.healthCard.onRendered(function(){ + let oldId = Template.currentData()._id; + this.autorun(() => { + const id = Template.currentData()._id; + if (oldId !== id){ + this.find("#hitPointSlider").resetOldValue(); + oldId = id; + } + }); +}); + Template.healthCard.helpers({ tempHitPoints: function(){ return TemporaryHitPoints.find({charId: this._id}); diff --git a/rpg-docs/public/custom_components/paper-diff-slider/paper-diff-slider.html b/rpg-docs/public/custom_components/paper-diff-slider/paper-diff-slider.html index e624a428..6474e63c 100644 --- a/rpg-docs/public/custom_components/paper-diff-slider/paper-diff-slider.html +++ b/rpg-docs/public/custom_components/paper-diff-slider/paper-diff-slider.html @@ -1,13 +1,3 @@ -s - @@ -514,6 +504,11 @@ Custom property | Description | Default this.value = this._clampValue(this.value - this.step); }, + resetOldValue: function(){ + this.secondaryProgress = this.value; + this._setOldValue(this.value); + }, + _updateKnob: function(value, min, max, snaps, step) { this.setAttribute('aria-valuemin', min); this.setAttribute('aria-valuemax', max);