diff --git a/app/.bowerrc b/app/.bowerrc deleted file mode 100644 index 1ad2d4f1..00000000 --- a/app/.bowerrc +++ /dev/null @@ -1 +0,0 @@ -{"directory":"public/components/"} \ No newline at end of file diff --git a/app/imports/api/creature/properties/Actions.js b/app/imports/api/creature/properties/Actions.js index 2bc8b12a..409c9459 100644 --- a/app/imports/api/creature/properties/Actions.js +++ b/app/imports/api/creature/properties/Actions.js @@ -2,8 +2,7 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js'; import StoredBuffSchema from '/imports/api/creature/properties/Buffs.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js'; // Mixins @@ -11,26 +10,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 +50,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 +59,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 +68,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, @@ -82,7 +91,6 @@ ActionSchema.extend(ColorSchema); Actions.attachSchema(ActionSchema); Actions.attachSchema(PropertySchema); -Actions.attachSchema(ChildSchema); const insertAction = new ValidatedMethod({ name: 'Actions.methods.insert', @@ -104,18 +112,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..75619fe4 100644 --- a/app/imports/api/creature/properties/Attributes.js +++ b/app/imports/api/creature/properties/Attributes.js @@ -1,5 +1,4 @@ -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js'; import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; @@ -79,7 +78,6 @@ let AttributeSchema = schema({ }); AttributeSchema.extend(ColorSchema); -AttributeSchema.extend(PropertySchema); const ComputedAttributeSchema = schema({ // The computed value of the attribute @@ -95,7 +93,7 @@ const ComputedAttributeSchema = schema({ }).extend(AttributeSchema); Attributes.attachSchema(ComputedAttributeSchema); -Attributes.attachSchema(ChildSchema); +Attributes.attachSchema(PropertySchema); const insertAttribute = new ValidatedMethod({ name: 'Attributes.methods.insert', @@ -125,7 +123,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 +132,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..29359715 100644 --- a/app/imports/api/creature/properties/Buffs.js +++ b/app/imports/api/creature/properties/Buffs.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import { EffectSchema } from '/imports/api/creature/properties/Effects.js'; // Mixins @@ -9,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 Buffs = new Mongo.Collection('buffs'); @@ -77,7 +78,6 @@ let AppliedBuffSchema = schema({ Buffs.attachSchema(AppliedBuffSchema); Buffs.attachSchema(PropertySchema); -Buffs.attachSchema(ChildSchema); const insertBuff = new ValidatedMethod({ name: 'Buffs.methods.insert', @@ -99,18 +99,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..b9aa42d2 100644 --- a/app/imports/api/creature/properties/ClassLevels.js +++ b/app/imports/api/creature/properties/ClassLevels.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js'; // Mixins @@ -9,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 ClassLevels = new Mongo.Collection("classLevels"); @@ -17,6 +18,10 @@ let ClassLevelSchema = schema({ type: String, optional: true, }, + enabled: { + type: Boolean, + defaultValue: true, + }, // The name of this class level's variable variableName: { type: String, @@ -42,7 +47,6 @@ let ClassLevelSchema = schema({ ClassLevels.attachSchema(ClassLevelSchema); ClassLevels.attachSchema(PropertySchema); -ClassLevels.attachSchema(ChildSchema); // Todo ensure the class level is being parented to a compatible class, and that // previous level requirements are met @@ -66,18 +70,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..7f12f41a 100644 --- a/app/imports/api/creature/properties/Classes.js +++ b/app/imports/api/creature/properties/Classes.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js"; import VARIABLE_NAME_REGEX from '/imports/constants/VARIABLE_NAME_REGEX.js'; @@ -10,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 Classes = new Mongo.Collection("classes"); @@ -29,7 +30,6 @@ ClassSchema.extend(ColorSchema); Classes.attachSchema(ClassSchema); Classes.attachSchema(PropertySchema); -Classes.attachSchema(ChildSchema); const insertClass = new ValidatedMethod({ name: 'Classes.methods.insert', @@ -51,18 +51,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..24badb1a 100644 --- a/app/imports/api/creature/properties/DamageMultipliers.js +++ b/app/imports/api/creature/properties/DamageMultipliers.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import DAMAGE_TYPES from '/imports/constants/DAMAGE_TYPES.js'; // Mixins @@ -10,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 DamageMultipliers = new Mongo.Collection("damageMultipliers"); @@ -37,17 +38,16 @@ let DamageMultiplierSchema = schema({ DamageMultipliers.attachSchema(DamageMultiplierSchema); DamageMultipliers.attachSchema(PropertySchema); -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 +60,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..81118182 100644 --- a/app/imports/api/creature/properties/Effects.js +++ b/app/imports/api/creature/properties/Effects.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' // Mixins import recomputeCreatureMixin from '/imports/api/mixins/recomputeCreatureMixin.js'; @@ -9,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 Effects = new Mongo.Collection('effects'); @@ -56,9 +57,8 @@ const EffectComputedSchema = new SimpleSchema({ }, }).extend(EffectSchema); -Effects.attachSchema(PropertySchema); -Effects.attachSchema(ChildSchema); Effects.attachSchema(EffectComputedSchema); +Effects.attachSchema(PropertySchema); const insertEffect = new ValidatedMethod({ name: 'Effects.methods.insert', @@ -81,18 +81,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..9c9937b5 100644 --- a/app/imports/api/creature/properties/Experiences.js +++ b/app/imports/api/creature/properties/Experiences.js @@ -1,6 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import recomputeCreatureXP from '/imports/api/creature/creatureComputation.js'; // Mixins @@ -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"); @@ -46,8 +48,8 @@ let ExperienceSchema = schema({ }, }); -Experiences.attachSchema(PropertySchema); Experiences.attachSchema(ExperienceSchema); +Experiences.attachSchema(PropertySchema); const insertExperience = new ValidatedMethod({ name: 'Experiences.methods.insert', @@ -77,16 +79,14 @@ const insertExperience = new ValidatedMethod({ const updateExperience = new ValidatedMethod({ name: 'Experiences.methods.update', mixins: [ - creaturePermissionMixin, recomputeCreatureMixin, - simpleSchemaMixin, + propagateInheritanceUpdateMixin, + 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..2c2ffa2e 100644 --- a/app/imports/api/creature/properties/Features.js +++ b/app/imports/api/creature/properties/Features.js @@ -1,26 +1,27 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js'; -import { recomputeCreatureById } from '/imports/api/creature/creatureComputation.js' -import { getHighestOrder } from '/imports/api/order/order.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.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'); -let FeatureSchema = schema({ +let FeatureSchema = new SimpleSchema({ name: { type: String, optional: true, }, + enabled: { + type: Boolean, + defaultValue: true, + }, description: { type: String, optional: true, @@ -35,16 +36,15 @@ FeatureSchema.extend(ColorSchema); Features.attachSchema(FeatureSchema); Features.attachSchema(PropertySchema); -Features.attachSchema(ChildSchema); const insertFeature = new ValidatedMethod({ name: 'Features.methods.insert', mixins: [ - creaturePermissionMixin, - setDocAncestryMixin, - ensureAncestryContainsCharIdMixin, setDocToLastMixin, - simpleSchemaMixin, + simpleSchemaMixin, + ensureAncestryContainsCharIdMixin, + setDocAncestryMixin, + creaturePermissionMixin, ], collection: Features, permission: 'edit', @@ -57,18 +57,13 @@ const insertFeature = new ValidatedMethod({ const updateFeature = new ValidatedMethod({ name: 'Features.methods.update', mixins: [ + updateSchemaMixin, + propagateInheritanceUpdateMixin, 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..3fb32e40 100644 --- a/app/imports/api/creature/properties/Folders.js +++ b/app/imports/api/creature/properties/Folders.js @@ -1,26 +1,32 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' // Mixins 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 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, + }, }); Folders.attachSchema(FolderSchema); Folders.attachSchema(PropertySchema); -Folders.attachSchema(ChildSchema); const insertFolder = new ValidatedMethod({ name: 'Folders.methods.insert', @@ -42,18 +48,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..f2070aa2 100644 --- a/app/imports/api/creature/properties/Notes.js +++ b/app/imports/api/creature/properties/Notes.js @@ -1,13 +1,15 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js"; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' // Mixins 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 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..a50d3a42 100644 --- a/app/imports/api/creature/properties/Proficiencies.js +++ b/app/imports/api/creature/properties/Proficiencies.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' // Mixins import recomputeCreatureMixin from '/imports/api/mixins/recomputeCreatureMixin.js'; @@ -9,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 Proficiencies = new Mongo.Collection("proficiencies"); @@ -32,7 +33,6 @@ let ProficiencySchema = schema({ Proficiencies.attachSchema(ProficiencySchema); Proficiencies.attachSchema(PropertySchema); -Proficiencies.attachSchema(ChildSchema); const insertProficiency = new ValidatedMethod({ name: 'Proficiencies.methods.insert', @@ -55,18 +55,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/Properties.js b/app/imports/api/creature/properties/Properties.js new file mode 100644 index 00000000..f10afc30 --- /dev/null +++ b/app/imports/api/creature/properties/Properties.js @@ -0,0 +1,64 @@ +import SimpleSchema from 'simpl-schema'; +import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js'; +import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import softRemove from '/imports/api/parenting/softRemove.js'; +import getCollectionByName from '/imports/api/parenting/getCollectionByName.js'; + +// Mixins +import recomputeCreatureMixin from '/imports/api/mixins/recomputeCreatureMixin.js'; +import creaturePermissionMixin from '/imports/api/mixins/creaturePermissionMixin.js'; +import simpleSchemaMixin from '/imports/api/mixins/simpleSchemaMixin.js'; + +const PropertySchema = new SimpleSchema({ + charId: { + type: String, + regEx: SimpleSchema.RegEx.Id, + index: 1, + optional: true, + }, + name: { + type: String, + optional: true, + }, + enabled: { + type: Boolean, + defaultValue: true, + }, + order: { + type: SimpleSchema.Integer, + index: true, + }, +}); + +PropertySchema.extend(SoftRemovableSchema); +PropertySchema.extend(ChildSchema); + +// Always recomputes the character, because we don't know the extent of the tree +// that was removed with this document +const softRemoveProperty = new ValidatedMethod({ + name: 'softRemoveProperty', + mixins: [ + simpleSchemaMixin, + recomputeCreatureMixin, + creaturePermissionMixin, + ], + getCharId({_id, collection}){ + let col = getCollectionByName(collection); + let doc = col.findOne(_id, {fields: {charId: 1}}); + if (!doc || !doc.charId){ + throw new Meteor.Error(`Could not find charId of ${_id} in ${collection}`); + } else { + return doc.charId; + } + }, + permission: 'edit', + schema: new SimpleSchema({ + _id: SimpleSchema.RegEx.Id, + collection: String, + }), + run({_id, collection}){ + softRemove({_id, collection}); + }, +}); + +export { PropertySchema, softRemoveProperty }; diff --git a/app/imports/api/creature/properties/Rolls.js b/app/imports/api/creature/properties/Rolls.js index 892c0285..2d498300 100644 --- a/app/imports/api/creature/properties/Rolls.js +++ b/app/imports/api/creature/properties/Rolls.js @@ -1,6 +1,5 @@ import SimpleSchema from 'simpl-schema'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js'; import StoredBuffSchema from '/imports/api/creature/properties/Buffs.js'; @@ -9,14 +8,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,17 +88,12 @@ 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); Rolls.attachSchema(PropertySchema); -Rolls.attachSchema(ChildSchema); const insertRoll = new ValidatedMethod({ name: 'Rolls.methods.insert', @@ -123,18 +115,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..7a1404af 100644 --- a/app/imports/api/creature/properties/Skills.js +++ b/app/imports/api/creature/properties/Skills.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js'; // Mixins @@ -10,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 Skills = new Mongo.Collection("skills"); @@ -101,7 +102,6 @@ let ComputedSkillSchema = schema({ Skills.attachSchema(ComputedSkillSchema); Skills.attachSchema(PropertySchema); -Skills.attachSchema(ChildSchema); const insertSkill = new ValidatedMethod({ name: 'Skills.methods.insert', @@ -124,18 +124,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..b5f8a5d9 100644 --- a/app/imports/api/creature/properties/SpellLists.js +++ b/app/imports/api/creature/properties/SpellLists.js @@ -1,14 +1,15 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js"; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' // Mixins 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 SpellLists = new Mongo.Collection("spellLists"); @@ -42,7 +43,6 @@ SpellListSchema.extend(ColorSchema); SpellLists.attachSchema(SpellListSchema); SpellLists.attachSchema(PropertySchema); -SpellLists.attachSchema(ChildSchema); const insertSpellList = new ValidatedMethod({ name: 'SpellLists.methods.insert', @@ -64,18 +64,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..8290fc0d 100644 --- a/app/imports/api/creature/properties/Spells.js +++ b/app/imports/api/creature/properties/Spells.js @@ -1,14 +1,15 @@ import ColorSchema from '/imports/api/creature/subSchemas/ColorSchema.js'; import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; -import ChildSchema from '/imports/api/parenting/ChildSchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' // Mixins 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'; const magicSchools = [ 'Abjuration', @@ -28,11 +29,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, @@ -86,7 +94,6 @@ SpellSchema.extend(ColorSchema); Spells.attachSchema(SpellSchema); Spells.attachSchema(PropertySchema); -Spells.attachSchema(ChildSchema); const insertSpell = new ValidatedMethod({ name: 'Spells.methods.insert', @@ -108,18 +115,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/creature/subSchemas/ColorSchema.js b/app/imports/api/creature/subSchemas/ColorSchema.js index e0b74c61..f258c269 100644 --- a/app/imports/api/creature/subSchemas/ColorSchema.js +++ b/app/imports/api/creature/subSchemas/ColorSchema.js @@ -1,22 +1,12 @@ import SimpleSchema from 'simpl-schema'; -const getColorSchema = function({optional = true} = {}){ - let schema = { +const ColorSchema = new SimpleSchema({ + color: { type: String, // match hex colors of the form #A23 or #A23f56 regEx: /^#([a-f0-9]{3}){1,2}\b$/i, - }; - if (optional) { - schema.optional = true; - } else { - schema.defaultValue = "#9E9E9E"; - } - return schema -}; - -const ColorSchema = new SimpleSchema({ - color: getColorSchema(), + optional: true, + }, }); export default ColorSchema; -export { getColorSchema }; diff --git a/app/imports/api/creature/subSchemas/PropertySchema.js b/app/imports/api/creature/subSchemas/PropertySchema.js deleted file mode 100644 index c1126787..00000000 --- a/app/imports/api/creature/subSchemas/PropertySchema.js +++ /dev/null @@ -1,27 +0,0 @@ -import SimpleSchema from 'simpl-schema'; -import SoftRemovableSchema from '/imports/api/parenting/SoftRemovableSchema.js'; - -const PropertySchema = new SimpleSchema({ - charId: { - type: String, - regEx: SimpleSchema.RegEx.Id, - index: 1, - optional: true, - }, - enabled: { - type: Boolean, - defaultValue: true, - }, - name: { - type: String, - optional: true, - }, - order: { - type: SimpleSchema.Integer, - index: true, - }, -}); - -PropertySchema.extend(SoftRemovableSchema); - -export default PropertySchema; diff --git a/app/imports/api/inventory/Containers.js b/app/imports/api/inventory/Containers.js index 98ac4bf5..efd13b41 100644 --- a/app/imports/api/inventory/Containers.js +++ b/app/imports/api/inventory/Containers.js @@ -1,7 +1,7 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js"; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import ChildSchema from '/imports/api/parenting/ChildSchema.js'; //set up the collection for containers diff --git a/app/imports/api/inventory/Items.js b/app/imports/api/inventory/Items.js index c704b942..a87291f1 100644 --- a/app/imports/api/inventory/Items.js +++ b/app/imports/api/inventory/Items.js @@ -1,7 +1,7 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js"; -import PropertySchema from '/imports/api/creature/subSchemas/PropertySchema.js'; +import { PropertySchema } from '/imports/api/creature/properties/Properties.js' import ChildSchema from '/imports/api/parenting/ChildSchema.js'; Items = new Mongo.Collection("items"); diff --git a/app/imports/api/mixins/setDocToLastMixin.js b/app/imports/api/mixins/setDocToLastMixin.js index 1b31b90d..db056d9b 100644 --- a/app/imports/api/mixins/setDocToLastMixin.js +++ b/app/imports/api/mixins/setDocToLastMixin.js @@ -8,12 +8,12 @@ export function setDocToLastMixin(methodOptions){ if (methodOptions.validate){ throw new Meteor.Error(`setDocToLastMixin should come before simpleSchemaMixin`); } - methodOptions.schema.extend({ + methodOptions.schema = new SimpleSchema({ charId: { type: String, regEx: SimpleSchema.RegEx.Id, }, - }); + }).extend(methodOptions.schema); let collection = methodOptions.collection; if (!collection){ throw new Meteor.Error("`collection` required in method options for setDocToLastMixin"); diff --git a/app/imports/api/mixins/updateSchemaMixin.js b/app/imports/api/mixins/updateSchemaMixin.js index 2e840492..9f6d52b5 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,16 +42,26 @@ 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 methodOptions.validate = function(args){ argumentSchema.validate(args); - updateSchema.validate(args.update, methodOptions.schemaValidatorOptions); + updateSchema.validate( + {$set: 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; } diff --git a/app/imports/api/parenting/ChildSchema.js b/app/imports/api/parenting/ChildSchema.js index 10500921..badd8219 100644 --- a/app/imports/api/parenting/ChildSchema.js +++ b/app/imports/api/parenting/ChildSchema.js @@ -1,15 +1,7 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -const RefSchema = new SimpleSchema({ - id: { - type: String, - regEx: SimpleSchema.RegEx.Id, - index: 1 - }, - collection: { - type: String - }, +const inhertitedFieldsSchema = new SimpleSchema({ name: { type: String, optional: true, @@ -21,6 +13,19 @@ const RefSchema = new SimpleSchema({ }, }); +const RefSchema = new SimpleSchema({ + id: { + type: String, + regEx: SimpleSchema.RegEx.Id, + index: 1 + }, + collection: { + type: String + }, +}); + +RefSchema.extend(inhertitedFieldsSchema); + let ChildSchema = schema({ parent: { type: RefSchema, @@ -35,9 +40,7 @@ let ChildSchema = schema({ }, }); -const inheritedFields = new Set(RefSchema.objectKeys()); -inheritedFields.delete('id'); -inheritedFields.delete('collection'); +const inheritedFields = new Set(inhertitedFieldsSchema.objectKeys()); export default ChildSchema; export { inheritedFields }; diff --git a/app/imports/api/parenting/fetchDocByRef.js b/app/imports/api/parenting/fetchDocByRef.js index 23766707..dfa485dc 100644 --- a/app/imports/api/parenting/fetchDocByRef.js +++ b/app/imports/api/parenting/fetchDocByRef.js @@ -9,4 +9,4 @@ const docNotFoundError = function({id, collection}){ export default function fetchDocByRef({id, collection}, options){ return getCollectionByName(collection).findOne(id, options) || docNotFoundError({id, collection}); -}; +} diff --git a/app/imports/api/parenting/parenting.js b/app/imports/api/parenting/parenting.js index 88bba7f0..04fd6a4e 100644 --- a/app/imports/api/parenting/parenting.js +++ b/app/imports/api/parenting/parenting.js @@ -81,7 +81,7 @@ export function getAncestry({id, collection}){ }; // Ancestors is [...parent's ancestors, parent ref] - let ancestors = parentDoc.ancestors; + let ancestors = parentDoc.ancestors || []; ancestors.push(parent); return {parent, ancestors}; @@ -90,9 +90,10 @@ export function getAncestry({id, collection}){ export function setDocAncestryMixin(methodOptions){ // Extend the method's schema to require the needed properties // This mixin should come before simpleschema mixin - methodOptions.schema.extend({ + methodOptions.schema = new SimpleSchema({ parent: { type: Object, + optional: true, }, 'parent.id': { type: String, @@ -101,10 +102,14 @@ export function setDocAncestryMixin(methodOptions){ 'parent.collection': { type: String, }, - }); + }).extend(methodOptions.schema); // Change the doc's ancestry before running let runFunc = methodOptions.run; methodOptions.run = function(doc, ...rest){ + // If the doc's parent doesn't exist, set it to the character + if (!doc.parent && doc.charId) { + doc.parent = {id: doc.charId, collection: 'creatures'}; + } let {parent, ancestors} = getAncestry(doc.parent); doc.parent = parent; doc.ancestors = ancestors; @@ -137,12 +142,12 @@ function ensureAncestryContainsId(ancestors, id){ export function ensureAncestryContainsCharIdMixin(methodOptions){ // Extend the method's schema to require the needed properties // This mixin should come before simpleSchemaMixin - methodOptions.schema.extend({ + methodOptions.schema = new SimpleSchema({ charId: { type: String, regEx: SimpleSchema.RegEx.Id, }, - }); + }).extend(methodOptions.schema); let runFunc = methodOptions.run; methodOptions.run = function({charId, ancestors}){ ensureAncestryContainsId(ancestors, charId); diff --git a/app/imports/api/parenting/softRemove.js b/app/imports/api/parenting/softRemove.js index a64053de..71eb3b18 100644 --- a/app/imports/api/parenting/softRemove.js +++ b/app/imports/api/parenting/softRemove.js @@ -2,11 +2,11 @@ import getCollectionByName from '/imports/api/parenting/getCollectionByName.js'; import updateDecendents from '/imports/api/parenting/parenting.js'; // 1 + n database hits -export function softRemove({id, collection}){ +export function softRemove({_id, collection}){ let removalDate = new Date(); // Remove this document collection = getCollectionByName(collection); - collection.update(id, {$set: { + collection.update(_id, {$set: { removed: true, removedAt: removalDate, }, $unset: { @@ -15,15 +15,15 @@ export function softRemove({id, collection}){ // Remove all the decendents that have not yet been removed, and set them to be // removed with this document updateDecendents({ - ancestorId: id, + ancestorId: _id, filter: {removed: {$ne: true}}, modifier: {$set: { removed: true, removedAt: removalDate, - removedWith: id, + removedWith: _id, }}, }); -}; +} const restoreError = function(){ throw new Meteor.Error('restore-failed', @@ -31,10 +31,10 @@ const restoreError = function(){ ); }; -export function restore({id, collection}){ +export function restore({_id, collection}){ collection = getCollectionByName(collection); let numUpdated = collection.update({ - _id: id, + _id, removedWith: {$exists: false} }, { $unset: { removed: 1, @@ -42,9 +42,9 @@ export function restore({id, collection}){ }}); if (numUpdated === 0) restoreError(); updateDecendents({ - ancestorId: id, + ancestorId: _id, filter: { - removedWith: id, + removedWith: _id, }, modifier: { $unset: { removed: 1, diff --git a/app/imports/api/schema.js b/app/imports/api/schema.js index 4ec13855..de1f8fe9 100644 --- a/app/imports/api/schema.js +++ b/app/imports/api/schema.js @@ -1,7 +1,7 @@ import SimpleSchema from 'simpl-schema'; -function getDefaultSchema(){ - return new SimpleSchema({}, { +export default function schema(options){ + return new SimpleSchema(options, { clean: { filter: true, autoConvert: true, @@ -11,8 +11,4 @@ function getDefaultSchema(){ removeNullsFromArrays: true, }, }); -}; - -export default function schema(options){ - return getDefaultSchema().extend(options); -}; +} diff --git a/app/imports/ui/character/FeaturesTab.vue b/app/imports/ui/character/FeaturesTab.vue index f05ca9f3..7ffd4dbe 100644 --- a/app/imports/ui/character/FeaturesTab.vue +++ b/app/imports/ui/character/FeaturesTab.vue @@ -3,8 +3,10 @@
@@ -21,11 +23,11 @@ diff --git a/app/imports/ui/components/MarkdownText.vue b/app/imports/ui/components/MarkdownText.vue new file mode 100644 index 00000000..1d2ffc06 --- /dev/null +++ b/app/imports/ui/components/MarkdownText.vue @@ -0,0 +1,20 @@ + + + diff --git a/app/imports/ui/components/ToolbarCard.vue b/app/imports/ui/components/ToolbarCard.vue index a26a0501..69f3cda4 100644 --- a/app/imports/ui/components/ToolbarCard.vue +++ b/app/imports/ui/components/ToolbarCard.vue @@ -1,15 +1,15 @@