Added Soft remove and a character asset parenting system

This commit is contained in:
Thaum
2015-03-18 08:59:02 +00:00
parent 06b0ad7eba
commit 3656a0b66f
24 changed files with 215 additions and 121 deletions

View File

@@ -30,14 +30,7 @@ Containers.helpers({
}
});
Containers.before.remove(function (userId, container) {
if(Meteor.isServer){
Items.remove({container: container._id});
} else {
Items.find({container: container._id}).forEach(function(item){
Items.remove(item._id);
});
}
});
Containers.attachBehaviour('softRemovable');
makeParent(Containers); //parents of items
Containers.allow(CHARACTER_SUBSCHEMA_ALLOW);

View File

@@ -4,7 +4,6 @@ Schemas.Item = new SimpleSchema({
name: {type: String, defaultValue: "New Item", trim: false},
plural: {type: String, optional: true, trim: false},
description:{type: String, optional: true, trim: false},
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},
@@ -14,8 +13,8 @@ Schemas.Item = new SimpleSchema({
defaultValue: "none",
allowedValues: ["none", "head", "armor", "arms", "hands", "held", "feet"]
},
equipped: {type: Boolean, defaultValue: false},
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
enabled: {type: Boolean, defaultValue: false},
color: {type: String, allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q"}
});
Items.attachSchema(Schemas.Item);
@@ -36,24 +35,8 @@ Items.helpers({
}
});
//remove effects and attacks if their item source is removed
Items.before.remove(function (userId, item) {
Effects.find({sourceId: item._id, type: "equipment"}).forEach(function(effect){
Effects.remove(effect._id);
});
Attacks.find({sourceId: item._id, type: "equipment"}).forEach(function(attack){
Attacks.remove(attack._id);
});
});
//keep the effects and attacks on the correct character and enabled when equipped
Items.after.update(function (userId, item, fieldNames, modifier, options) {
Effects.find({sourceId: item._id, type: "equipment"}).forEach(function(effect){
Effects.update(effect._id, { $set: {charId: item.charId, enabled: item.equipped, name: item.name} });
});
Attacks.find({sourceId: item._id, type: "equipment"}).forEach(function(attack){
Attacks.update(attack._id, { $set: {charId: item.charId, enabled: item.equipped, name: item.name} });
});
}, {fetchPrevious: false});
Items.attachBehaviour('softRemovable');
makeChild(Items); //children of containers
makeParent(Items); //parents of effects and attacks
Items.allow(CHARACTER_SUBSCHEMA_ALLOW);