Made proficiencies their own objects, added migration functionality

This commit is contained in:
Thaum
2015-04-17 13:56:52 +00:00
parent 245867dae6
commit b76ac23713
20 changed files with 331 additions and 17 deletions

View File

@@ -18,3 +18,4 @@ zimme:collection-softremovable
momentjs:moment
mike:mocha
dburles:mongo-collection-instances
percolate:migrations

View File

@@ -55,6 +55,7 @@ mongo@1.1.0
npm-bcrypt@0.7.8_2
observe-sequence@1.0.6
ordered-dict@1.0.3
percolate:migrations@0.7.3
practicalmeteor:chai@1.9.2_3
practicalmeteor:loglevel@1.1.0_3
random@1.0.3

View File

@@ -13,7 +13,6 @@ Schemas.Character = new SimpleSchema({
bonds: { type: String, defaultValue: "", trim: false},
flaws: { type: String, defaultValue: "", trim: false},
backstory: { type: String, defaultValue: "", trim: false},
proficiencies:{ type: String, defaultValue: "", trim: false},
languages: { type: String, defaultValue: "", trim: false},
//attributes
@@ -182,7 +181,7 @@ var attributeBase = function(charId, statName){
//start with the highest base value
_.each(effects.base, function(effect){
var efv = evaluateEffect(charId, effect)
var efv = evaluateEffect(charId, effect);
if (efv > value){
value = efv;
}
@@ -210,7 +209,7 @@ var attributeBase = function(charId, statName){
value = value < max? value : max;
});
return value;
}
};
//functions and calculated values.
//These functions can only rely on this._id since no other
@@ -302,12 +301,10 @@ Characters.helpers({
var charId = this._id;
//return largest value in proficiency array
var prof = 0;
Effects.find({charId: charId, stat: skillName, enabled: true}).forEach(function(effect){
if(effect.operation === "proficiency"){
var newProf = evaluateEffect(charId, effect);
if (newProf > prof){
prof = newProf;
}
Proficiencies.find({charId: charId, name: skillName, enabled: true}).forEach(function(proficiency){
var newProf = proficiency.value;
if (newProf > prof){
prof = newProf;
}
});
return prof;
@@ -317,7 +314,7 @@ Characters.helpers({
if (_.isString(skillName)){
var skill = this.getField(skillName);
}
var charId = this._id
var charId = this._id;
var mod = +this.skillMod(skillName);
var value = 10 + mod;
Effects.find({charId: charId, stat: skillName, enabled: true, operation: "passiveAdd"}).forEach(function(effect){
@@ -328,7 +325,7 @@ Characters.helpers({
},
advantage: function(skillName){
var charId = this._id
var charId = this._id;
var advantage = Effects.find({charId: charId, stat: skillName, enabled: true, operation: "advantage"}).count();
var disadvantage = Effects.find({charId: charId, stat: skillName, enabled: true, operation: "disadvantage"}).count();
if(advantage && !disadvantage) return 1;

View File

@@ -7,12 +7,24 @@ Schemas.Proficiency = new SimpleSchema({
},
name: {
type: String,
trim: false
trim: false,
optional: true,
},
value: {
type: Number,
allowedValues: [0, 0.5, 1],
allowedValues: [0, 0.5, 1, 2],
defaultValue: 1,
decimal: true,
},
type: {
type: String,
allowedValues: ["skill", "save", "weapon", "armor", "tool", "language"],
defaultValue: "skill",
},
enabled: {
type: Boolean,
defaultValue: true,
}
});
Proficiencies.attachSchema(Schemas.Proficiency);

View File

@@ -1,7 +1,7 @@
<!--needs to be given charId, parentId and parentCollection-->
<template name="effectsEditList">
{{#if effects.count}}
<hr style="margin: 16px 0 16px 0;">
<hr class="vertMargin">
<div id="effects">
<h2>Effects</h2>
{{#each effects}}

View File

@@ -38,6 +38,7 @@
{{/if}}
{{> effectsViewList charId=charId parentId=_id}}
{{> proficiencyViewList charId=charId parentId=_id}}
</template>
<template name="featureEdit">
@@ -82,4 +83,5 @@
</paper-input-decorator>
{{> effectsEditList parentId=_id parentCollection="Features" charId=charId name=name enabled=enabled}}
{{> proficiencyEditList parentId=_id parentCollection="Features" charId=charId enabled=enabled}}
</template>

View File

@@ -7,6 +7,7 @@
<paper-input id="levelValueInput" label="Level" floatinglabel value={{level}}></paper-input>
<!--Effects-->
{{> effectsEditList parentId=_id parentCollection="Classes" charId=charId}}
{{> proficiencyEditList parentId=_id parentCollection="Characters" charId=charId}}
{{/baseDialog}}
{{/with}}
</template>

View File

@@ -2,5 +2,6 @@
{{#baseDialog title="Race" class=colorClass hideColor="true" hideDelete="true"}}
<paper-input id="raceInput" label="Race" floatinglabel value={{race}}></paper-input>
{{> effectsEditList parentId=charId parentCollection="Characters" charId=charId}}
{{> proficiencyEditList parentId=charId parentCollection="Characters" charId=charId}}
{{/baseDialog}}
</template>

View File

@@ -0,0 +1,43 @@
<template name="proficiencyEdit">
<div layout horizontal around-justified>
<paper-dropdown-menu class="typeDropDown" label="Stat Group" flex>
<paper-dropdown layered class="dropdown">
<core-menu class="menu typeMenu" selected={{type}}>
{{#each proficiencyTypes}}
<paper-item class="statGroupSelect" name={{type}}>{{name}}</paper-item>
{{/each}}
</core-menu>
</paper-dropdown>
</paper-dropdown-menu>
{{> UI.dynamic template=nameInputTemplate}}
<paper-dropdown-menu class="valueDropDown" label="Proficiency" flex>
<paper-dropdown layered class="dropdown">
<core-menu class="menu valueMenu" selected={{value}}>
<paper-item name="1">Proficient</paper-item>
<paper-item name="0.5">Half Prof. Bonus</paper-item>
<paper-item name="2">Double Prof. Bonus</paper-item>
</core-menu>
</paper-dropdown>
</paper-dropdown-menu>
</div>
</template>
<template name="nameDropdown">
<paper-dropdown-menu class="nameDropDown sideMargin" label="Proficiency" flex>
<paper-dropdown layered class="dropdown">
<core-menu class="menu nameMenu" selected={{name}}>
{{#each nameDropdownItems}}
<paper-item name={{stat}}>{{name}}</paper-item>
{{/each}}
</core-menu>
</paper-dropdown>
</paper-dropdown-menu>
</template>
<template name="nameInput sideMargin">
<paper-input class="nameInput"
label="Name"
floatinglabel
value={{name}}
flex></paper-input>
</template>

View File

@@ -0,0 +1,86 @@
var profTypes = [
{type: "skill", name: "Skill"},
{type: "save", name: "Saving Throw"},
{type: "weapon", name: "Weapon"},
{type: "armor", name: "Armor"},
{type: "tool", name: "Tool"},
{type: "language", name: "Language"}
];
var saves = [
{name: "Strength Save", stat: "strengthSave"},
{name: "Dexterity Save", stat: "dexteritySave"},
{name: "Constitution Save", stat: "constitutionSave"},
{name: "Intelligence Save", stat: "intelligenceSave"},
{name: "Wisdom Save", stat: "wisdomSave"},
{name: "Charisma Save", stat: "charismaSave"},
];
var skills = [
{name: "Acrobatics", stat: "acrobatics"},
{name: "Animal Handling", stat: "animalHandling"},
{name: "Arcana", stat: "arcana"},
{name: "Athletics", stat: "athletics"},
{name: "Deception", stat: "deception"},
{name: "History", stat: "history"},
{name: "Insight", stat: "insight"},
{name: "Intimidation", stat: "intimidation"},
{name: "Investigation", stat: "investigation"},
{name: "Medicine", stat: "medicine"},
{name: "Nature", stat: "nature"},
{name: "Perception", stat: "perception"},
{name: "Performance", stat: "performance"},
{name: "Persuasion", stat: "persuasion"},
{name: "Religion", stat: "religion"},
{name: "Sleight of Hand", stat: "sleightOfHand"},
{name: "Stealth", stat: "stealth"},
{name: "Survival", stat: "survival"},
{name: "Initiative", stat: "initiative"},
];
Template.proficiencyEdit.helpers({
proficiencyTypes: function(){
return profTypes;
},
nameInputTemplate: function(){
if(!this.type) return null;
if(this.type === "skill"||
this.type === "save") return "nameDropdown";
return "nameInput";
}
});
Template.proficiencyEdit.events({
"core-select .typeDropDown": function(event){
var detail = event.originalEvent.detail;
if(!detail.isSelected) return;
var type = detail.item.getAttribute("name");
if (type == this.type) return;
Proficiencies.update(this._id, {$set: {type: type}});
},
"core-select .valueDropDown": function(event){
var detail = event.originalEvent.detail;
if(!detail.isSelected) return;
var value = +detail.item.getAttribute("name");
if (value == this.value) return;
Proficiencies.update(this._id, {$set: {value: value}});
},
"core-select .nameDropDown": function(event){
var detail = event.originalEvent.detail;
if(!detail.isSelected) return;
var name = detail.item.getAttribute("name");
if (name == this.name) return;
Proficiencies.update(this._id, {$set: {name: name}});
},
"change .nameInput": function(event){
var name = event.currentTarget.value;
Proficiencies.update(this._id, {$set: {name: name}});
}
});
Template.nameDropdown.helpers({
nameDropdownItems: function(){
if (this.type === "skill") return skills;
if (this.type === "save") return saves;
}
});

View File

@@ -0,0 +1,18 @@
<!--needs to be given charId, parentId and parentCollection-->
<template name="proficiencyEditList">
{{#if proficiencies.count}}
<hr class="vertMargin">
<div id="proficiencies">
<h2>Proficiencies</h2>
{{#each proficiencies}}
{{>proficiencyEdit}}
{{/each}}
</div>
{{/if}}
<paper-button id="addProficiencyButton"
class="red-button"
raised>
Add Proficiency
</paper-button>
</template>

View File

@@ -0,0 +1,24 @@
Template.proficiencyEditList.helpers({
proficiencies: function(){
var cursor = Proficiencies.find({"parent.id": this.parentId, "parent.collection": this.parentCollection});
return cursor;
}
});
Template.proficiencyEditList.events({
"tap #addProficiencyButton": function(){
if ( !_.isBoolean(this.enabled) ) {
this.enabled = true;
}
Proficiencies.insert({
charId: this.charId,
parent: {
id: this.parentId,
collection: this.parentCollection
},
enabled: this.enabled,
value: 1,
type: "skill",
});
},
});

View File

@@ -0,0 +1,6 @@
<template name="proficiencyView">
<div class="proficiencyView" layout horizontal center>
<core-icon icon="{{profIcon}}"></core-icon>
<div class="sideMargin">{{getName}}</div>
</div>
</template>

View File

@@ -0,0 +1,45 @@
var saves = {
strengthSave: "Strength Save",
dexteritySave: "Dexterity Save",
constitutionSave: "Constitution Save",
intelligenceSave: "Intelligence Save",
wisdomSave: "Wisdom Save",
charismaSave: "Charisma Save",
};
var skills = {
acrobatics: "Acrobatics",
animalHandling: "Animal Handling",
arcana: "Arcana",
athletics: "Athletics",
deception: "Deception",
history: "History",
insight: "Insight",
intimidation: "Intimidation",
investigation: "Investigation",
medicine: "Medicine",
nature: "Nature",
perception: "Perception",
performance: "Performance",
persuasion: "Persuasion",
religion: "Religion",
sleightOfHand: "Sleight of Hand",
stealth: "Stealth",
survival: "Survival",
initiative: "Initiative",
};
Template.proficiencyView.helpers({
profIcon: function(){
var prof = this.value;
if(prof > 0 && prof < 1) return "image:brightness-2";
if(prof === 1) return "image:brightness-1";
if(prof > 1) return "av:album";
return "radio-button-off";
},
getName: function(){
if(this.type === "skill") return skills[this.name];
if(this.type === "save") return saves[this.name];
return this.name;
}
});

View File

@@ -0,0 +1,11 @@
<template name="proficiencyViewList">
{{#if proficiencies.count}}
<hr class="vertMargin">
<div class="proficiencies">
<h2 class="spaceAfter">Proficiencies</h2>
{{#each proficiencies}}
{{> proficiencyView}}
{{/each}}
</div>
{{/if}}
</template>

View File

@@ -0,0 +1,5 @@
Template.proficiencyViewList.helpers({
proficiencies: function(){
return Proficiencies.find({"parent.id": this.parentId, charId: this.charId});
}
});

View File

@@ -0,0 +1,8 @@
SAVES = [
"strengthSave",
"dexteritySave",
"constitutionSave",
"intelligenceSave",
"wisdomSave",
"charismaSave",
];

View File

@@ -0,0 +1,21 @@
SKILLS = [
"acrobatics",
"animalHandling",
"arcana",
"athletics",
"deception",
"history",
"insight",
"intimidation",
"investigation",
"medicine",
"nature",
"perception",
"performance",
"persuasion",
"religion",
"sleightOfHand",
"stealth",
"survival",
"initiative",
];

View File

@@ -0,0 +1,31 @@
Migrations.add({
version: 1,
up: function() {
return;
}
});
Migrations.add({
version: 2,
name: "converts effect proficiencies to proficiency objects",
up: function() {
Effects.find({operation: "proficiency"}).forEach(function(effect){
var type;
if(_.contains(SKILLS, effect.stat)) type = "skill";
if(_.contains(SAVES, effect.stat)) type = "save";
if(!type) throw "stat not a skill or a save";
Proficiencies.insert({
charId: effect.charId,
name: effect.stat,
value: effect.value,
parent: effect.parent,
type: type,
enabled: effect.enabled
});
Effects.remove(effect._id);
});
},
down: function(){
return;
}
});

View File

@@ -3,9 +3,9 @@ Meteor.publish("singleCharacter", function(characterId, userId){
Characters.findOne({
_id: characterId,
$or: [
{readers: userId},
{writers: userId},
{owner: userId}
{readers: userId},
{writers: userId},
{owner: userId}
]
})
){
@@ -24,6 +24,7 @@ Meteor.publish("singleCharacter", function(characterId, userId){
Spells.find ({charId: characterId}, {removed: true}),
SpellLists.find ({charId: characterId}, {removed: true}),
TemporaryHitPoints.find({charId: characterId}, {removed: true}),
Proficiencies.find ({charId: characterId}, {removed: true}),
];
}
});