implemented UI for new parenting

This commit is contained in:
Thaum
2015-03-20 09:12:38 +00:00
parent ecc43752aa
commit 48f8cef928
23 changed files with 126 additions and 99 deletions

View File

@@ -16,14 +16,14 @@ Containers.attachSchema(Schemas.Container);
Containers.helpers({
totalValue: function(){
var value = this.value;
Items.find({container: this._id, equipped: false}, {fields: {quantity: 1, value: 1}}).forEach(function(item){
Items.find({"parent.id": this._id}, {fields: {quantity: 1, value: 1}}).forEach(function(item){
value += item.totalValue();
});
return value;
},
totalWeight: function(){
var weight = this.weight;
Items.find({container: this._id, equipped: false}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){
Items.find({"parent.id": this._id}, {fields: {quantity: 1, weight: 1}}).forEach(function(item){
weight += item.totalWeight();
});
return weight;

View File

@@ -33,17 +33,24 @@ Items.helpers({
return this.name;
}
},
equip: function(){
Items.update(this._id, {$set: {enabled: true}});
equip: function(characterId){
var charId = characterId || this.charId;
if(!charId || ! Characters.findOne(charId)) throw "Invalid character";
if(this.parent.collection === "Characters" && this.parent.id === charId && this.enabled) return;
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": charId, enabled: true}});
},
unequip: function(){
if(!this.enabled) return;
Items.update(this._id, {$set: {enabled: false}});
},
moveToContainer: function(containerId){
if( !containerId || !Containers.findOne(containerId) ) throw "Invalid container";
if(this.parent.collection === "Containers" && this.parent.id === containerId && !this.enabled) return;
Items.update(this._id, {$set: {"parent.collection": "Containers", "parent.id": containerId, enabled: false}});
},
moveToCharacter: function(characterId){
if(this.charId === characterId) return;
if(!characterId || ! Characters.findOne(characterId)) throw "Invalid character";
if(this.parent.collection === "Characters" && this.parent.id === characterId && !this.enabled) return;
Items.update(this._id, {$set: {"parent.collection": "Characters", "parent.id": characterId, charId: characterId, enabled: false}});
}
});