Started working on getting creature property insertion working
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
||||
import propertySchemas from '/imports/api/properties/propertySchemas.js';
|
||||
import Libraries from '/imports/api/library/Libraries.js';
|
||||
import Creature from '/imports/api/creature/Creatures.js';
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||
import getModifierFields from '/imports/api/getModifierFields.js';
|
||||
import propertySchemasIndex from '/imports/api/properties/propertySchemasIndex.js';
|
||||
|
||||
let CreatureProperties = new Mongo.Collection('creatureProperties');
|
||||
|
||||
let CreaturePropertySchema = new SimpleSchema({
|
||||
type: {
|
||||
type: String,
|
||||
allowedValues: Object.keys(propertySchemas),
|
||||
allowedValues: Object.keys(propertySchemasIndex),
|
||||
},
|
||||
charId: {
|
||||
type: String,
|
||||
@@ -20,9 +19,9 @@ let CreaturePropertySchema = new SimpleSchema({
|
||||
},
|
||||
});
|
||||
|
||||
for (let key in propertySchemas){
|
||||
for (let key in propertySchemasIndex){
|
||||
let schema = new SimpleSchema({});
|
||||
schema.extend(propertySchemas[key]);
|
||||
schema.extend(propertySchemasIndex[key]);
|
||||
schema.extend(CreaturePropertySchema);
|
||||
schema.extend(ChildSchema);
|
||||
CreatureProperties.attachSchema(schema, {
|
||||
@@ -30,6 +29,28 @@ for (let key in propertySchemas){
|
||||
});
|
||||
}
|
||||
|
||||
function getCreature(property){
|
||||
if (!property) throw new Meteor.Error('No property provided');
|
||||
let creature = Creatures.findOne(property.ancestors[0].id);
|
||||
if (!creature) throw new Meteor.Error('Creature does not exist');
|
||||
return creature;
|
||||
}
|
||||
|
||||
function assertPropertyEditPermission(property, userId){
|
||||
let creature = getCreature(property);
|
||||
return assertEditPermission(creature, userId);
|
||||
}
|
||||
|
||||
const insertProperty = new ValidatedMethod({
|
||||
name: 'CreatureProperties.methods.insert',
|
||||
validate: null,
|
||||
run(creatureProperty) {
|
||||
assertPropertyEditPermission(creatureProperty, this.userId);
|
||||
return CreatureProperties.insert(creatureProperty);
|
||||
},
|
||||
});
|
||||
|
||||
/*
|
||||
const adjustAttribute = new ValidatedMethod({
|
||||
name: 'Attributes.methods.adjust',
|
||||
mixins: [
|
||||
@@ -73,6 +94,7 @@ const adjustAttribute = new ValidatedMethod({
|
||||
}
|
||||
},
|
||||
});
|
||||
*/
|
||||
|
||||
export default CreatureProperties;
|
||||
export { CreaturePropertySchema};
|
||||
export { CreaturePropertySchema, insertProperty };
|
||||
|
||||
@@ -50,38 +50,10 @@ let CreatureSchema = new SimpleSchema({
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
race: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
picture: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
personality: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
ideals: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
bonds: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
flaws: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
backstory: {
|
||||
type: String,
|
||||
optional: true
|
||||
},
|
||||
|
||||
// Mechanics
|
||||
deathSave: {
|
||||
@@ -105,8 +77,6 @@ let CreatureSchema = new SimpleSchema({
|
||||
defaultValue: "pc",
|
||||
allowedValues: ["pc", "npc", "monster"],
|
||||
},
|
||||
|
||||
// Computed
|
||||
variables: {
|
||||
type: Object,
|
||||
blackbox: true,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import ChildSchema from '/imports/api/parenting/ChildSchema.js';
|
||||
import librarySchemas from '/imports/api/library/librarySchemas.js';
|
||||
import propertySchemasIndex from '/imports/api/properties/propertySchemasIndex.js';
|
||||
import Libraries from '/imports/api/library/Libraries.js';
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions.js';
|
||||
import { softRemove } from '/imports/api/parenting/softRemove.js';
|
||||
@@ -11,14 +11,14 @@ let LibraryNodes = new Mongo.Collection('libraryNodes');
|
||||
let LibraryNodeSchema = new SimpleSchema({
|
||||
type: {
|
||||
type: String,
|
||||
allowedValues: Object.keys(librarySchemas),
|
||||
allowedValues: Object.keys(propertySchemasIndex),
|
||||
},
|
||||
});
|
||||
|
||||
for (let key in librarySchemas){
|
||||
for (let key in propertySchemasIndex){
|
||||
let schema = new SimpleSchema({});
|
||||
schema.extend(LibraryNodeSchema);
|
||||
schema.extend(librarySchemas[key]);
|
||||
schema.extend(propertySchemasIndex[key]);
|
||||
schema.extend(ChildSchema);
|
||||
schema.extend(SoftRemovableSchema);
|
||||
LibraryNodes.attachSchema(schema, {
|
||||
@@ -112,36 +112,6 @@ const softRemoveLibraryNode = new ValidatedMethod({
|
||||
}
|
||||
});
|
||||
|
||||
function libraryNodesToTree(ancestorId){
|
||||
// Store a dict of all the nodes
|
||||
let nodeIndex = {};
|
||||
let nodeList = [];
|
||||
LibraryNodes.find({
|
||||
'ancestors.id': ancestorId,
|
||||
removed: {$ne: true},
|
||||
}, {
|
||||
sort: {order: 1}
|
||||
}).forEach( node => {
|
||||
let treeNode = {
|
||||
node: node,
|
||||
children: [],
|
||||
};
|
||||
nodeIndex[node._id] = treeNode;
|
||||
nodeList.push(treeNode);
|
||||
});
|
||||
// Create a forest of trees
|
||||
let forest = [];
|
||||
// Either the node is a child of another node, or in the forest as a root
|
||||
nodeList.forEach(node => {
|
||||
if (nodeIndex[node.node.parent.id]){
|
||||
nodeIndex[node.node.parent.id].children.push(node);
|
||||
} else {
|
||||
forest.push(node);
|
||||
}
|
||||
});
|
||||
return forest;
|
||||
}
|
||||
|
||||
export default LibraryNodes;
|
||||
export {
|
||||
LibraryNodeSchema,
|
||||
|
||||
@@ -165,3 +165,33 @@ export function getName(doc){
|
||||
if (ancestors[i].name) return ancestors[i].name;
|
||||
}
|
||||
}
|
||||
|
||||
export function nodesToTree({collection, ancestorId}){
|
||||
// Store a dict of all the nodes
|
||||
let nodeIndex = {};
|
||||
let nodeList = [];
|
||||
collection.find({
|
||||
'ancestors.id': ancestorId,
|
||||
removed: {$ne: true},
|
||||
}, {
|
||||
sort: {order: 1}
|
||||
}).forEach( node => {
|
||||
let treeNode = {
|
||||
node: node,
|
||||
children: [],
|
||||
};
|
||||
nodeIndex[node._id] = treeNode;
|
||||
nodeList.push(treeNode);
|
||||
});
|
||||
// Create a forest of trees
|
||||
let forest = [];
|
||||
// Either the node is a child of another node, or in the forest as a root
|
||||
nodeList.forEach(node => {
|
||||
if (nodeIndex[node.node.parent.id]){
|
||||
nodeIndex[node.node.parent.id].children.push(node);
|
||||
} else {
|
||||
forest.push(node);
|
||||
}
|
||||
});
|
||||
return forest;
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
import { ActionSchema } from '/imports/api/properties/Actions.js';
|
||||
import { AttackSchema } from '/imports/api/properties/Attacks.js';
|
||||
import { AttributeSchema } from '/imports/api/properties/Attributes.js';
|
||||
import { StoredBuffSchema } from '/imports/api/properties/Buffs.js';
|
||||
import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js';
|
||||
import { DamageMultiplierSchema } from '/imports/api/properties/DamageMultipliers.js';
|
||||
import { EffectSchema } from '/imports/api/properties/Effects.js';
|
||||
import { ExperienceSchema } from '/imports/api/properties/Experiences.js';
|
||||
import { FeatureSchema } from '/imports/api/properties/Features.js';
|
||||
import { FolderSchema } from '/imports/api/properties/Folders.js';
|
||||
import { NoteSchema } from '/imports/api/properties/Notes.js';
|
||||
import { ProficiencySchema } from '/imports/api/properties/Proficiencies.js';
|
||||
import { RollSchema } from '/imports/api/properties/Rolls.js';
|
||||
import { SavingThrowSchema } from '/imports/api/properties/SavingThrows.js';
|
||||
import { SkillSchema } from '/imports/api/properties/Skills.js';
|
||||
import { SpellListSchema } from '/imports/api/properties/SpellLists.js';
|
||||
import { SpellSchema } from '/imports/api/properties/Spells.js';
|
||||
import { ContainerSchema } from '/imports/api/properties/Containers.js';
|
||||
import { ItemSchema } from '/imports/api/properties/Items.js';
|
||||
|
||||
const propertySchemas = {
|
||||
action: ActionSchema,
|
||||
attack: AttackSchema,
|
||||
attribute: AttributeSchema,
|
||||
buff: StoredBuffSchema,
|
||||
classLevel: ClassLevelSchema,
|
||||
damageMultiplier: DamageMultiplierSchema,
|
||||
effect: EffectSchema,
|
||||
experience: ExperienceSchema,
|
||||
feature: FeatureSchema,
|
||||
folder: FolderSchema,
|
||||
note: NoteSchema,
|
||||
proficiency: ProficiencySchema,
|
||||
roll: RollSchema,
|
||||
savingThrow: SavingThrowSchema,
|
||||
skill: SkillSchema,
|
||||
spellList: SpellListSchema,
|
||||
spell: SpellSchema,
|
||||
container: ContainerSchema,
|
||||
item: ItemSchema,
|
||||
};
|
||||
|
||||
export default propertySchemas;
|
||||
@@ -19,7 +19,7 @@ import { SpellSchema } from '/imports/api/properties/Spells.js';
|
||||
import { ContainerSchema } from '/imports/api/properties/Containers.js';
|
||||
import { ItemSchema } from '/imports/api/properties/Items.js';
|
||||
|
||||
const librarySchemas = {
|
||||
const propertySchemasIndex = {
|
||||
action: ActionSchema,
|
||||
attack: AttackSchema,
|
||||
attribute: AttributeSchema,
|
||||
@@ -42,4 +42,4 @@ const librarySchemas = {
|
||||
any: new SimpleSchema({}),
|
||||
};
|
||||
|
||||
export default librarySchemas;
|
||||
export default propertySchemasIndex;
|
||||
Reference in New Issue
Block a user