Added cascading deletions
This commit is contained in:
@@ -18,3 +18,4 @@ differential:vulcanize
|
|||||||
aldeed:autoform
|
aldeed:autoform
|
||||||
conielo:autoform-polymer-paper
|
conielo:autoform-polymer-paper
|
||||||
msavin:mongol
|
msavin:mongol
|
||||||
|
matb33:collection-hooks
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ less@1.0.12
|
|||||||
livedata@1.0.12
|
livedata@1.0.12
|
||||||
localstorage@1.0.2
|
localstorage@1.0.2
|
||||||
logging@1.0.6
|
logging@1.0.6
|
||||||
|
matb33:collection-hooks@0.7.11
|
||||||
meteor@1.1.4
|
meteor@1.1.4
|
||||||
meteor-platform@1.2.1
|
meteor-platform@1.2.1
|
||||||
minifiers@1.1.3
|
minifiers@1.1.3
|
||||||
|
|||||||
@@ -19,3 +19,10 @@ Schemas.Buff = new SimpleSchema({
|
|||||||
});
|
});
|
||||||
|
|
||||||
Buffs.attachSchema(Schemas.Buff);
|
Buffs.attachSchema(Schemas.Buff);
|
||||||
|
|
||||||
|
Buffs.before.remove(function (userId, buff) {
|
||||||
|
Effects.find({sourceId: buff._id, type: "buff"}).forEach(function(effect){
|
||||||
|
Effects.remove(effect._id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -464,3 +464,21 @@ Characters.helpers({
|
|||||||
return xp;
|
return xp;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//clean up all data related to that character before removing it
|
||||||
|
Characters.before.remove(function (userId, character) {
|
||||||
|
if(Meteor.isServer){
|
||||||
|
Actions .remove({charId: character._id});
|
||||||
|
Attacks .remove({charId: character._id});
|
||||||
|
Buffs .remove({charId: character._id});
|
||||||
|
Classes .remove({charId: character._id});
|
||||||
|
Effects .remove({charId: character._id});
|
||||||
|
Experience .remove({charId: character._id});
|
||||||
|
Features .remove({charId: character._id});
|
||||||
|
Notes .remove({charId: character._id});
|
||||||
|
Proficiencies .remove({charId: character._id});
|
||||||
|
SpellLists .remove({charId: character._id});
|
||||||
|
Items .remove({charId: character._id});
|
||||||
|
Containers .remove({charId: character._id});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -20,3 +20,9 @@ Features.helpers({
|
|||||||
return evaluate(this.charId, this.uses);
|
return evaluate(this.charId, this.uses);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Features.before.remove(function (userId, feature) {
|
||||||
|
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
|
||||||
|
Effects.remove(effect._id);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -22,3 +22,13 @@ SpellLists.helpers({
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
SpellLists.before.remove(function (userId, list) {
|
||||||
|
if(Meteor.isServer){
|
||||||
|
Spells.remove({listId: list._id});
|
||||||
|
} else {
|
||||||
|
Spells.find({listId: list._id}).forEach(function(spell){
|
||||||
|
Spells.remove(spell._id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -29,3 +29,13 @@ Containers.helpers({
|
|||||||
return weight;
|
return weight;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|||||||
@@ -36,35 +36,16 @@ Items.helpers({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//keep effects sycned with items
|
//remove effects if their item source is removed
|
||||||
//if an item's equipped state changes, update related effects' enabled state
|
Items.before.remove(function (userId, item) {
|
||||||
Items.find({}, {fields: {equipped: 1}}).observeChanges({
|
Effects.find({sourceId: item._id, type: "equipment"}).forEach(function(effect){
|
||||||
added: function(id, fields){
|
Effects.remove(effect._id);
|
||||||
Effects.find({ type: "equipment", sourceId: id, enabled: {$ne: fields.equipped} },
|
});
|
||||||
{fields: {enabled: 1} }).forEach(function(effect){
|
|
||||||
Effects.update(effect._id, {$set: {enabled: fields.equipped}})
|
|
||||||
});
|
|
||||||
},
|
|
||||||
changed: function(id, fields){
|
|
||||||
Effects.find({type: "equipment", sourceId: id, enabled: {$ne: fields.equipped} },
|
|
||||||
{fields: {enabled: 1} }).forEach(function(effect){
|
|
||||||
Effects.update(effect._id, {$set: {enabled: fields.equipped}})
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//if an effect's type, source or enabled state change, keep the enabled state up to date with the item's equipped state
|
//keep the effects on the correct character and enabled when equipped
|
||||||
Effects.find({type: "equipment"}, {fields: {type: 1, enabled: 1, sourceId: 1}}).observe({
|
Items.after.update(function (userId, item, fieldNames, modifier, options) {
|
||||||
added: function(newEffect){
|
Effects.find({sourceId: item._id, type: "equipment"}).forEach(function(effect){
|
||||||
var item = Items.findOne(newEffect.sourceId, {fields: {equipped: 1}});
|
Effects.update(effect._id, { $set: {charId: item.charId, enabled: item.equipped} });
|
||||||
if(item && item.equipped !== newEffect.enabled){
|
}, {fetchPrevious: false});
|
||||||
Effects.update(newEffect._id, {$set: {enabled: item.equipped}})
|
});
|
||||||
}
|
|
||||||
},
|
|
||||||
changed: function(newEffect, oldEffect){
|
|
||||||
var item = Items.findOne(newEffect.sourceId, {fields: {equipped: 1}});
|
|
||||||
if(item && item.equipped !== newEffect.enabled){
|
|
||||||
Effects.update(newEffect._id, {$set: {enabled: item.equipped}})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|||||||
@@ -7,11 +7,15 @@ Template.effectsEditList.helpers({
|
|||||||
|
|
||||||
Template.effectsEditList.events({
|
Template.effectsEditList.events({
|
||||||
"tap #addEffectButton": function(){
|
"tap #addEffectButton": function(){
|
||||||
|
if ( !_.isBoolean(this.enabled) ) {
|
||||||
|
this.enabled = true;
|
||||||
|
}
|
||||||
Effects.insert({
|
Effects.insert({
|
||||||
charId: this.charId,
|
charId: this.charId,
|
||||||
sourceId: this.sourceId,
|
sourceId: this.sourceId,
|
||||||
operation: "add",
|
operation: "add",
|
||||||
type: this.type
|
type: this.type,
|
||||||
|
enabled: this.enabled
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -56,7 +56,7 @@
|
|||||||
</paper-autogrow-textarea>
|
</paper-autogrow-textarea>
|
||||||
</paper-input-decorator>
|
</paper-input-decorator>
|
||||||
<!--Effects-->
|
<!--Effects-->
|
||||||
{{> effectsEditList sourceId=_id charId=charId type="equipment"}}
|
{{> effectsEditList sourceId=_id charId=charId type="equipment" enabled=equipped}}
|
||||||
{{/baseDialog}}
|
{{/baseDialog}}
|
||||||
{{/with}}
|
{{/with}}
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user