Changed how levels are handled

This commit is contained in:
Thaum
2015-03-02 19:38:53 +00:00
parent 80d44ff310
commit 88dbaccfc5
14 changed files with 110 additions and 66 deletions

View File

@@ -434,7 +434,7 @@ Characters.helpers({
return 10 + mod; return 10 + mod;
}, },
level: function(){ xpLevel: function(){
var xp = this.experience(); var xp = this.experience();
var xpTable = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000, var xpTable = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000,
85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000, 85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000,
@@ -448,6 +448,14 @@ Characters.helpers({
return 0; return 0;
}, },
level: function(){
var level = 0;
Classes.find({charId: this._id}).forEach(function(cls){
level += cls.level;
})
return level;
},
experience: function(){ experience: function(){
var xp = 0; var xp = 0;
Experiences.find({charId: this._id}, {fields: {value: 1}}).forEach(function(e){ Experiences.find({charId: this._id}, {fields: {value: 1}}).forEach(function(e){

View File

@@ -3,6 +3,7 @@ Classes = new Meteor.Collection("classes");
Schemas.Class = new SimpleSchema({ Schemas.Class = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id}, charId: {type: String, regEx: SimpleSchema.RegEx.Id},
name: {type: String, trim: false}, name: {type: String, trim: false},
level: {type: Number},
createdAt: { createdAt: {
type: Date, type: Date,
autoValue: function() { autoValue: function() {
@@ -15,6 +16,7 @@ Schemas.Class = new SimpleSchema({
} }
} }
}, },
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
}); });
Classes.attachSchema(Schemas.Class); Classes.attachSchema(Schemas.Class);

View File

@@ -33,7 +33,7 @@ Schemas.Effect = new SimpleSchema({
type: { type: {
type: String, type: String,
defaultValue: "editable", defaultValue: "editable",
allowedValues: ["editable", "feature", "level", "buff", "equipment", "racial", "inate"] allowedValues: ["editable", "feature", "class", "buff", "equipment", "racial", "inate"]
}, },
//the id of the feature, buff or item that created this effect //the id of the feature, buff or item that created this effect
sourceId: { sourceId: {

View File

@@ -1,9 +0,0 @@
Levels = new Meteor.Collection("levels");
Schemas.Level = new SimpleSchema({
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
classId: {type: String, regEx: SimpleSchema.RegEx.Id},
value: {type: Number}
});
Levels.attachSchema(Schemas.Level);

View File

@@ -45,7 +45,7 @@
<!--Proficiencies--> <!--Proficiencies-->
<paper-shadow class="card container" hero-id="main" {{detailHero "proficiencies"}}> <paper-shadow class="card container" hero-id="main" {{detailHero "proficiencies"}}>
<div id="proficiencies" <div id="proficiencies"
class="containerTop grey white-text" class="whiteTop"
hero-id="toolbar" hero-id="toolbar"
layout horizontal center layout horizontal center
{{detailHero "proficiencies"}}> {{detailHero "proficiencies"}}>

View File

@@ -0,0 +1,12 @@
<template name="classDialog">
{{#with class}}
{{#baseDialog title=name class=colorClass hideColor="true"}}
<!--Name-->
<paper-input id="classNameInput" label="Class Name" floatinglabel value={{name}}></paper-input>
<!--Level-->
<paper-input id="levelValueInput" label="Level" floatinglabel value={{level}}></paper-input>
<!--Effects-->
{{> effectsEditList sourceId=_id charId=charId type="class"}}
{{/baseDialog}}
{{/with}}
</template>

View File

@@ -0,0 +1,20 @@
Template.classDialog.events({
"tap #deleteButton": function(event, instance){
Classes.remove(instance.data.classId);
GlobalUI.closeDetail()
},
"change #classNameInput": function(event){
var value = event.currentTarget.value;
Classes.update(this._id, {$set: {name: value}});
},
"change #levelValueInput": function(event){
var value = event.currentTarget.value;
Classes.update(this._id, {$set: {level: value}});
}
});
Template.classDialog.helpers({
class: function(){
return Classes.findOne(this.classId);
}
});

View File

@@ -2,10 +2,12 @@
<div fit> <div fit>
<div id="journal" class="scroll-y" fit> <div id="journal" class="scroll-y" fit>
<div class="containers"> <div class="containers">
<!--Experience Table-->
<paper-shadow class="card container experiencesCard" hero-id="main" {{detailHero}}> <paper-shadow class="card container experiencesCard" hero-id="main" {{detailHero}}>
<div class="containerTop {{colorClass}}" hero-id="toolbar" layout horizontal center {{detailHero}}> <div class="whiteTop" hero-id="toolbar" layout horizontal center {{detailHero}}>
<div class="containerName subhead" flex>Experience</div> <div class="containerName subhead" flex>Experience</div>
<div class="subhead">{{experience}} XP</div> <div class="subhead">{{experience}} XP</div>
<paper-icon-button class="black54" id="addXP" icon="add"></paper-icon-button>
</div> </div>
<div class="containerMain experiences"> <div class="containerMain experiences">
{{#each experiences}} {{#each experiences}}
@@ -23,35 +25,35 @@
</div> </div>
{{/if}} {{/if}}
</paper-shadow> </paper-shadow>
<!--Class Table-->
<paper-shadow class="card container" hero-id="main" {{detailHero}}> <paper-shadow class="card container" hero-id="main" {{detailHero}}>
<div class="containerTop {{colorClass}}" hero-id="toolbar" layout horizontal center {{detailHero}}> <div class="whiteTop" hero-id="toolbar" layout horizontal center {{detailHero}}>
<div flex> <div flex>
<div class="containerName subhead">Levels</div> <div class="containerName subhead">Level {{level}}</div>
{{#if nextLevelXP}}
<div class="caption">
Next Level: {{nextLevelXP}}XP
</div>
{{/if}}
</div> </div>
<paper-icon-button class="black54" id="addClassButton" icon="add"></paper-icon-button>
</div> </div>
<div class="containerMain experiences"> <div class="containerMain experiences">
<div class="list-subhead" layout horizontal center>
Race
</div>
<div class="itemSlot"> <div class="itemSlot">
<paper-item class="inventoryItem race" hero-id="main" {{detailHero "race"}} layout horizontal> <paper-item class="inventoryItem race" hero-id="main" {{detailHero "race"}} layout horizontal>
{{race}} {{race}}
</paper-item> </paper-item>
</div> </div>
{{#each classes}} {{#each classes}}
<div class="list-subhead" layout horizontal center> <div class="itemSlot">
{{name}} <paper-item class="inventoryItem class" hero-id="main" {{detailHero}} layout horizontal>
{{name}}&nbsp;{{level}}
</paper-item>
</div> </div>
{{#each levels ../_id}}
<div class="itemSlot">
<paper-item class="inventoryItem level" hero-id="main" {{detailHero}} layout horizontal>
Level {{value}}
</paper-item>
</div>
{{/each}}
{{/each}} {{/each}}
</div> </div>
</paper-shadow> </paper-shadow>
<!--Notes-->
{{#each notes}} {{#each notes}}
<paper-shadow class="card container" hero-id="main" {{detailHero}}> <paper-shadow class="card container" hero-id="main" {{detailHero}}>
<div class="containerTop {{colorClass}} noteTop" hero-id="toolbar" layout horizontal center {{detailHero}}> <div class="containerTop {{colorClass}} noteTop" hero-id="toolbar" layout horizontal center {{detailHero}}>
@@ -66,8 +68,11 @@
<div class="fab-buffer"></div> <div class="fab-buffer"></div>
</div> </div>
</div> </div>
<paper-fab-menu id="inventoryAddMenu" icon="add" closeIcon="close" duration="0.3"> <paper-fab id="addNote"
<paper-fab-menu-item id="addNote" icon="note-add" color="#d23f31" tooltip="Note"></paper-fab-menu-item> class="floatyButton"
<paper-fab-menu-item id="addXP" icon="work" color="#d23f31" tooltip="Experience"></paper-fab-menu-item> icon="add"
</paper-fab-menu> title="Add"
role="button"
tabindex="0"
hero-id="main"></paper-fab>
</template> </template>

View File

@@ -26,6 +26,12 @@ Template.journal.helpers({
levels: function(charId){ levels: function(charId){
return Levels.find({charId: charId, classId: this._id}, {sort: {value: 1}}); return Levels.find({charId: charId, classId: this._id}, {sort: {value: 1}});
}, },
nextLevelXP: function(){
var currentLevel = this.level();
if (currentLevel < 20){
return xpTable[currentLevel];
}
},
race: function(){ race: function(){
var char = Characters.findOne(this._id, {fields: {race: 1}}); var char = Characters.findOne(this._id, {fields: {race: 1}});
return char && char.race; return char && char.race;
@@ -47,10 +53,10 @@ Template.journal.events({
heroId: this._id heroId: this._id
}); });
}, },
"tap .level": function(event){ "tap .class": function(event){
GlobalUI.setDetail({ GlobalUI.setDetail({
template: "levelDialog", template: "classDialog",
data: {levelId: this._id, charId: this.charId}, data: {classId: this._id, charId: this.charId},
heroId: this._id heroId: this._id
}); });
}, },
@@ -90,6 +96,22 @@ Template.journal.events({
} }
}) })
}, },
"tap #addClassButton":function(event){
var charId = this._id;
Classes.insert({
charId: charId,
name: "new Class",
level: 1
}, function(error, id){
if(!error){
GlobalUI.setDetail({
template: "classDialog",
data: {classId: id, charId: charId},
heroId: id
});
}
})
},
"tap #moreExperiences": function(event){ "tap #moreExperiences": function(event){
var inst = Template.instance(); var inst = Template.instance();
inst.experiencesLimit.set(inst.experiencesLimit.get() + (this.settings && this.settings.experiencesInc || 10)); inst.experiencesLimit.set(inst.experiencesLimit.get() + (this.settings && this.settings.experiencesInc || 10));

View File

@@ -1,10 +0,0 @@
<template name="levelDialog">
{{#with level}}
{{#baseDialog title=name class=colorClass hideColor="true"}}
<!--Level-->
<paper-input id="levelValueInput" label="Level" floatinglabel value={{value}}></paper-input>
<!--Effects-->
{{> effectsEditList sourceId=_id charId=charId type="level"}}
{{/baseDialog}}
{{/with}}
</template>

View File

@@ -1,16 +0,0 @@
Template.levelDialog.events({
"tap #deleteButton": function(event, instance){
Levels.remove(instance.data.levelId);
GlobalUI.closeDetail()
},
"change #levelValueInput": function(event){
var value = event.currentTarget.value;
Levels.update(this._id, {$set: {value: value}});
}
});
Template.levelDialog.helpers({
level: function(){
return Levels.findOne(this.levelId);
}
});

View File

@@ -0,0 +1,3 @@
xpTable = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000,
85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000,
305000, 355000];

View File

@@ -2,18 +2,26 @@
evaluate = function(charId, string){ evaluate = function(charId, string){
if(!string) return string; if(!string) return string;
var char = Characters.findOne(charId, {fields: {_id: 1}}); var char = Characters.findOne(charId, {fields: {_id: 1}});
string = string.replace(/\b[a-zA-Z]+\b/g, function(sub){ string = string.replace(/\b[a-z]+\b/gi, function(sub){
//fields //fields
if(Schemas.Character.schema(sub)){ if(Schemas.Character.schema(sub)){
return char.fieldValue(sub) return char.fieldValue(sub)
} }
//ability modifiers //ability modifiers
var abilityMods = ["strengthMod", "dexterityMod", "constitutionMod", "intelligenceMod", "wisdomMod", "charismaMod"] var abilityMods = ["STRENGTHMOD", "DEXTERITYMOD", "CONSTITUTIONMOD", "INTELLIGENCEMOD", "WISDOMMOD", "CHARISMAMOD"]
if( _.contains(abilityMods, sub) ){ if( _.contains(abilityMods, sub.toUpperCase()) ){
var slice = sub.slice(0, - 3); var slice = sub.slice(0, - 3);
return char.abilityMod(slice); return char.abilityMod(slice);
} }
if(sub === "level"){ //class levels
if(/\w+levels?\b/gi.test(sub)){
//strip out "level"
var className = sub.replace(/levels?\b/gi, "");
var cls = Classes.findOne({charId: charId, name: className});
return cls && cls.level;
}
//character level
if(sub.toUpperCase() === "LEVEL"){
return char.level(); return char.level();
} }
return sub; return sub;

View File

@@ -11,7 +11,6 @@ Meteor.publish("singleCharacter", function(characterId, userId){
Experiences.find({charId: characterId}), Experiences.find({charId: characterId}),
Features.find({charId: characterId}), Features.find({charId: characterId}),
Items.find({charId: characterId}), Items.find({charId: characterId}),
Levels.find({charId: characterId}),
Notes.find({charId: characterId}), Notes.find({charId: characterId}),
Spells.find({charId: characterId}), Spells.find({charId: characterId}),
SpellLists.find({charId: characterId}), SpellLists.find({charId: characterId}),