Implemented item editing

This commit is contained in:
Thaum
2015-01-26 13:28:10 +00:00
parent 6a2e7f0832
commit dc6ea555e5
25 changed files with 331 additions and 133 deletions

View File

@@ -4,13 +4,11 @@ Schemas.Item = new SimpleSchema({
name: {type: String, defaultValue: "New Item"},
plural: {type: String, optional: true},
description:{type: String, defaultValue: ""},
container: {type: String, regEx: SimpleSchema.RegEx.Id, optional: true}, //id of container it normally is stowed in
charId: {type: String, regEx: SimpleSchema.RegEx.Id, optional: true}, //id of owner
container: {type: String, regEx: SimpleSchema.RegEx.Id}, //id of container it is normally stowed in
charId: {type: String, regEx: SimpleSchema.RegEx.Id}, //id of owner
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},
equipmentSlot: {
type: String,
defaultValue: "none",
@@ -29,10 +27,33 @@ Items.helpers({
return this.weight * this.quantity;
},
pluralName: function(){
if(this.stackable && this.plural && this.quantity > 1){
if(this.plural && this.quantity > 1){
return this.plural;
} else{
return this.name;
}
}
});
});
//keep effects sycned with items
Items.find({}, {fields: {equipped: 1}}).observeChanges({
added: function(id, fields){
Effects.find({type: "equipment", sourceId: id}, {fields: {enabled: 1} }).forEach(function(effect){
if(fields.equipped !== effect.enabled){
Effects.update(effect._id, {$set: {enabled: fields.equipped}})
}
});
},
changed: function(id, fields){
Effects.find({type: "equipment", sourceId: id}, {fields: {enabled: 1} }).forEach(function(effect){
if(fields.equipped !== effect.enabled){
Effects.update(effect._id, {$set: {enabled: fields.equipped}})
}
});
},
removed: function(id){
Effects.find({type: "equipment", sourceId: id}, {fields: {_id: 1} }).forEach(function(effect){
Effects.remove(effect._id);
});
}
});