Began implementing features that change stats
This commit is contained in:
@@ -1,14 +1,5 @@
|
||||
//set up the collection for characters
|
||||
Characters = new Meteor.Collection("characters", {
|
||||
//transform function alters the object returned by the database
|
||||
transform: function (doc) {
|
||||
//extend character with its protoypal functions
|
||||
var newInstance = Object.create(protoCharacter);
|
||||
doc = _.extend(newInstance, doc);
|
||||
|
||||
return doc;
|
||||
}
|
||||
});
|
||||
Characters = new Meteor.Collection("characters");
|
||||
|
||||
var attributes = [
|
||||
{name: "strength"},
|
||||
@@ -100,6 +91,7 @@ var strings = [
|
||||
"alignment",
|
||||
"gender",
|
||||
"race",
|
||||
"class",
|
||||
"description",
|
||||
"personality",
|
||||
"ideals",
|
||||
@@ -132,18 +124,20 @@ Character = function(owner){
|
||||
success : 0,
|
||||
fail: 0
|
||||
};
|
||||
|
||||
this.hitDice = [];
|
||||
|
||||
|
||||
this.weaponProficiencies = [];
|
||||
this.toolProficiencies = [];
|
||||
this.languages = [];
|
||||
|
||||
/*
|
||||
//anything that needs to be edited rather than added or removed
|
||||
//needs its own collection.
|
||||
this.hitDice = [];
|
||||
|
||||
this.features = [];
|
||||
|
||||
this.spells = [];
|
||||
|
||||
this.classes = [];
|
||||
*/
|
||||
|
||||
this.vulnerability = {};
|
||||
for(var i = 0, l = DamageTypes.length; i < l; i++){
|
||||
@@ -159,7 +153,7 @@ Character = function(owner){
|
||||
}
|
||||
|
||||
//functions and calculated values go here
|
||||
var protoCharacter = {
|
||||
protoCharacter = {
|
||||
attributeValue: function(attribute){
|
||||
if (attribute === undefined) return;
|
||||
//base value
|
||||
@@ -252,6 +246,41 @@ var protoCharacter = {
|
||||
passiveAbility: function(attribute){
|
||||
var mod = +getMod(this.attributeValue(attribute));
|
||||
return 10 + mod;
|
||||
},
|
||||
|
||||
pushEffects : function(effectName, effectsArray){
|
||||
//check that the arguments are of the right for
|
||||
check(effectName, String);
|
||||
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
|
||||
|
||||
for(var i = 0; i < effectsArray.length; i++){
|
||||
var effect = effectsArray[i];
|
||||
|
||||
//check if the character exists with the field we are changing
|
||||
if(pop(effect.stat, this) !== undefined){
|
||||
var newEffect = {};
|
||||
newEffect[effect.stat] = {_id: effect.id, name: effectName, value: effect.value};
|
||||
//update the field
|
||||
Characters.update(this._id, {$push: newEffect});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
pullEffects : function(effectsArray){
|
||||
//check that the arguments are of the right form
|
||||
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
|
||||
|
||||
for(var i = 0; i < effectsArray.length; i++){
|
||||
var effect = effectsArray[i];
|
||||
|
||||
//check if the character exists with the field we are changing
|
||||
if(pop(effect.stat, this) !== undefined){
|
||||
var effectToPull = {};
|
||||
effectToPull[effect.stat] = {_id: effect.id};
|
||||
//update the field
|
||||
Characters.update(this._id, {$pull: effectToPull});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,46 +2,4 @@ Effect = function(stat, value){
|
||||
this.stat = stat;
|
||||
this.value = value;
|
||||
this._id = new Mongo.ObjectID()._str;
|
||||
}
|
||||
|
||||
|
||||
pushEffects = function(characterId, effectName, effectsArray){
|
||||
//check that the arguments are of the right form
|
||||
check(characterId, String);
|
||||
check(effectName, String);
|
||||
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
|
||||
|
||||
for(var i = 0; i < effectsArray.length; i++){
|
||||
var effect = effectsArray[i];
|
||||
|
||||
//check if the character exists with the field we are changing
|
||||
var chk = {_id: characterId}; //right id
|
||||
chk[effect.stat] = {$exists: true}; //has a field for the stat already
|
||||
if(Characters.findOne(chk)){
|
||||
var newEffect = {};
|
||||
newEffect[effect.stat] = {_id: effect.id, name: effectName, value: effect.value};
|
||||
//update the field
|
||||
Characters.update(characterId, {$push: newEffect});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pullEffects = function(characterId, effectsArray){
|
||||
//check that the arguments are of the right form
|
||||
check(characterId, String);
|
||||
check(effectsArray, [{ _id: String, stat: String, value: Number}]);
|
||||
|
||||
for(var i = 0; i < effectsArray.length; i++){
|
||||
var effect = effectsArray[i];
|
||||
|
||||
//check if the character exists with the field we are changing
|
||||
var chk = {_id: characterId}; //right id
|
||||
chk[effect.stat] = {$exists: true}; //has a field for the stat already
|
||||
if(Characters.findOne(chk)){
|
||||
var effectToPull = {};
|
||||
effectToPull[effect.stat] = {_id: effect.id};
|
||||
//update the field
|
||||
Characters.update(characterId, {$pull: effectToPull});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
Feature = function(name){
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
9
rpg-docs/Model/Character/Features.js
Normal file
9
rpg-docs/Model/Character/Features.js
Normal file
@@ -0,0 +1,9 @@
|
||||
Features = new Meteor.Collection("features");
|
||||
|
||||
Feature = function(characterId){
|
||||
this.character = characterId;
|
||||
this.name = "New Feature";
|
||||
this.description = "";
|
||||
this.effects = [];
|
||||
this.enabled = false;
|
||||
}
|
||||
@@ -1,20 +1,23 @@
|
||||
Router.map( function () {
|
||||
this.route('home', {
|
||||
path: '/',
|
||||
data: { characters: function(){
|
||||
console.log('id ' + Meteor.userId());
|
||||
return Characters.find({owner: Meteor.userId()})
|
||||
}
|
||||
}
|
||||
this.route('home',
|
||||
{
|
||||
path: '/',
|
||||
data: {
|
||||
characters: function(){
|
||||
return Characters.find({owner: Meteor.userId()})
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.route('character', {
|
||||
path: '/character/:_id',
|
||||
notFoundTemplate: 'characterNotFound',
|
||||
data: function() {
|
||||
character = Characters.findOne({_id: this.params._id});
|
||||
if (character) character.items = Items.find({owner: this.params._id});
|
||||
return character;
|
||||
}
|
||||
path: '/character/:_id',
|
||||
notFoundTemplate: 'characterNotFound',
|
||||
data: function() {
|
||||
var data = Characters.findOne({_id: this.params._id});
|
||||
data.features = Features.find({character: data._id});
|
||||
var newInstance = Object.create(protoCharacter);
|
||||
data = _.extend(newInstance, data);
|
||||
return data;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -17,5 +17,8 @@
|
||||
<div id="stats" class="flexItem">
|
||||
{{> characterStats}}
|
||||
</div>
|
||||
<div>
|
||||
{{> features}}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
8
rpg-docs/client/views/character/features.html
Normal file
8
rpg-docs/client/views/character/features.html
Normal file
@@ -0,0 +1,8 @@
|
||||
<template name="features">
|
||||
{{#each features}}
|
||||
<li><strong>{{name}}</strong><input class="enabled" type="checkbox" checked={{enabled}}><br>
|
||||
{{# each effects}}
|
||||
{{stat}}: {{value}}
|
||||
{{/each}}</li>
|
||||
{{/each}}
|
||||
</template>
|
||||
20
rpg-docs/client/views/character/features.js
Normal file
20
rpg-docs/client/views/character/features.js
Normal file
@@ -0,0 +1,20 @@
|
||||
Template.features.helpers = {
|
||||
features: function(){
|
||||
var features = Features.find({character: this._id});
|
||||
console.log('found: ', features);
|
||||
return features;
|
||||
}
|
||||
}
|
||||
|
||||
Template.features.events = {
|
||||
// Fires when any element is clicked
|
||||
'change .enabled': function (event) {
|
||||
var enable = event.target.checked
|
||||
Features.update(this._id, {$set: {enabled: enable}});
|
||||
if(enable){
|
||||
Template.parentData(1).pushEffects(this.name, this.effects);
|
||||
} else {
|
||||
Template.parentData(1).pullEffects(this.effects);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user