- {{char.skillMod skillName}}
+ {{characterCalculate "skillMod" charId skillName}}
@@ -25,9 +25,9 @@
| {{abilityName}} |
- {{char.abilityMod ability}} |
+ {{characterCalculate "abilityMod" charId ability}} |
- {{#if char.proficiency skillName}}
+ {{#if characterCalculate "proficiency" charId skillName}}
| {{proficiencyValue}} |
{{signedString profBonus}} |
@@ -59,7 +59,7 @@
{{/each}}
| Total |
- {{char.skillMod skillName}} |
+ {{characterCalculate "skillMod" charId skillName}} |
diff --git a/rpg-docs/client/views/character/stats/skillDialog/skillDialog.js b/rpg-docs/client/views/character/stats/skillDialog/skillDialog.js
index c2cbf6fc..759c1f11 100644
--- a/rpg-docs/client/views/character/stats/skillDialog/skillDialog.js
+++ b/rpg-docs/client/views/character/stats/skillDialog/skillDialog.js
@@ -106,9 +106,7 @@ Template.skillDialogView.helpers({
return a || b || c;
},
profIcon: function(){
- var char = Characters.findOne(this.charId);
- if (!char) return;
- var prof = char.proficiency(this.skillName);
+ var prof = Characters.calculate.proficiency(this.charId, this.skillName);
if (prof > 0 && prof < 1) return "image:brightness-2";
if (prof === 1) return "image:brightness-1";
if (prof > 1) return "av:album";
@@ -123,13 +121,13 @@ Template.skillDialogView.helpers({
profBonus: function(){
var char = Characters.findOne(this.charId);
if (!char) return;
- return char.proficiency(this.skillName) *
- char.attributeValue("proficiencyBonus");
+ var prof = Characters.calculate.proficiency(this.charId, this.skillName);
+ var proficiencyBonus =
+ Characters.calculate.attributeValue(this.charId, "proficiencyBonus");
+ return prof * proficiencyBonus;
},
proficiencyValue: function(){
- var char = Characters.findOne(this.charId);
- if (!char) return;
- var prof = char.proficiency(this.skillName);
+ var prof = Characters.calculate.proficiency(this.charId, this.skillName);
if (prof == 0.5) return "Half Proficiency";
if (prof == 1) return "Proficient";
if (prof == 2) return "Double Proficiency";
@@ -199,22 +197,15 @@ Template.skillDialogView.helpers({
return skill.ability;
},
abilityName: function(){
- var opts = {fields: {}};
- opts.fields[this.skillName] = 1;
- var char = Characters.findOne(this.charId, opts);
- if (!char) return;
- var skill = char[this.skillName];
+ var skill = Characters.calculate.getField(this.charId, this.skillName);
if (!skill) return;
var ability = skill.ability;
return abilities[ability] && abilities[ability].name;
},
- char: function(){
- return Characters.findOne(this.charId, {fields:{_id: 1}});
- },
sourceName: function(){
if (this.parent.collection === "Characters"){
if (this.parent.group === "racial"){
- return Characters.findOne(this.charId, {fields:{race: 1}}).race || "Race";
+ return Characters.calculate.getField(this.charId, "race") || "Race";
}
if (this.parent.group === "background"){
return "Background";
diff --git a/rpg-docs/client/views/character/stats/skillRow/skillRow.html b/rpg-docs/client/views/character/stats/skillRow/skillRow.html
index 65cc3814..37caa03b 100644
--- a/rpg-docs/client/views/character/stats/skillRow/skillRow.html
+++ b/rpg-docs/client/views/character/stats/skillRow/skillRow.html
@@ -8,7 +8,9 @@
{{#if failSkill}}
fail
{{else}}
-
{{../skillMod skill}}
+
+ {{characterCalculate "skillMod" ../_id skill}}
+
{{/if}}
{{name}}
@@ -16,7 +18,7 @@
*
{{/if}}
{{#if showPassive}}
- ({{../passiveSkill skill}})
+ ({{characterCalculate "passiveSkill" ../_id skill}})
{{/if}}
diff --git a/rpg-docs/client/views/character/stats/skillRow/skillRow.js b/rpg-docs/client/views/character/stats/skillRow/skillRow.js
index 8c4ca52c..760c0e4f 100644
--- a/rpg-docs/client/views/character/stats/skillRow/skillRow.js
+++ b/rpg-docs/client/views/character/stats/skillRow/skillRow.js
@@ -7,7 +7,7 @@ Template.skillRow.helpers({
return "radio-button-off";
},
failSkill: function(){
- var charId = Template.parentData(1)._id;
+ var charId = Template.parentData()._id;
return Effects.find({
charId: charId,
stat: this.skill,
@@ -16,12 +16,13 @@ Template.skillRow.helpers({
}).count();
},
advantage: function(){
- var advantage = Template.parentData(1).advantage(this.skill);
+ var charId = Template.parentData()._id;
+ var advantage = Characters.calculate.advantage(charId, this.skill);
if (advantage > 0) return "advantage";
if (advantage < 0) return "disadvantage";
},
conditionalCount: function(){
- var charId = Template.parentData(1)._id;
+ var charId = Template.parentData()._id;
return Effects.find({
charId: charId,
stat: this.skill,
diff --git a/rpg-docs/client/views/character/stats/stats.html b/rpg-docs/client/views/character/stats/stats.html
index 20a63d87..0e7eb6da 100644
--- a/rpg-docs/client/views/character/stats/stats.html
+++ b/rpg-docs/client/views/character/stats/stats.html
@@ -75,9 +75,9 @@
{{#if isSkill}}
- {{../skillMod stat}}
+ {{characterCalculate "skillMod" ../_id stat}}
{{else}}
- {{prefix}}{{../attributeValue stat}}
+ {{prefix}}{{characterCalculate "attributeValue" ../_id stat}}
{{/if}}
diff --git a/rpg-docs/lib/functions/preventLoop.js b/rpg-docs/lib/functions/preventLoop.js
index d71b6a2c..12deea1f 100644
--- a/rpg-docs/lib/functions/preventLoop.js
+++ b/rpg-docs/lib/functions/preventLoop.js
@@ -1,4 +1,5 @@
preventLoop = function(inputFunction){
+ var self = this;
if (!_.isFunction(inputFunction)){
throw new Meteor.Error(
"Not a function",
@@ -9,23 +10,26 @@ preventLoop = function(inputFunction){
//if we try to visit the same argument twice before resolving its value
//we are in a dependency loop and need to GTFO
var visitedArgs = [];
- return function(argument){
- var value;
+ return function(){
+ var result;
+ var hash = _.reduce(arguments, function(memo, arg) {
+ return memo + arg;
+ }, "");
//we're still evaluating this attribute, must be in a loop
- if (_.contains(visitedArgs, argument)) {
+ if (_.contains(visitedArgs, hash)) {
console.warn("dependency loop detected");
return NaN;
} else {
- //push this skill to the list of visited skills
+ //push this hash to the list of visited hashes
//we can't visit it again unless it returns first
- visitedArgs.push(argument);
+ visitedArgs.push(hash);
}
try {
- value = inputFunction.call(this, argument);
+ result = inputFunction.apply(this, arguments);
} finally{
- //this argument returns or fails, pull it from the array
- visitedArgs = _.without(visitedArgs, argument);
+ //this hash returns or fails, pull it from the array
+ visitedArgs = _.without(visitedArgs, hash);
}
- return value;
+ return result;
};
};
diff --git a/rpg-docs/lib/memoize/memoize.js b/rpg-docs/lib/memoize/memoize.js
index 6d510374..092a4036 100644
--- a/rpg-docs/lib/memoize/memoize.js
+++ b/rpg-docs/lib/memoize/memoize.js
@@ -24,7 +24,7 @@ function CacheObject(func, address, args, cache, context){
if (!computation.firstRun && !self.dep.hasDependents()){
computation.stop();
delete cache[address];
- console.log("Nothing depends on '" + address + "', deleting");
+ return;
}
//call the expensive function
var newValue = func.apply(context, args);