Merge branch 'hotfix-rounding'

This commit is contained in:
Stefan Zermatten
2015-06-29 09:45:38 +02:00
3 changed files with 29 additions and 7 deletions

View File

@@ -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(

View File

@@ -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;

View File

@@ -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",
],
});