From e0ce6275bffb437d54c778bded9df1d71d2d024b Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 29 Jun 2015 09:40:37 +0200 Subject: [PATCH 1/3] Floor character attribute values --- rpg-docs/Model/Character/Characters.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/rpg-docs/Model/Character/Characters.js b/rpg-docs/Model/Character/Characters.js index b4d76c60..efee22a4 100644 --- a/rpg-docs/Model/Character/Characters.js +++ b/rpg-docs/Model/Character/Characters.js @@ -186,7 +186,7 @@ Schemas.Character = new SimpleSchema({ Characters.attachSchema(Schemas.Character); -var attributeBase = function(charId, statName){ +var attributeBase = preventLoop(function(charId, statName){ check(statName, String); //if it's a damage multiplier, we treat it specially if (_.contains(DAMAGE_MULTIPLIERS, statName)){ @@ -253,8 +253,8 @@ var attributeBase = function(charId, statName){ if (result < min) result = min; if (result > max) result = max; - return result; -}; + return Math.floor(result); +}); if (Meteor.isClient) { Template.registerHelper("characterCalculate", function(func, charId, input) { @@ -324,9 +324,9 @@ Characters.calculate = { value += attribute.adjustment; return value; }), - attributeBase: memoize(preventLoop(function(charId, attributeName){ + attributeBase: memoize(function(charId, attributeName){ return attributeBase(charId, attributeName); - })), + }), skillMod: memoize(preventLoop(function(charId, skillName){ var skill = Characters.calculate.getField(charId, skillName); //get the final value of the ability score @@ -369,7 +369,7 @@ Characters.calculate = { if (result < min) result = min; if (result > max) result = max; - return result; + return Math.floor(result); })), proficiency: memoize(function(charId, skillName){ //return largest value in proficiency array @@ -390,7 +390,7 @@ Characters.calculate = { }); var advantage = Characters.calculate.advantage(charId, skillName); value += 5 * advantage; - return value; + return Math.floor(value); }), advantage: memoize(function(charId, skillName){ var advantage = Effects.find( From 453d4365d3226547a176fb410ff87de09bdd1aea Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 29 Jun 2015 09:41:01 +0200 Subject: [PATCH 2/3] Prevent memoized values being used in dependency loops --- rpg-docs/lib/memoize/memoize.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rpg-docs/lib/memoize/memoize.js b/rpg-docs/lib/memoize/memoize.js index 092a4036..0b98d376 100644 --- a/rpg-docs/lib/memoize/memoize.js +++ b/rpg-docs/lib/memoize/memoize.js @@ -15,6 +15,7 @@ function CacheObject(func, address, args, cache, context){ var self = this; self.currentValue = null; self.dep = new Tracker.Dependency(); + self.numRun = 0; //spawn a new autorun that keeps the value up-to-date Tracker.nonreactive(function() { @@ -26,8 +27,22 @@ function CacheObject(func, address, args, cache, context){ delete cache[address]; return; } + //if we haven't run this before this flush, reset the counter after the flush + if(self.numRun === 0){ + Tracker.afterFlush(function(){ + self.numRun = 0; + }); + } + self.numRun++; //call the expensive function + //even if we don't use its value, we need to track its dependencies var newValue = func.apply(context, args); + //prevent dependency loops, the memoized function shouldn't re-run + //more than once per flush + if (self.numRun > 1){ + newValue = NaN; + if(_.isNaN(self.currentValue)) return; + } //if the value changed, store the new value if (self.currentValue !== newValue){ self.currentValue = newValue; From 266495abc8b23b7e5f7f6922f170ec1fcc521e79 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 29 Jun 2015 09:44:57 +0200 Subject: [PATCH 3/3] Bumped version --- rpg-docs/private/changeLogs/changeLogs.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rpg-docs/private/changeLogs/changeLogs.js b/rpg-docs/private/changeLogs/changeLogs.js index 741181e0..a4346a1b 100644 --- a/rpg-docs/private/changeLogs/changeLogs.js +++ b/rpg-docs/private/changeLogs/changeLogs.js @@ -201,3 +201,10 @@ ChangeLogs.insert({ ], }); +ChangeLogs.insert({ + version: "0.6.3", + changes: [ + "Fixed a regression that stopped skills and attributes from rounding down correctly", + "Made dependency loops return NaN immediately, rather than looping indefinitely until a page refresh. Adding an effect that adds \"strength\" to Strength, won't cause Strength to constantly increase or freeze the browser, Strength just becomes NaN", + ], +});