Consolidated all sub-documents into character document to improve granularity significantly
Because just the top-level field changing invalidates everything in the sub-document, a single attribute change would trigger a re-calculation on all attributes and their dependents. This change should significantly improve performance.
This commit is contained in:
8
rpg-docs/client/main.js
Normal file
8
rpg-docs/client/main.js
Normal file
@@ -0,0 +1,8 @@
|
||||
_.each(Template, function (template, name) {
|
||||
if(template){
|
||||
var counter = 0;
|
||||
template.rendered = template.rendered || function () {
|
||||
console.log(name, "render count: ", ++counter);
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -4,10 +4,10 @@
|
||||
Strength
|
||||
</div>
|
||||
<div class="abilityScore">
|
||||
{{attributeValue attributes.strength}}
|
||||
{{attributeValue "strength"}}
|
||||
</div>
|
||||
<div class="abilityMod">
|
||||
{{abilityMod attributes.strength}}
|
||||
{{abilityMod "strength"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ability floatBox">
|
||||
@@ -15,10 +15,10 @@
|
||||
Dexterity
|
||||
</div>
|
||||
<div class="abilityScore">
|
||||
{{attributeValue attributes.dexterity}}
|
||||
{{attributeValue "dexterity"}}
|
||||
</div>
|
||||
<div class="abilityMod">
|
||||
{{abilityMod attributes.dexterity}}
|
||||
{{abilityMod "dexterity"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ability floatBox">
|
||||
@@ -26,10 +26,10 @@
|
||||
Constitution
|
||||
</div>
|
||||
<div class="abilityScore">
|
||||
{{attributeValue attributes.constitution}}
|
||||
{{attributeValue "constitution"}}
|
||||
</div>
|
||||
<div class="abilityMod">
|
||||
{{abilityMod attributes.constitution}}
|
||||
{{abilityMod "constitution"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ability floatBox">
|
||||
@@ -37,10 +37,10 @@
|
||||
Intelligence
|
||||
</div>
|
||||
<div class="abilityScore">
|
||||
{{attributeValue attributes.intelligence}}
|
||||
{{attributeValue "intelligence"}}
|
||||
</div>
|
||||
<div class="abilityMod">
|
||||
{{abilityMod attributes.intelligence}}
|
||||
{{abilityMod "intelligence"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ability floatBox">
|
||||
@@ -48,10 +48,10 @@
|
||||
Wisdom
|
||||
</div>
|
||||
<div class="abilityScore">
|
||||
{{attributeValue attributes.wisdom}}
|
||||
{{attributeValue "wisdom"}}
|
||||
</div>
|
||||
<div class="abilityMod">
|
||||
{{abilityMod attributes.wisdom}}
|
||||
{{abilityMod "wisdom"}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="ability floatBox">
|
||||
@@ -59,10 +59,10 @@
|
||||
Charisma
|
||||
</div>
|
||||
<div class="abilityScore">
|
||||
{{attributeValue attributes.charisma}}
|
||||
{{attributeValue "charisma"}}
|
||||
</div>
|
||||
<div class="abilityMod">
|
||||
{{abilityMod attributes.charisma}}
|
||||
{{abilityMod "charisma"}}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -26,7 +26,7 @@
|
||||
<div class="healthBarRed" style="width: {{hpRed}}%"></div>
|
||||
<div class="healthBarGreen" style="width: {{hpGreen}}%"></div>
|
||||
<div class="healthBarBorder">
|
||||
<span class="hpReadout">{{attributeValue attributes.hitPoints}}/{{maxHp}}</span>
|
||||
<span class="hpReadout">{{attributeValue "hitPoints"}}/{{maxHp}}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
Template.healthBar.helpers({
|
||||
healthy: function(){
|
||||
var hp = this.attributeValue(this.attributes.hitPoints);
|
||||
var hp = this.attributeValue("hitPoints");
|
||||
return hp > 0;
|
||||
},
|
||||
dead: function(){
|
||||
if(this.deathSave.canDeathSave){
|
||||
return this.deathSave.fail >= 3;
|
||||
var deathSave = this.getField("deathSave");
|
||||
if(deathSave.canDeathSave){
|
||||
return deathSave.fail >= 3;
|
||||
} else{
|
||||
//creatures that can't make death saves die at 0 HP
|
||||
var hp = this.attributeValue(this.attributes.hitPoints);
|
||||
var hp = this.attributeValue("hitPoints");
|
||||
return hp <= 0;
|
||||
}
|
||||
}
|
||||
@@ -16,13 +17,13 @@ Template.healthBar.helpers({
|
||||
|
||||
Template.hitPointBars.helpers({
|
||||
hpRed: function(){
|
||||
var currentHp = this.attributeValue(this.attributes.hitPoints);
|
||||
var damage = this.attributes.hitPoints.base;
|
||||
var currentHp = this.attributeValue("hitPoints");
|
||||
var damage = this.getField("hitPoints").base;
|
||||
return 100*(currentHp/(currentHp - damage));
|
||||
},
|
||||
hpGreen: function(){
|
||||
var currentHp = this.attributeValue(this.attributes.hitPoints);
|
||||
var damage = this.attributes.hitPoints.base;
|
||||
var currentHp = this.attributeValue("hitPoints");
|
||||
var damage = this.getField("hitPoints").base;
|
||||
var maxHp = currentHp - damage;
|
||||
var percent = 100*(currentHp/ maxHp);
|
||||
var change = 100 * Template.instance().deltaHp.get() / maxHp;
|
||||
@@ -33,8 +34,8 @@ Template.hitPointBars.helpers({
|
||||
}
|
||||
},
|
||||
hpYellow: function(){
|
||||
var currentHp = this.attributeValue(this.attributes.hitPoints);
|
||||
var damage = this.attributes.hitPoints.base;
|
||||
var currentHp = this.attributeValue("hitPoints");
|
||||
var damage = this.getField("hitPoints").base;
|
||||
var maxHp = currentHp - damage;
|
||||
var percent = 100*(currentHp/ maxHp);
|
||||
var change = 100 * Template.instance().deltaHp.get() / maxHp;
|
||||
@@ -48,16 +49,16 @@ Template.hitPointBars.helpers({
|
||||
if(!Template.instance().deltaHp){
|
||||
Template.instance().deltaHp = new ReactiveVar(0);
|
||||
}
|
||||
var currentHp = this.attributeValue(this.attributes.hitPoints);
|
||||
var damage = this.attributes.hitPoints.base;
|
||||
var currentHp = this.attributeValue("hitPoints");
|
||||
var damage = this.getField("hitPoints").base;
|
||||
var maxHp = currentHp - damage;
|
||||
var percent = 100*(currentHp/ maxHp);
|
||||
var change = 100 * Template.instance().deltaHp.get() / maxHp;
|
||||
return percent + change;
|
||||
},
|
||||
maxHp: function(){
|
||||
var currentHp = this.attributeValue(this.attributes.hitPoints);
|
||||
var damage = this.attributes.hitPoints.base;
|
||||
var currentHp = this.attributeValue("hitPoints");
|
||||
var damage = this.getField("hitPoints").base;
|
||||
return currentHp - damage;
|
||||
},
|
||||
deltaHp: function(){
|
||||
@@ -81,8 +82,8 @@ Template.hitPointBars.events({
|
||||
"drag": function(event, templateInstance, handler){
|
||||
//the width of the bar, fetch dynamically if needed
|
||||
var healthBarWidth = 300;
|
||||
var hpLeft = this.attributeValue(this.attributes.hitPoints)
|
||||
var damage = this.attributes.hitPoints.base
|
||||
var hpLeft = this.attributeValue("hitPoints");
|
||||
var damage = this.getField("hitPoints").base;
|
||||
var maxHp = hpLeft - damage;
|
||||
var dragMultiplier = maxHp / healthBarWidth;
|
||||
var newValue = dragMultiplier * handler.deltaX + Template.instance().startDrag.get();
|
||||
@@ -98,7 +99,7 @@ Template.hitPointBars.events({
|
||||
"click .healthBarPlus": function(event){
|
||||
var newValue = Template.instance().deltaHp.get() + 1;
|
||||
//don't heal more than -damage
|
||||
var damage = this.attributes.hitPoints.base
|
||||
var damage = this.getField("hitPoints").base;
|
||||
newValue = newValue < -damage ? newValue : -damage;
|
||||
//set value
|
||||
Template.instance().deltaHp.set(newValue);
|
||||
@@ -106,13 +107,13 @@ Template.hitPointBars.events({
|
||||
"click .healthBarMinus": function(event){
|
||||
var newValue = Template.instance().deltaHp.get() - 1;
|
||||
//dont damage more than hit points left
|
||||
var hpLeft = this.attributeValue(this.attributes.hitPoints)
|
||||
var hpLeft = this.getField("hitPoints").base;
|
||||
newValue = newValue > -hpLeft ? newValue : -hpLeft;
|
||||
//set value
|
||||
Template.instance().deltaHp.set(newValue);
|
||||
},
|
||||
"click #applyDelta": function(event){
|
||||
Characters.update(this._id, {$inc: {"attributes.hitPoints.base": Template.instance().deltaHp.get()}})
|
||||
Characters.update(this._id, {$inc: {"hitPoints.base": Template.instance().deltaHp.get()}})
|
||||
Template.instance().deltaHp.set(0);
|
||||
}
|
||||
});
|
||||
@@ -126,22 +127,26 @@ Template.deadBar.events({
|
||||
|
||||
Template.deathSaves.helpers({
|
||||
deathFailGT: function(num){
|
||||
if(this.deathSave.fail > num) return "tickedDeathFail";
|
||||
var deathSave = this.getField("deathSave");
|
||||
if(deathSave.fail > num) return "tickedDeathFail";
|
||||
else return "untickedDeathFail";
|
||||
},
|
||||
deathPassGT: function(num){
|
||||
if(this.deathSave.pass > num) return "tickedDeathPass";
|
||||
var deathSave = this.getField("deathSave");
|
||||
if(deathSave.pass > num) return "tickedDeathPass";
|
||||
else return "untickedDeathPass";
|
||||
},
|
||||
stable: function(){
|
||||
if(this.deathSave.pass > 0 || this.deathSave.fail > 0){
|
||||
var deathSave = this.getField("deathSave");
|
||||
if(deathSave.pass > 0 || deathSave.fail > 0){
|
||||
return "stability";
|
||||
} else{
|
||||
return "heal";
|
||||
}
|
||||
},
|
||||
stabilizeText: function(){
|
||||
if(this.deathSave.pass > 0 || this.deathSave.fail > 0){
|
||||
var deathSave = this.getField("deathSave");
|
||||
if(deathSave.pass > 0 || deathSave.fail > 0){
|
||||
return "stabilize";
|
||||
} else{
|
||||
return "heal";
|
||||
|
||||
@@ -1,53 +1,55 @@
|
||||
Template.skills.helpers({
|
||||
saveList: function(){
|
||||
return [
|
||||
{name: "Strength", skill: this.skills.strengthSave},
|
||||
{name: "Dexterity", skill: this.skills.dexteritySave},
|
||||
{name: "Constitution", skill: this.skills.constitutionSave},
|
||||
{name: "Intelligence", skill: this.skills.intelligenceSave},
|
||||
{name: "Wisdom", skill: this.skills.wisdomSave},
|
||||
{name: "Charisma", skill: this.skills.charismaSave}
|
||||
return [
|
||||
{name: "Strength", skill: "strengthSave"},
|
||||
{name: "Dexterity", skill: "dexteritySave"},
|
||||
{name: "Constitution", skill: "constitutionSave"},
|
||||
{name: "Intelligence", skill: "intelligenceSave"},
|
||||
{name: "Wisdom", skill: "wisdomSave"},
|
||||
{name: "Charisma", skill: "charismaSave"}
|
||||
];
|
||||
},
|
||||
skillList: function(){
|
||||
return [
|
||||
{name: "Acrobatics", skill: this.skills.acrobatics},
|
||||
{name: "Animal Handling", skill: this.skills.animalHandling},
|
||||
{name: "Arcana", skill: this.skills.arcana},
|
||||
{name: "Athletics", skill: this.skills.athletics},
|
||||
{name: "Deception", skill: this.skills.deception},
|
||||
{name: "History", skill: this.skills.history},
|
||||
{name: "Insight", skill: this.skills.insight},
|
||||
{name: "Intimidation", skill: this.skills.intimidation},
|
||||
{name: "Investigation", skill: this.skills.investigation},
|
||||
{name: "Medicine", skill: this.skills.medicine},
|
||||
{name: "Nature", skill: this.skills.nature},
|
||||
{name: "Perception", skill: this.skills.perception},
|
||||
{name: "Performance", skill: this.skills.performance},
|
||||
{name: "Persuasion", skill: this.skills.persuasion},
|
||||
{name: "Religion", skill: this.skills.religion},
|
||||
{name: "Sleight of Hand", skill: this.skills.sleightOfHand},
|
||||
{name: "Stealth", skill: this.skills.stealth},
|
||||
{name: "Survival", skill: this.skills.survival}
|
||||
{name: "Acrobatics", skill: "acrobatics"},
|
||||
{name: "Animal Handling", skill: "animalHandling"},
|
||||
{name: "Arcana", skill: "arcana"},
|
||||
{name: "Athletics", skill: "athletics"},
|
||||
{name: "Deception", skill: "deception"},
|
||||
{name: "History", skill: "history"},
|
||||
{name: "Insight", skill: "insight"},
|
||||
{name: "Intimidation", skill: "intimidation"},
|
||||
{name: "Investigation", skill: "investigation"},
|
||||
{name: "Medicine", skill: "medicine"},
|
||||
{name: "Nature", skill: "nature"},
|
||||
{name: "Perception", skill: "perception"},
|
||||
{name: "Performance", skill: "performance"},
|
||||
{name: "Persuasion", skill: "persuasion"},
|
||||
{name: "Religion", skill: "religion"},
|
||||
{name: "Sleight of Hand", skill: "sleightOfHand"},
|
||||
{name: "Stealth", skill: "stealth"},
|
||||
{name: "Survival", skill: "survival"}
|
||||
];
|
||||
},
|
||||
profIcon: function(skill){
|
||||
var prof = Template.parentData(1).proficiency(skill);
|
||||
var prof = Template.parentData(1).proficiency(this.skill);
|
||||
if(prof > 0 && prof < 1) return "profHalf.png";
|
||||
if(prof === 1) return "profSingle.png";
|
||||
if(prof > 1) return "profDouble.png";
|
||||
return "profNone.png";
|
||||
},
|
||||
failSkill: function(){
|
||||
return this.skill.fail.length > 0;
|
||||
return Template.parentData(1).getField(this.skill).fail.length > 0;
|
||||
},
|
||||
advantage: function(){
|
||||
var adv = this.skill.advantage.length;
|
||||
var disadv = this.skill.disadvantage.length;
|
||||
var adv = Template.parentData(1).getField(this.skill).advantage.length;
|
||||
var disadv = Template.parentData(1).getField(this.skill).disadvantage.length;
|
||||
if(adv > 0 && disadv === 0) return "advantage";
|
||||
if(disadv > 0 && adv === 0) return "disadvantage";
|
||||
},
|
||||
conditionals: function(){
|
||||
if(this.skill.conditional.length > 0) return "conditionals";
|
||||
if(Template.parentData(1).getField(this.skill).conditional.length > 0){
|
||||
return "conditionals";
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -8,12 +8,12 @@ Template.textField.helpers({
|
||||
return Template.instance().editing.get();
|
||||
},
|
||||
input: function(){
|
||||
var text = this.character.strings[this.field];
|
||||
var text = this.character.getField(this.field);
|
||||
if (_.isString(text)) return Spacebars.SafeString(text);
|
||||
return text;
|
||||
},
|
||||
output: function(){
|
||||
var html = evaluateString(this.character, this.character.strings[this.field]);
|
||||
var html = evaluateString(this.character._id, this.character.getField(this.field));
|
||||
if (_.isString(html)) return Spacebars.SafeString(html);
|
||||
return html;
|
||||
},
|
||||
@@ -33,7 +33,7 @@ Template.textField.events({
|
||||
if(!_.isString(text)) text = "";
|
||||
//TODO sanitise the html
|
||||
var setter = {};
|
||||
setter["strings."+this.field] = text;
|
||||
setter[this.field] = text;
|
||||
Characters.update(this.character._id, {$set: setter}, function(error, result) {
|
||||
if(error) console.log(error);
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{>loginButtons}}
|
||||
<div>
|
||||
{{# each characters}}
|
||||
<li><a href="{{ pathFor 'character' }} ">{{_id}}</a> <button class="deleteChar">delete</button></li>
|
||||
<li><a href="{{ pathFor 'character' }} ">{{_id}}</a> <button id="deleteChar">delete</button></li>
|
||||
{{/each}}
|
||||
</div>
|
||||
<input id="addCharacter" type="button" value="Add Character">
|
||||
|
||||
@@ -2,7 +2,8 @@ Template.home.events({
|
||||
"click #addCharacter": function (event, template) {
|
||||
Characters.insert({});
|
||||
},
|
||||
"click .delete": function(event, template){
|
||||
"click #deleteChar": function(event, template){
|
||||
console.log("deleting", this);
|
||||
Characters.remove(this._id);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user