Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
463b7f0fc9 | ||
|
|
266495abc8 | ||
|
|
453d4365d3 | ||
|
|
e0ce6275bf |
@@ -186,7 +186,7 @@ Schemas.Character = new SimpleSchema({
|
|||||||
|
|
||||||
Characters.attachSchema(Schemas.Character);
|
Characters.attachSchema(Schemas.Character);
|
||||||
|
|
||||||
var attributeBase = function(charId, statName){
|
var attributeBase = preventLoop(function(charId, statName){
|
||||||
check(statName, String);
|
check(statName, String);
|
||||||
//if it's a damage multiplier, we treat it specially
|
//if it's a damage multiplier, we treat it specially
|
||||||
if (_.contains(DAMAGE_MULTIPLIERS, statName)){
|
if (_.contains(DAMAGE_MULTIPLIERS, statName)){
|
||||||
@@ -253,8 +253,8 @@ var attributeBase = function(charId, statName){
|
|||||||
if (result < min) result = min;
|
if (result < min) result = min;
|
||||||
if (result > max) result = max;
|
if (result > max) result = max;
|
||||||
|
|
||||||
return result;
|
return Math.floor(result);
|
||||||
};
|
});
|
||||||
|
|
||||||
if (Meteor.isClient) {
|
if (Meteor.isClient) {
|
||||||
Template.registerHelper("characterCalculate", function(func, charId, input) {
|
Template.registerHelper("characterCalculate", function(func, charId, input) {
|
||||||
@@ -324,9 +324,9 @@ Characters.calculate = {
|
|||||||
value += attribute.adjustment;
|
value += attribute.adjustment;
|
||||||
return value;
|
return value;
|
||||||
}),
|
}),
|
||||||
attributeBase: memoize(preventLoop(function(charId, attributeName){
|
attributeBase: memoize(function(charId, attributeName){
|
||||||
return attributeBase(charId, attributeName);
|
return attributeBase(charId, attributeName);
|
||||||
})),
|
}),
|
||||||
skillMod: memoize(preventLoop(function(charId, skillName){
|
skillMod: memoize(preventLoop(function(charId, skillName){
|
||||||
var skill = Characters.calculate.getField(charId, skillName);
|
var skill = Characters.calculate.getField(charId, skillName);
|
||||||
//get the final value of the ability score
|
//get the final value of the ability score
|
||||||
@@ -369,7 +369,7 @@ Characters.calculate = {
|
|||||||
if (result < min) result = min;
|
if (result < min) result = min;
|
||||||
if (result > max) result = max;
|
if (result > max) result = max;
|
||||||
|
|
||||||
return result;
|
return Math.floor(result);
|
||||||
})),
|
})),
|
||||||
proficiency: memoize(function(charId, skillName){
|
proficiency: memoize(function(charId, skillName){
|
||||||
//return largest value in proficiency array
|
//return largest value in proficiency array
|
||||||
@@ -390,7 +390,7 @@ Characters.calculate = {
|
|||||||
});
|
});
|
||||||
var advantage = Characters.calculate.advantage(charId, skillName);
|
var advantage = Characters.calculate.advantage(charId, skillName);
|
||||||
value += 5 * advantage;
|
value += 5 * advantage;
|
||||||
return value;
|
return Math.floor(value);
|
||||||
}),
|
}),
|
||||||
advantage: memoize(function(charId, skillName){
|
advantage: memoize(function(charId, skillName){
|
||||||
var advantage = Effects.find(
|
var advantage = Effects.find(
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ function CacheObject(func, address, args, cache, context){
|
|||||||
var self = this;
|
var self = this;
|
||||||
self.currentValue = null;
|
self.currentValue = null;
|
||||||
self.dep = new Tracker.Dependency();
|
self.dep = new Tracker.Dependency();
|
||||||
|
self.numRun = 0;
|
||||||
|
|
||||||
//spawn a new autorun that keeps the value up-to-date
|
//spawn a new autorun that keeps the value up-to-date
|
||||||
Tracker.nonreactive(function() {
|
Tracker.nonreactive(function() {
|
||||||
@@ -26,8 +27,22 @@ function CacheObject(func, address, args, cache, context){
|
|||||||
delete cache[address];
|
delete cache[address];
|
||||||
return;
|
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
|
//call the expensive function
|
||||||
|
//even if we don't use its value, we need to track its dependencies
|
||||||
var newValue = func.apply(context, args);
|
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 the value changed, store the new value
|
||||||
if (self.currentValue !== newValue){
|
if (self.currentValue !== newValue){
|
||||||
self.currentValue = newValue;
|
self.currentValue = newValue;
|
||||||
|
|||||||
@@ -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",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user