Started working on getting creature property insertion working

This commit is contained in:
Stefan Zermatten
2019-09-27 11:06:33 +02:00
parent 73f193460d
commit f4d613a20b
22 changed files with 437 additions and 282 deletions

View File

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

View File

@@ -1,45 +0,0 @@
import SimpleSchema from 'simpl-schema';
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 { SkillSchema } from '/imports/api/properties/Skills.js';
import { SavingThrowSchema } from '/imports/api/properties/SavingThrows.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 librarySchemas = {
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,
any: new SimpleSchema({}),
};
export default librarySchemas;