Merge branch 'version-2' of https://github.com/ThaumRystra/DiceCloud into version-2

This commit is contained in:
Thaum Rystra
2019-04-06 10:56:57 +02:00
46 changed files with 569 additions and 492 deletions

View File

@@ -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;

View File

@@ -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({

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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',
]);
},
});

View File

@@ -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);
},

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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',
]);
},
});

View File

@@ -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 };

View File

@@ -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;

View File

@@ -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',
]);
},
});

View File

@@ -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;

View File

@@ -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;

View File

@@ -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 };

View File

@@ -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;

View File

@@ -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

View File

@@ -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");

View File

@@ -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");

View File

@@ -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;
}

View File

@@ -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 };

View File

@@ -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});
};
}

View File

@@ -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);

View File

@@ -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,

View File

@@ -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);
};
}