Added Soft remove and a character asset parenting system
This commit is contained in:
@@ -27,5 +27,8 @@ Schemas.Action = new SimpleSchema({
|
||||
|
||||
Actions.attachSchema(Schemas.Action);
|
||||
|
||||
Actions.attachBehaviour('softRemovable');
|
||||
makeChild(Actions);
|
||||
|
||||
Actions.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Actions.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -49,10 +49,8 @@ Schemas.Attack = new SimpleSchema({
|
||||
allowedValues: ["editable", "feature", "class", "buff", "equipment", "racial", "inate"]
|
||||
},
|
||||
//the id of the feature, buff or item that created this effect
|
||||
sourceId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true
|
||||
parent: {
|
||||
type: Schemas.Parent
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
@@ -67,5 +65,8 @@ Schemas.Attack = new SimpleSchema({
|
||||
|
||||
Attacks.attachSchema(Schemas.Attack);
|
||||
|
||||
Attacks.attachBehaviour('softRemovable');
|
||||
makeChild(Attacks); //children of lots of things
|
||||
|
||||
Attacks.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Attacks.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -20,11 +20,8 @@ Schemas.Buff = new SimpleSchema({
|
||||
|
||||
Buffs.attachSchema(Schemas.Buff);
|
||||
|
||||
Buffs.before.remove(function (userId, buff) {
|
||||
Effects.find({sourceId: buff._id, type: "buff"}).forEach(function(effect){
|
||||
Effects.remove(effect._id);
|
||||
});
|
||||
});
|
||||
Buffs.attachBehaviour('softRemovable');
|
||||
makeParent(Buffs); //parents of effects and attacks
|
||||
|
||||
Buffs.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Buffs.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -458,28 +458,3 @@ Characters.deny({
|
||||
return _.contains(fields, 'owner');
|
||||
}
|
||||
});
|
||||
|
||||
CHARACTER_SUBSCHEMA_ALLOW = {
|
||||
// the user must be logged in, and the user must be a writer of the character
|
||||
insert: function (userId, doc) {
|
||||
var char = Characters.findOne( doc.charId, { fields: {owner: 1, writers: 1} } );
|
||||
return ( userId && char.owner === userId || _.contains(char.writers, userId) );
|
||||
},
|
||||
update: function (userId, doc, fields, modifier) {
|
||||
var char = Characters.findOne( doc.charId, { fields: {owner: 1, writers: 1} } );
|
||||
return ( userId && char.owner === userId || _.contains(char.writers, userId) );
|
||||
},
|
||||
remove: function (userId, doc) {
|
||||
var char = Characters.findOne( doc.charId, { fields: {owner: 1, writers: 1} } );
|
||||
return ( userId && char.owner === userId || _.contains(char.writers, userId) );
|
||||
},
|
||||
fetch: ["charId"]
|
||||
};
|
||||
|
||||
CHARACTER_SUBSCHEMA_DENY = {
|
||||
update: function (userId, docs, fields, modifier) {
|
||||
// can't change character
|
||||
return _.contains(fields, 'charId');
|
||||
},
|
||||
fetch: ["charId"]
|
||||
};
|
||||
@@ -21,5 +21,8 @@ Schemas.Class = new SimpleSchema({
|
||||
|
||||
Classes.attachSchema(Schemas.Class);
|
||||
|
||||
Classes.attachBehaviour('softRemovable');
|
||||
makeParent(Classes); //parents of effects and attacks
|
||||
|
||||
Classes.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Classes.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -35,11 +35,9 @@ Schemas.Effect = new SimpleSchema({
|
||||
defaultValue: "editable",
|
||||
allowedValues: ["editable", "feature", "class", "buff", "equipment", "racial", "inate"]
|
||||
},
|
||||
//the id of the feature, buff or item that created this effect
|
||||
sourceId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true
|
||||
//the thing that created this effect
|
||||
parent: {
|
||||
type: Schemas.Parent
|
||||
},
|
||||
//which stat the effect is applied to
|
||||
stat: {
|
||||
@@ -91,5 +89,8 @@ Characters.after.insert(function (userId, char) {
|
||||
}
|
||||
});
|
||||
|
||||
Effects.attachBehaviour('softRemovable');
|
||||
makeChild(Effects); //children of lots of things
|
||||
|
||||
Effects.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Effects.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -21,5 +21,7 @@ Schemas.Experience = new SimpleSchema({
|
||||
|
||||
Experiences.attachSchema(Schemas.Experience);
|
||||
|
||||
Experiences.attachBehaviour('softRemovable');
|
||||
|
||||
Experiences.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Experiences.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -22,20 +22,8 @@ Features.helpers({
|
||||
}
|
||||
});
|
||||
|
||||
//Delete effects where this the removed feature is source
|
||||
Features.before.remove(function (userId, feature) {
|
||||
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
|
||||
Effects.remove(effect._id);
|
||||
});
|
||||
});
|
||||
|
||||
//keep the effects up to date with enabled state
|
||||
Features.after.update(function (userId, feature, fieldNames, modifier, options) {
|
||||
var enabled = feature.enabled !== "disabled";
|
||||
Effects.find({sourceId: feature._id, type: "feature"}).forEach(function(effect){
|
||||
Effects.update(effect._id, { $set: {charId: feature.charId, enabled: enabled, name: feature.name} });
|
||||
});
|
||||
}, {fetchPrevious: false});
|
||||
Features.attachBehaviour('softRemovable');
|
||||
makeParent(Features); //parents of effects and attacks
|
||||
|
||||
Features.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Features.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -9,5 +9,7 @@ Schemas.Note = new SimpleSchema({
|
||||
|
||||
Notes.attachSchema(Schemas.Note);
|
||||
|
||||
Notes.attachBehaviour('softRemovable');
|
||||
|
||||
Notes.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Notes.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -15,15 +15,12 @@ Schemas.Proficiency = new SimpleSchema({
|
||||
defaultValue: "editable",
|
||||
allowedValues: ["editable", "feature", "buff", "equipment", "inate"]
|
||||
},
|
||||
//the id of the feature, buff or item that created this effect
|
||||
sourceId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true
|
||||
},
|
||||
});
|
||||
|
||||
Proficiencies.attachSchema(Schemas.Proficiency);
|
||||
|
||||
Proficiencies.attachBehaviour('softRemovable');
|
||||
makeChild(Proficiencies);
|
||||
|
||||
Proficiencies.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Proficiencies.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -23,15 +23,8 @@ SpellLists.helpers({
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
SpellLists.attachBehaviour('softRemovable');
|
||||
makeParent(SpellLists); //parents of spells
|
||||
|
||||
SpellLists.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
SpellLists.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -2,7 +2,6 @@ Spells = new Mongo.Collection("spells");
|
||||
|
||||
Schemas.Spell = new SimpleSchema({
|
||||
charId: {type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
listId: {type: String, regEx: SimpleSchema.RegEx.Id},
|
||||
prepared: {type: String, defaultValue: "unprepared", allowedValues: ["prepared","unprepared","always"]},
|
||||
name: {type: String, trim: false},
|
||||
description: {type: String, optional: true, trim: false},
|
||||
@@ -21,5 +20,8 @@ Schemas.Spell = new SimpleSchema({
|
||||
|
||||
Spells.attachSchema(Schemas.Spell);
|
||||
|
||||
Spells.attachBehaviour('softRemovable');
|
||||
makeChild(Spells); //children of spell lists
|
||||
|
||||
Spells.allow(CHARACTER_SUBSCHEMA_ALLOW);
|
||||
Spells.deny(CHARACTER_SUBSCHEMA_DENY);
|
||||
|
||||
@@ -19,4 +19,4 @@ Schemas.DeathSave = new SimpleSchema({
|
||||
type: Boolean,
|
||||
defaultValue: false
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user