From a3b0c6cafdde690236f330fc4e146623bb853d5e Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 9 Aug 2017 10:06:11 +0100 Subject: [PATCH] Added a schema/collection pair for CustomBuffs --- rpg-docs/Model/Character/Buffs.js | 17 ++++-- rpg-docs/Model/Character/Characters.js | 1 + rpg-docs/Model/Character/CustomBuffs.js | 57 +++++++++++++++++++ .../server/lib/cron/deleteRemovedDocuments.js | 2 +- .../server/publications/singleCharacter.js | 29 +++++----- 5 files changed, 86 insertions(+), 20 deletions(-) create mode 100644 rpg-docs/Model/Character/CustomBuffs.js diff --git a/rpg-docs/Model/Character/Buffs.js b/rpg-docs/Model/Character/Buffs.js index dd16c39b..94ce78f9 100644 --- a/rpg-docs/Model/Character/Buffs.js +++ b/rpg-docs/Model/Character/Buffs.js @@ -42,10 +42,18 @@ Schemas.Buff = new SimpleSchema({ allowedValues: _.pluck(colorOptions, "key"), defaultValue: "q", }, - //the id of the feature, buff or item that created this buff - parent: { - type: Schemas.Parent, - optional: true, + appliedBy: { //the charId of whoever applied the buff + type: String, + regEx: SimpleSchema.RegEx.Id, + }, + appliedByDetails: {//the name and collection of the thing that applied the buff, and the character's name + type: Object; + }, + "appliedByDetails.name": { + type: String, + }, + "appliedByDetails.collection": { + type: String, }, }); @@ -53,7 +61,6 @@ Buffs.attachSchema(Schemas.Buff); Buffs.attachBehaviour("softRemovable"); makeParent(Buffs, ["name", "enabled"]); //parents of effects, attacks, proficiencies -makeChild(Buffs, ["enabled"]); //children of lots of things Buffs.allow(CHARACTER_SUBSCHEMA_ALLOW); Buffs.deny(CHARACTER_SUBSCHEMA_DENY); diff --git a/rpg-docs/Model/Character/Characters.js b/rpg-docs/Model/Character/Characters.js index e75430b2..cd945467 100644 --- a/rpg-docs/Model/Character/Characters.js +++ b/rpg-docs/Model/Character/Characters.js @@ -532,6 +532,7 @@ if (Meteor.isServer){ Attacks .remove({charId: character._id}); Buffs .remove({charId: character._id}); Classes .remove({charId: character._id}); + CustomBuffs .remove({charId: character._id}); Effects .remove({charId: character._id}); Experiences .remove({charId: character._id}); Features .remove({charId: character._id}); diff --git a/rpg-docs/Model/Character/CustomBuffs.js b/rpg-docs/Model/Character/CustomBuffs.js new file mode 100644 index 00000000..2920a547 --- /dev/null +++ b/rpg-docs/Model/Character/CustomBuffs.js @@ -0,0 +1,57 @@ +CustomBuffs = new Mongo.Collection("customBuffs"); + +Schemas.CustomBuff = new SimpleSchema({ + charId: { + type: String, + regEx: SimpleSchema.RegEx.Id, + index: 1, + }, + name: { + type: String, + optional: true, + trim: false, + }, + description: { + type: String, + optional: true, + trim: false, + }, + enabled: { + type: Boolean, + autoValue: function(){ + return false; + //enabled is ALWAYS false on these, so that its children are also not enabled, so that the buff templates have no effects. + }, + }, + type: { + type: String, + allowedValues: [ + "inate", //this should be "innate", but changing it could be problematic + "custom", + ], + }, + "lifeTime.total": { + type: Number, + defaultValue: 0, //0 is infinite + min: 0, + }, + color: { + type: String, + allowedValues: _.pluck(colorOptions, "key"), + defaultValue: "q", + }, + //the id of the feature, buff or item that creates this buff + parent: { + type: Schemas.Parent, + optional: true, + }, +}); + +CustomBuffs.attachSchema(Schemas.CustomBuff); + +CustomBuffs.attachBehaviour("softRemovable"); +makeParent(CustomBuffs, ["name", "enabled"]); //parents of effects, attacks, proficiencies. Since this represents a template, "enabled" is always false. +makeChild(CustomBuffs, ["enabled"]); //children of lots of things + +CustomBuffs.allow(CHARACTER_SUBSCHEMA_ALLOW); +CustomBuffs.deny(CHARACTER_SUBSCHEMA_DENY); diff --git a/rpg-docs/server/lib/cron/deleteRemovedDocuments.js b/rpg-docs/server/lib/cron/deleteRemovedDocuments.js index cbd3f13c..d450aaec 100644 --- a/rpg-docs/server/lib/cron/deleteRemovedDocuments.js +++ b/rpg-docs/server/lib/cron/deleteRemovedDocuments.js @@ -1,6 +1,6 @@ Meteor.startup(() => { const collections = [ - Attacks, Buffs, Classes, Effects, Experiences, + Attacks, Buffs, Classes, CustomBuffs, Effects, Experiences, Features, Notes, Proficiencies, SpellLists, Spells, Containers, Items, ]; diff --git a/rpg-docs/server/publications/singleCharacter.js b/rpg-docs/server/publications/singleCharacter.js index 13632db3..3a039c38 100644 --- a/rpg-docs/server/publications/singleCharacter.js +++ b/rpg-docs/server/publications/singleCharacter.js @@ -13,20 +13,21 @@ Meteor.publish("singleCharacter", function(characterId){ return [ Characters.find({_id: characterId}), //get all the assets for this character including soft deleted ones - Actions.find ({charId: characterId}, {removed: true}), - Attacks.find ({charId: characterId}, {removed: true}), - Buffs.find ({charId: characterId}, {removed: true}), - Classes.find ({charId: characterId}, {removed: true}), - Containers.find ({charId: characterId}, {removed: true}), - Effects.find ({charId: characterId}, {removed: true}), - Experiences.find ({charId: characterId}, {removed: true}), - Features.find ({charId: characterId}, {removed: true}), - Items.find ({charId: characterId}, {removed: true}), - Notes.find ({charId: characterId}, {removed: true}), - Spells.find ({charId: characterId}, {removed: true}), - SpellLists.find ({charId: characterId}, {removed: true}), - TemporaryHitPoints.find({charId: characterId}, {removed: true}), - Proficiencies.find ({charId: characterId}, {removed: true}), + Actions.find ({charId: characterId}, {removed: true}), + Attacks.find ({charId: characterId}, {removed: true}), + Buffs.find ({charId: characterId}, {removed: true}), + Classes.find ({charId: characterId}, {removed: true}), + Containers.find ({charId: characterId}, {removed: true}), + CustomBuffs.find ({charId: characterId}, {removed: true}), + Effects.find ({charId: characterId}, {removed: true}), + Experiences.find ({charId: characterId}, {removed: true}), + Features.find ({charId: characterId}, {removed: true}), + Items.find ({charId: characterId}, {removed: true}), + Notes.find ({charId: characterId}, {removed: true}), + Spells.find ({charId: characterId}, {removed: true}), + SpellLists.find ({charId: characterId}, {removed: true}), + TemporaryHitPoints.find ({charId: characterId}, {removed: true}), + Proficiencies.find ({charId: characterId}, {removed: true}), ]; } else { return [];