From a94f437ba8740d0f1015bfe4d110cc092d6cd48e Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 1 Apr 2019 13:48:39 +0200 Subject: [PATCH] methods now use correct mixins --- .../api/creature/properties/Actions.js | 33 +++++++++++-------- .../api/creature/properties/Attributes.js | 7 ++-- app/imports/api/creature/properties/Buffs.js | 13 +++----- .../api/creature/properties/ClassLevels.js | 17 +++++----- .../api/creature/properties/Classes.js | 13 +++----- .../creature/properties/DamageMultipliers.js | 17 ++++------ .../api/creature/properties/Effects.js | 21 +++++++----- .../api/creature/properties/Experiences.js | 12 +++---- .../api/creature/properties/Features.js | 18 +++++----- .../api/creature/properties/Folders.js | 22 +++++++------ app/imports/api/creature/properties/Notes.js | 13 +++----- .../api/creature/properties/Proficiencies.js | 20 ++++++----- app/imports/api/creature/properties/Rolls.js | 25 ++++---------- app/imports/api/creature/properties/Skills.js | 23 ++++++++----- .../api/creature/properties/SpellLists.js | 13 +++----- app/imports/api/creature/properties/Spells.js | 28 +++++++++------- app/imports/api/mixins/updateSchemaMixin.js | 23 +++++++------ 17 files changed, 160 insertions(+), 158 deletions(-) diff --git a/app/imports/api/creature/properties/Actions.js b/app/imports/api/creature/properties/Actions.js index 2bc8b12a..f86b9129 100644 --- a/app/imports/api/creature/properties/Actions.js +++ b/app/imports/api/creature/properties/Actions.js @@ -11,26 +11,35 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; - +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Actions = new Mongo.Collection('actions'); /* * Actions are things a character can do + * Any rolls that are children of actions will be rolled when taking the action + * Any actions that are children of this action will be considered alternatives + * to this action */ let ActionSchema = schema({ name: { type: String, optional: true, }, + enabled: { + type: Boolean, + defaultValue: true, + }, description: { type: String, optional: true, }, // What time-resource is used to take the action in combat + // long actions take longer than 1 round to cast type: { type: String, - allowedValues: ['attack', 'action', 'bonus', 'reaction', 'free'], + allowedValues: ['action', 'bonus', 'attack', 'reaction', 'free', 'long'], defaultValue: 'action', }, // Who is the action directed at @@ -42,8 +51,8 @@ let ActionSchema = schema({ 'multipleTargets', ], }, - // Adjustments applied when taking this action, regardless of roll outcomes - // If these adjustments can't be made, the action should be unusable + // Adjustments applied when taking this action + // Ideally, if these adjustments can't be made, the action should be unusable adjustments: { type: Array, defaultValue: [], @@ -51,7 +60,7 @@ let ActionSchema = schema({ 'adjustments.$': { type: AdjustmentSchema, }, - // Buffs applied when taking this action, regardless of roll outcomes + // Buffs applied when taking this action buffs: { type: Array, defaultValue: [], @@ -60,7 +69,8 @@ let ActionSchema = schema({ type: StoredBuffSchema, }, // Calculation of how many times this action can be used - // Only set if this action tracks its own uses + // Only set if this action tracks its own uses, rather than adjusting + // resources uses: { type: String, optional: true, @@ -104,18 +114,13 @@ const insertAction = new ValidatedMethod({ const updateAction = new ValidatedMethod({ name: 'Actions.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Actions, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: ActionSchema.omit('name'), - }), - run({_id, update}) { - return Actions.update(_id, {$set: update}); - }, + schema: ActionSchema, }); export default Actions; diff --git a/app/imports/api/creature/properties/Attributes.js b/app/imports/api/creature/properties/Attributes.js index cff80927..076ec855 100644 --- a/app/imports/api/creature/properties/Attributes.js +++ b/app/imports/api/creature/properties/Attributes.js @@ -79,7 +79,6 @@ let AttributeSchema = schema({ }); AttributeSchema.extend(ColorSchema); -AttributeSchema.extend(PropertySchema); const ComputedAttributeSchema = schema({ // The computed value of the attribute @@ -94,6 +93,7 @@ const ComputedAttributeSchema = schema({ }, }).extend(AttributeSchema); +Attributes.attachSchema(PropertySchema); Attributes.attachSchema(ComputedAttributeSchema); Attributes.attachSchema(ChildSchema); @@ -125,7 +125,7 @@ const updateAttribute = new ValidatedMethod({ ], collection: Attributes, permission: 'edit', - updateSchema: AttributeSchema, + schema: AttributeSchema.omit(['adjutment']), skipRecompute({update}){ let fields = getModifierFields(update); return !fields.hasAny([ @@ -134,9 +134,6 @@ const updateAttribute = new ValidatedMethod({ 'baseValue', ]); }, - run({_id, update}) { - return Attributes.update(_id, update); - }, }); const adjustAttribute = new ValidatedMethod({ diff --git a/app/imports/api/creature/properties/Buffs.js b/app/imports/api/creature/properties/Buffs.js index 54a8be9b..3ac52d3c 100644 --- a/app/imports/api/creature/properties/Buffs.js +++ b/app/imports/api/creature/properties/Buffs.js @@ -9,6 +9,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Buffs = new Mongo.Collection('buffs'); @@ -99,18 +101,13 @@ const insertBuff = new ValidatedMethod({ const updateBuff = new ValidatedMethod({ name: 'Buffs.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Buffs, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: BuffSchema.omit('name'), - }), - run({_id, update}) { - return Buffs.update(_id, {$set: update}); - }, + schema: BuffSchema, }); export default Buffs; diff --git a/app/imports/api/creature/properties/ClassLevels.js b/app/imports/api/creature/properties/ClassLevels.js index 111d2aee..f3aa70f9 100644 --- a/app/imports/api/creature/properties/ClassLevels.js +++ b/app/imports/api/creature/properties/ClassLevels.js @@ -9,6 +9,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let ClassLevels = new Mongo.Collection("classLevels"); @@ -17,6 +19,10 @@ let ClassLevelSchema = schema({ type: String, optional: true, }, + enabled: { + type: Boolean, + defaultValue: true, + }, // The name of this class level's variable variableName: { type: String, @@ -66,18 +72,13 @@ const insertClassLevel = new ValidatedMethod({ const updateClassLevel = new ValidatedMethod({ name: 'ClassLevels.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: ClassLevels, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: ClassLevelSchema.omit('name'), - }), - run({_id, update}) { - return ClassLevels.update(_id, {$set: update}); - }, + schema: ClassLevelSchema, }); export default ClassLevels; diff --git a/app/imports/api/creature/properties/Classes.js b/app/imports/api/creature/properties/Classes.js index d38dcb89..adcafbf2 100644 --- a/app/imports/api/creature/properties/Classes.js +++ b/app/imports/api/creature/properties/Classes.js @@ -10,6 +10,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Classes = new Mongo.Collection("classes"); @@ -51,18 +53,13 @@ const insertClass = new ValidatedMethod({ const updateClass = new ValidatedMethod({ name: 'Classes.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Classes, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: ClassSchema.omit('name'), - }), - run({_id, update}) { - return Classes.update(_id, {$set: update}); - }, + schema: ClassSchema, }); export default Classes; diff --git a/app/imports/api/creature/properties/DamageMultipliers.js b/app/imports/api/creature/properties/DamageMultipliers.js index 74d939b9..627feaac 100644 --- a/app/imports/api/creature/properties/DamageMultipliers.js +++ b/app/imports/api/creature/properties/DamageMultipliers.js @@ -10,6 +10,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let DamageMultipliers = new Mongo.Collection("damageMultipliers"); @@ -42,12 +44,12 @@ DamageMultipliers.attachSchema(ChildSchema); const insertDamageMultiplier = new ValidatedMethod({ name: 'DamageMultipliers.methods.insert', mixins: [ - creaturePermissionMixin, setDocAncestryMixin, ensureAncestryContainsCharIdMixin, recomputeCreatureMixin, setDocToLastMixin, simpleSchemaMixin, + creaturePermissionMixin, ], collection: DamageMultipliers, permission: 'edit', @@ -60,19 +62,14 @@ const insertDamageMultiplier = new ValidatedMethod({ const updateDamageMultiplier = new ValidatedMethod({ name: 'DamageMultipliers.methods.update', mixins: [ - creaturePermissionMixin, recomputeCreatureMixin, - simpleSchemaMixin, + propagateInheritanceUpdateMixin, + updateSchemaMixin, + creaturePermissionMixin, ], collection: DamageMultipliers, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: DamageMultiplierSchema.omit('name'), - }), - run({_id, update}) { - return DamageMultipliers.update(_id, {$set: update}); - }, + schema: DamageMultiplierSchema, }); export default DamageMultipliers; diff --git a/app/imports/api/creature/properties/Effects.js b/app/imports/api/creature/properties/Effects.js index d833bc38..387f198d 100644 --- a/app/imports/api/creature/properties/Effects.js +++ b/app/imports/api/creature/properties/Effects.js @@ -9,6 +9,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Effects = new Mongo.Collection('effects'); @@ -81,18 +83,21 @@ const insertEffect = new ValidatedMethod({ const updateEffect = new ValidatedMethod({ name: 'Effects.methods.update', mixins: [ - creaturePermissionMixin, recomputeCreatureMixin, - simpleSchemaMixin, + propagateInheritanceUpdateMixin, + updateSchemaMixin, + creaturePermissionMixin, ], collection: Effects, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: EffectSchema.omit('name'), - }), - run({_id, update}) { - return Effects.update(_id, {$set: update}); + schema: EffectSchema, + skipRecompute({update}){ + let fields = getModifierFields(update); + return !fields.hasAny([ + 'operation', + 'calculation', + 'stat', + ]); }, }); diff --git a/app/imports/api/creature/properties/Experiences.js b/app/imports/api/creature/properties/Experiences.js index 8ff256f0..ca81ec9b 100644 --- a/app/imports/api/creature/properties/Experiences.js +++ b/app/imports/api/creature/properties/Experiences.js @@ -9,6 +9,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Experiences = new Mongo.Collection("experience"); @@ -77,16 +79,14 @@ const insertExperience = new ValidatedMethod({ const updateExperience = new ValidatedMethod({ name: 'Experiences.methods.update', mixins: [ - creaturePermissionMixin, recomputeCreatureMixin, - simpleSchemaMixin, + ropagateInheritanceUpdateMixin, + updateSchemaMixin, + creaturePermissionMixin, ], collection: Experiences, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: ExperienceSchema.omit('name'), - }), + schema: ExperienceSchema, skipRecompute({update}){ return !('value' in update); }, diff --git a/app/imports/api/creature/properties/Features.js b/app/imports/api/creature/properties/Features.js index d08591a7..eba5d322 100644 --- a/app/imports/api/creature/properties/Features.js +++ b/app/imports/api/creature/properties/Features.js @@ -8,11 +8,12 @@ import ChildSchema from '/imports/api/parenting/ChildSchema.js'; import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js'; // Mixins -import recomputeCreatureMixin from '/imports/api/mixins/recomputeCreatureMixin.js'; import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin.js'; import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Features = new Mongo.Collection('features'); @@ -21,6 +22,10 @@ let FeatureSchema = schema({ type: String, optional: true, }, + enabled: { + type: Boolean, + defaultValue: true, + }, description: { type: String, optional: true, @@ -57,18 +62,13 @@ const insertFeature = new ValidatedMethod({ const updateFeature = new ValidatedMethod({ name: 'Features.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Features, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: FeatureSchema.omit('name'), - }), - run({_id, update}) { - return Features.update(_id, {$set: update}); - }, + schema: FeatureSchema, }); export default Features; diff --git a/app/imports/api/creature/properties/Folders.js b/app/imports/api/creature/properties/Folders.js index 53fdb86b..b33a0b26 100644 --- a/app/imports/api/creature/properties/Folders.js +++ b/app/imports/api/creature/properties/Folders.js @@ -8,18 +8,25 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Folders = new Mongo.Collection('folders'); +// Folders organize a character sheet into a tree, particularly to group things +// like 'race' and 'background' let FolderSchema = schema({ name: { type: String, optional: true, }, -}); + enabled: { + type: Boolean, + defaultValue: true, + }, +}).extend(PropertySchema); Folders.attachSchema(FolderSchema); -Folders.attachSchema(PropertySchema); Folders.attachSchema(ChildSchema); const insertFolder = new ValidatedMethod({ @@ -42,18 +49,13 @@ const insertFolder = new ValidatedMethod({ const updateFolder = new ValidatedMethod({ name: 'Folders.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Folders, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: FolderSchema.omit('name'), - }), - run({_id, update}) { - return Folders.update(_id, {$set: update}); - }, + schema: FolderSchema, }); export default Folders; diff --git a/app/imports/api/creature/properties/Notes.js b/app/imports/api/creature/properties/Notes.js index af74d733..f98cfd22 100644 --- a/app/imports/api/creature/properties/Notes.js +++ b/app/imports/api/creature/properties/Notes.js @@ -8,6 +8,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Notes = new Mongo.Collection("notes"); @@ -47,18 +49,13 @@ const insertNote = new ValidatedMethod({ const updateNote = new ValidatedMethod({ name: 'Notes.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Notes, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: NoteSchema.omit('name'), - }), - run({_id, update}) { - return Notes.update(_id, {$set: update}); - }, + schema: NoteSchema, }); export default Notes; diff --git a/app/imports/api/creature/properties/Proficiencies.js b/app/imports/api/creature/properties/Proficiencies.js index 3df0227d..5770ea23 100644 --- a/app/imports/api/creature/properties/Proficiencies.js +++ b/app/imports/api/creature/properties/Proficiencies.js @@ -9,6 +9,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Proficiencies = new Mongo.Collection("proficiencies"); @@ -55,18 +57,20 @@ const insertProficiency = new ValidatedMethod({ const updateProficiency = new ValidatedMethod({ name: 'Proficiencies.methods.update', mixins: [ - creaturePermissionMixin, recomputeCreatureMixin, - simpleSchemaMixin, + propagateInheritanceUpdateMixin, + updateSchemaMixin, + creaturePermissionMixin, ], collection: Proficiencies, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: ProficiencySchema.omit('name'), - }), - run({_id, update}) { - return Proficiencies.update(_id, {$set: update}); + schema: ProficiencySchema, + skipRecompute({update}){ + let fields = getModifierFields(update); + return !fields.hasAny([ + 'value', + 'skill', + ]); }, }); diff --git a/app/imports/api/creature/properties/Rolls.js b/app/imports/api/creature/properties/Rolls.js index 892c0285..75d5067f 100644 --- a/app/imports/api/creature/properties/Rolls.js +++ b/app/imports/api/creature/properties/Rolls.js @@ -9,14 +9,12 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Rolls = new Mongo.Collection('rolls'); let RollChildrenSchema = new SimpleSchema({ - name: { - type: String, - optional: true, - }, // The adjustments to be applied adjustments: { type: Array, @@ -91,12 +89,8 @@ let RollSchema = new SimpleSchema({ optional: true, }, // The buffs and adjustments to apply based on the outcome of the roll - hit: { - type: RollChildrenSchema, - }, - miss: { - type: RollChildrenSchema, - }, + hit: RollChildrenSchema, + miss: RollChildrenSchema, }); Rolls.attachSchema(RollSchema); @@ -123,18 +117,13 @@ const insertRoll = new ValidatedMethod({ const updateRoll = new ValidatedMethod({ name: 'Rolls.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Rolls, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: RollSchema.omit('name'), - }), - run({_id, update}) { - return Rolls.update(_id, {$set: update}); - }, + schema: RollSchema, }); export default Rolls; diff --git a/app/imports/api/creature/properties/Skills.js b/app/imports/api/creature/properties/Skills.js index 1b6267d9..e117da53 100644 --- a/app/imports/api/creature/properties/Skills.js +++ b/app/imports/api/creature/properties/Skills.js @@ -10,6 +10,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let Skills = new Mongo.Collection("skills"); @@ -124,18 +126,23 @@ const insertSkill = new ValidatedMethod({ const updateSkill = new ValidatedMethod({ name: 'Skills.methods.update', mixins: [ - creaturePermissionMixin, recomputeCreatureMixin, - simpleSchemaMixin, + propagateInheritanceUpdateMixin, + updateSchemaMixin, + creaturePermissionMixin, ], collection: Skills, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: SkillSchema.omit('name'), - }), - run({_id, update}) { - return Skills.update(_id, {$set: update}); + schema: SkillSchema, + skipRecompute({update}){ + let fields = getModifierFields(update); + return !fields.hasAny([ + 'variableName', + 'ability', + 'type', + 'baseValue', + 'baseProficiency', + ]); }, }); diff --git a/app/imports/api/creature/properties/SpellLists.js b/app/imports/api/creature/properties/SpellLists.js index 14ff7532..ed104b4b 100644 --- a/app/imports/api/creature/properties/SpellLists.js +++ b/app/imports/api/creature/properties/SpellLists.js @@ -9,6 +9,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; let SpellLists = new Mongo.Collection("spellLists"); @@ -64,18 +66,13 @@ const insertSpellList = new ValidatedMethod({ const updateSpellList = new ValidatedMethod({ name: 'SpellLists.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: SpellLists, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: SpellListSchema.omit('name'), - }), - run({_id, update}) { - return SpellLists.update(_id, {$set: update}); - }, + schema: SpellListSchema, }); export default SpellLists; diff --git a/app/imports/api/creature/properties/Spells.js b/app/imports/api/creature/properties/Spells.js index 0ee95348..7bdd1080 100644 --- a/app/imports/api/creature/properties/Spells.js +++ b/app/imports/api/creature/properties/Spells.js @@ -9,6 +9,8 @@ import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin import { setDocToLastMixin } from '/imports/api/mixins/setDocToLastMixin.js'; import { setDocAncestryMixin, ensureAncestryContainsCharIdMixin } from '/imports/api/parenting/parenting.js'; import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; +import propagateInheritanceUpdateMixin from '/imports/api/mixins/propagateInheritanceUpdateMixin.js'; +import updateSchemaMixin from '/imports/api/mixins/updateSchemaMixin.js'; const magicSchools = [ 'Abjuration', @@ -28,11 +30,18 @@ let SpellSchema = schema({ type: String, optional: true, }, - prepared: { - type: String, - defaultValue: 'prepared', - allowedValues: ['prepared', 'unprepared', 'always'], + // If it's always prepared, it doesn't count against the number of spells + // prepared in a spell list, and enabled should be true + alwaysPrepared: { + type: Boolean, + defaultValue: false, }, + // Spells are enabled when they are prepared, so that unprepared spells don't + // show their actions + enabled: { + type: Boolean, + defaultValue: true, + }, description: { type: String, optional: true, @@ -108,18 +117,13 @@ const insertSpell = new ValidatedMethod({ const updateSpell = new ValidatedMethod({ name: 'Spells.methods.update', mixins: [ + propagateInheritanceUpdateMixin, + updateSchemaMixin, creaturePermissionMixin, - simpleSchemaMixin, ], collection: Spells, permission: 'edit', - schema: new SimpleSchema({ - _id: SimpleSchema.RegEx.Id, - update: SpellSchema.omit('name'), - }), - run({_id, update}) { - return Spells.update(_id, {$set: update}); - }, + schema: SpellSchema, }); export default Spells; diff --git a/app/imports/api/mixins/updateSchemaMixin.js b/app/imports/api/mixins/updateSchemaMixin.js index 2e840492..c62ff9a8 100644 --- a/app/imports/api/mixins/updateSchemaMixin.js +++ b/app/imports/api/mixins/updateSchemaMixin.js @@ -12,16 +12,12 @@ import SimpleSchema from 'simpl-schema'; export default function updateSchemaMixin(methodOptions) { // If the user didn't give us a schema and they did give us a validate, assume // that they are choosing to use the validate way of doing things in this call. - // If they've built a wrapper around ValidateMethod that includes this mixin - // all the time, this could happen semi-"intentionally". There may be times they - // just don't want to use a schema and have specified a "validate" option. So - // returning the unchanged options instead of an error seems proper. if (( - typeof methodOptions.updateSchema === 'undefined' && + typeof methodOptions.schema === 'undefined' && typeof methodOptions.validate !== 'undefined' ) || ( - typeof methodOptions.updateSchema !== 'undefined' && - methodOptions.updateSchema === null && + typeof methodOptions.schema !== 'undefined' && + methodOptions.schema === null && typeof methodOptions.validate !== 'undefined' && methodOptions.validate !== null )) { @@ -46,10 +42,10 @@ export default function updateSchemaMixin(methodOptions) { // Make the update schema a SimpleSchema, if it isn't already let updateSchema; - if (methodOptions.updateSchema instanceof SimpleSchema) { - updateSchema = methodOptions.updateSchema; + if (methodOptions.schema instanceof SimpleSchema) { + updateSchema = methodOptions.schema; } else { - updateSchema = new SimpleSchema(methodOptions.updateSchema); + updateSchema = new SimpleSchema(methodOptions.schema); } // Set up the new validation @@ -57,5 +53,12 @@ export default function updateSchemaMixin(methodOptions) { argumentSchema.validate(args); updateSchema.validate(args.update, methodOptions.schemaValidatorOptions); }; + + // Give a default run function if one isn't supplied + if (!methodOptions.run){ + methodOptions.run = function({_id, update}){ + return MethodOptions.collection.update(_id, {$set: update}); + }; + } return methodOptions; }