Implemented and cleaned up character schemas

This commit is contained in:
Thaum
2014-11-13 08:44:21 +00:00
parent d80fb19dfe
commit 7ab97a17cc
27 changed files with 403 additions and 259 deletions

View File

@@ -1,7 +1,10 @@
Containers = new Meteor.Collection('containers');
//set up the collection for containers
Containers = new Meteor.Collection("containers");
Container = function(name, owner){
this.name = name;
this.owner = owner;
this.isCarried = true;
};
Schemas.Container = new SimpleSchema({
name: { type: String },
owner: { type: String, regEx: SimpleSchema.RegEx.Id},
isCarried: { type: Boolean }
});
Containers.attachSchema(Schemas.Container);

View File

@@ -1,23 +1,26 @@
Items = new Meteor.Collection('items');
Item = function(name, container){
this.name = name;
this.container = container;
this.quantity = 1;
this.weight = 0.0;
//value in gold pieces
this.value = 0;
this.description = "";
//is this item a coin, letter of credit, ect.
this.tradeGood = false;
this.stakcable = false;
this.effects = [];
}
Schemas.Item = new SimpleSchema({
name: {type: String},
description:{type: String},
container: {type: String, regEx: SimpleSchema.RegEx.Id},
quantity: {type: Number, min: 0, defaultValue: 1},
weight: {type: Number, min: 0, defaultValue: 0, decimal: true},
value: {type: Number, min: 0, defaultValue: 0, decimal: true},
tradeGood: {type: Boolean, defaultValue: false},
stackable: {type: Boolean, defaultValue: false},
buffs: {type: [Schemas.Buff]}
});
Items.attachSchema(Schemas.Item);
Items.helpers({
totalValue: function(){
return this.value * this.quantity;
},
totalWeight: function(){
return this.weight * this.quantity;
},
pluralName: function(){
if(this.stackable && this.plural && this.quantity > 1){
return this.plural;
@@ -25,31 +28,4 @@ Items.helpers({
return this.name;
}
}
});
if(Meteor.isClient){
Template.registerHelper("valueString", function(value){
var resultArray = [];
//sp
var gp = Math.floor(value);
if(gp > 0) resultArray.push(gp + "gp");
//sp
var sp = Math.floor(10 * (value % 1));
if(sp > 0) resultArray.push(sp + "sp");
//cp
var cp = 10 * ((value * 10) % 1);
cp = Math.round(cp * 1000) / 1000;
if(cp > 0) resultArray.push(cp + "cp");
//build string with correct spacing
var result = "";
for(var i = 0; i < resultArray.length; i++){
//add a space between values
if(i !== 0){
result += " ";
}
result += resultArray[i];
}
return result;
});
}
});