@@ -24,6 +24,10 @@ Template.registerHelper("evaluateString", function(charId, string) {
|
|||||||
return evaluateString(charId, string);
|
return evaluateString(charId, string);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Template.registerHelper("evaluateSpellString", function(charId, spellListId, string) {
|
||||||
|
return evaluateSpellString(charId, spellListId, string);
|
||||||
|
});
|
||||||
|
|
||||||
Template.registerHelper("evaluateShortString", function(charId, string) {
|
Template.registerHelper("evaluateShortString", function(charId, string) {
|
||||||
if (_.isString(string)){
|
if (_.isString(string)){
|
||||||
return evaluateString(
|
return evaluateString(
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<div>{{#markdown}}{{evaluateString charId description}}{{/markdown}}</div>
|
<div>{{#markdown}}{{evaluateSpellString charId parent.id description}}{{/markdown}}</div>
|
||||||
{{> attacksViewList charId=charId parentId=_id}}
|
{{> attacksViewList charId=charId parentId=_id}}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
//evaluates a calculation string
|
//evaluates a calculation string
|
||||||
evaluate = function(charId, string){
|
evaluate = function(charId, string, opts){
|
||||||
|
var spellListId = opts && opts.spellListId;
|
||||||
if (!string) return string;
|
if (!string) return string;
|
||||||
string = string.replace(/\b[a-z]+\b/gi, function(sub){
|
string = string.replace(/\b[a-z]+\b/gi, function(sub){
|
||||||
//fields
|
//fields
|
||||||
@@ -43,6 +44,12 @@ evaluate = function(charId, string){
|
|||||||
if (sub.toUpperCase() === "LEVEL"){
|
if (sub.toUpperCase() === "LEVEL"){
|
||||||
return Characters.calculate.level(charId);
|
return Characters.calculate.level(charId);
|
||||||
}
|
}
|
||||||
|
if (spellListId && sub.toUpperCase() === "DC") {
|
||||||
|
var list = SpellLists.findOne(spellListId);
|
||||||
|
if (list && list.saveDC){
|
||||||
|
return evaluate(charId, list.saveDC);
|
||||||
|
}
|
||||||
|
}
|
||||||
return sub;
|
return sub;
|
||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
@@ -66,6 +73,17 @@ evaluateString = function(charId, string){
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
evaluateSpellString = function (charId, spellListId, string) {
|
||||||
|
//define brackets as curly brackets around anything that isn't a curly bracket
|
||||||
|
if (!string) return string;
|
||||||
|
var brackets = /\{[^\{\}]*\}/g;
|
||||||
|
var result = string.replace(brackets, function(exp){
|
||||||
|
exp = exp.replace(/(\{|\})/g, ""); //remove curly brackets
|
||||||
|
return evaluate(charId, exp, {spellListId});
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
//returns the value of the effect if it exists,
|
//returns the value of the effect if it exists,
|
||||||
//otherwise returns the result of the calculation if it exists,
|
//otherwise returns the result of the calculation if it exists,
|
||||||
//otherwise returns 0
|
//otherwise returns 0
|
||||||
|
|||||||
Reference in New Issue
Block a user