Multiple instances of the same proficiency are now merged

For tool/language/weapon/armour proficiencies, on the stats/persona page.
This commit is contained in:
Jacob
2017-07-18 22:33:28 +01:00
parent 11adf9da04
commit 1f0ea689dc
3 changed files with 47 additions and 7 deletions

View File

@@ -55,19 +55,19 @@
Proficiencies Proficiencies
</div> </div>
<div flex class="bottom list"> <div flex class="bottom list">
{{#if weaponProfs.count}} {{#if weaponProfs.length}}
<div class="paper-font-subhead">Weapons</div> <div class="paper-font-subhead">Weapons</div>
{{/if}} {{/if}}
{{#each weaponProfs}} {{#each weaponProfs}}
{{> proficiencyListItem}} {{> proficiencyListItem}}
{{/each}} {{/each}}
{{#if armorProfs.count}} {{#if armorProfs.length}}
<div class="paper-font-subhead">Armor</div> <div class="paper-font-subhead">Armor</div>
{{/if}} {{/if}}
{{#each armorProfs}} {{#each armorProfs}}
{{> proficiencyListItem}} {{> proficiencyListItem}}
{{/each}} {{/each}}
{{#if toolProfs.count}} {{#if toolProfs.length}}
<div class="paper-font-subhead">Tools</div> <div class="paper-font-subhead">Tools</div>
{{/if}} {{/if}}
{{#each toolProfs}} {{#each toolProfs}}

View File

@@ -1,3 +1,21 @@
var removeDuplicateProficiencies = function(proficiencies) {
dict = {};
proficiencies.forEach(function(prof) {
if (prof.name in dict) { //if we have already gone over another proficiency for the same thing
if (dict[prof.name].value < prof.value) {
dict[prof.name] = prof; //then take the new one if it's higher, otherwise leave it
}
} else {
dict[prof.name] = prof; //if it wasn't already there, store it
}
});
profs = []
_.forEach(dict, function(prof) {
profs.push(prof);
})
return profs;
};
Template.features.helpers({ Template.features.helpers({
features: function(){ features: function(){
var features = Features.find({charId: this._id}, {sort: {color: 1, name: 1}}); var features = Features.find({charId: this._id}, {sort: {color: 1, name: 1}});
@@ -27,13 +45,16 @@ Template.features.helpers({
return !this.alwaysEnabled; return !this.alwaysEnabled;
}, },
weaponProfs: function(){ weaponProfs: function(){
return Proficiencies.find({charId: this._id, type: "weapon"}); var profs = Proficiencies.find({charId: this._id, type: "weapon"});
return removeDuplicateProficiencies(profs);
}, },
armorProfs: function(){ armorProfs: function(){
return Proficiencies.find({charId: this._id, type: "armor"}); var profs = Proficiencies.find({charId: this._id, type: "armor"});
return removeDuplicateProficiencies(profs);
}, },
toolProfs: function(){ toolProfs: function(){
return Proficiencies.find({charId: this._id, type: "tool"}); var profs = Proficiencies.find({charId: this._id, type: "tool"});
return removeDuplicateProficiencies(profs);
}, },
}); });

View File

@@ -7,6 +7,24 @@ var colorMap = {
backstory: "j", backstory: "j",
}; };
var removeDuplicateProficiencies = function(proficiencies) {
dict = {};
proficiencies.forEach(function(prof) {
if (prof.name in dict) { //if we have already gone over another proficiency for the same thing
if (dict[prof.name].value < prof.value) {
dict[prof.name] = prof; //then take the new one if it's higher, otherwise leave it
}
} else {
dict[prof.name] = prof; //if it wasn't already there, store it
}
});
profs = []
_.forEach(dict, function(prof) {
profs.push(prof);
})
return profs;
};
Template.persona.helpers({ Template.persona.helpers({
characterDetails: function(){ characterDetails: function(){
var char = Characters.findOne( var char = Characters.findOne(
@@ -33,7 +51,8 @@ Template.persona.helpers({
}; };
}, },
languages: function(){ languages: function(){
return Proficiencies.find({charId: this._id, type: "language"}); var profs = Proficiencies.find({charId: this._id, type: "language"});
return removeDuplicateProficiencies(profs);
}, },
}); });