Began implementing features that change stats
This commit is contained in:
@@ -1,14 +1,5 @@
|
|||||||
//set up the collection for characters
|
//set up the collection for characters
|
||||||
Characters = new Meteor.Collection("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;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var attributes = [
|
var attributes = [
|
||||||
{name: "strength"},
|
{name: "strength"},
|
||||||
@@ -100,6 +91,7 @@ var strings = [
|
|||||||
"alignment",
|
"alignment",
|
||||||
"gender",
|
"gender",
|
||||||
"race",
|
"race",
|
||||||
|
"class",
|
||||||
"description",
|
"description",
|
||||||
"personality",
|
"personality",
|
||||||
"ideals",
|
"ideals",
|
||||||
@@ -132,18 +124,20 @@ Character = function(owner){
|
|||||||
success : 0,
|
success : 0,
|
||||||
fail: 0
|
fail: 0
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hitDice = [];
|
|
||||||
|
|
||||||
this.weaponProficiencies = [];
|
this.weaponProficiencies = [];
|
||||||
this.toolProficiencies = [];
|
this.toolProficiencies = [];
|
||||||
this.languages = [];
|
this.languages = [];
|
||||||
|
|
||||||
|
/*
|
||||||
|
//anything that needs to be edited rather than added or removed
|
||||||
|
//needs its own collection.
|
||||||
|
this.hitDice = [];
|
||||||
|
|
||||||
this.features = [];
|
this.features = [];
|
||||||
|
|
||||||
this.spells = [];
|
this.spells = [];
|
||||||
|
*/
|
||||||
this.classes = [];
|
|
||||||
|
|
||||||
this.vulnerability = {};
|
this.vulnerability = {};
|
||||||
for(var i = 0, l = DamageTypes.length; i < l; i++){
|
for(var i = 0, l = DamageTypes.length; i < l; i++){
|
||||||
@@ -159,7 +153,7 @@ Character = function(owner){
|
|||||||
}
|
}
|
||||||
|
|
||||||
//functions and calculated values go here
|
//functions and calculated values go here
|
||||||
var protoCharacter = {
|
protoCharacter = {
|
||||||
attributeValue: function(attribute){
|
attributeValue: function(attribute){
|
||||||
if (attribute === undefined) return;
|
if (attribute === undefined) return;
|
||||||
//base value
|
//base value
|
||||||
@@ -252,6 +246,41 @@ var protoCharacter = {
|
|||||||
passiveAbility: function(attribute){
|
passiveAbility: function(attribute){
|
||||||
var mod = +getMod(this.attributeValue(attribute));
|
var mod = +getMod(this.attributeValue(attribute));
|
||||||
return 10 + mod;
|
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.stat = stat;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this._id = new Mongo.ObjectID()._str;
|
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 () {
|
Router.map( function () {
|
||||||
this.route('home', {
|
this.route('home',
|
||||||
path: '/',
|
{
|
||||||
data: { characters: function(){
|
path: '/',
|
||||||
console.log('id ' + Meteor.userId());
|
data: {
|
||||||
return Characters.find({owner: Meteor.userId()})
|
characters: function(){
|
||||||
}
|
return Characters.find({owner: Meteor.userId()})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.route('character', {
|
this.route('character', {
|
||||||
path: '/character/:_id',
|
path: '/character/:_id',
|
||||||
notFoundTemplate: 'characterNotFound',
|
notFoundTemplate: 'characterNotFound',
|
||||||
data: function() {
|
data: function() {
|
||||||
character = Characters.findOne({_id: this.params._id});
|
var data = Characters.findOne({_id: this.params._id});
|
||||||
if (character) character.items = Items.find({owner: this.params._id});
|
data.features = Features.find({character: data._id});
|
||||||
return character;
|
var newInstance = Object.create(protoCharacter);
|
||||||
}
|
data = _.extend(newInstance, data);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -17,5 +17,8 @@
|
|||||||
<div id="stats" class="flexItem">
|
<div id="stats" class="flexItem">
|
||||||
{{> characterStats}}
|
{{> characterStats}}
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
{{> features}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</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