Added Character sheet
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import Effects from "/imports/api/creature/properties/Effects.js"
|
||||
import deathSaveSchema from "/imports/api/creature/subSchemas/DeathSavesSchema.js"
|
||||
import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js";
|
||||
|
||||
//Methods
|
||||
import '/imports/api/creature/insertCreature.js';
|
||||
import '/imports/api/creature/removeCreature.js';
|
||||
|
||||
//set up the collection for creatures
|
||||
Creatures = new Mongo.Collection("creatures");
|
||||
@@ -62,27 +62,8 @@ let creatureSchema = new SimpleSchema({
|
||||
Creatures.attachSchema(creatureSchema);
|
||||
Creatures.attachSchema(ColorSchema);
|
||||
|
||||
//clean up all data related to that creature before removing it
|
||||
//Keep the urlName up to date
|
||||
if (Meteor.isServer){
|
||||
Creatures.after.remove(function(userId, creature) {
|
||||
let charId = creature._id;
|
||||
Actions .remove({charId});
|
||||
Attacks .remove({charId});
|
||||
Attributes .remove({charId});
|
||||
Buffs .remove({charId});
|
||||
Classes .remove({charId});
|
||||
CustomBuffs .remove({charId});
|
||||
DamageMultipliers.remove({charId});
|
||||
Effects .remove({charId});
|
||||
Experiences .remove({charId});
|
||||
Features .remove({charId});
|
||||
Notes .remove({charId});
|
||||
Proficiencies .remove({charId});
|
||||
Skills .remove({charId});
|
||||
SpellLists .remove({charId});
|
||||
Items .remove({charId});
|
||||
Containers .remove({charId});
|
||||
});
|
||||
Creatures.after.update(function(userId, doc, fieldNames, modifier, options) {
|
||||
if (_.contains(fieldNames, "name")){
|
||||
var urlName = getSlug(doc.name, {maintainCase: true}) || "-";
|
||||
|
||||
@@ -19,7 +19,7 @@ const addDefaultDocs = function(docs){
|
||||
|
||||
const insertCreature = new ValidatedMethod({
|
||||
|
||||
name: "Creatures.methods.insertCharacter", // DDP method name
|
||||
name: "Creatures.methods.insertCreature",
|
||||
|
||||
validate: null,
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import SimpleSchema from "simpl-schema";
|
||||
|
||||
let Bundle = new Mongo.Collection("bundle");
|
||||
let Bundles = new Mongo.Collection("bundle");
|
||||
|
||||
let attributeSchema = new SimpleSchema({
|
||||
name: String,
|
||||
|
||||
@@ -24,3 +24,5 @@ let experienceSchema = new SimpleSchema({
|
||||
Experiences.attachSchema(experienceSchema);
|
||||
|
||||
//Experiences.attachBehaviour("softRemovable");
|
||||
|
||||
export default Experiences;
|
||||
|
||||
@@ -34,3 +34,5 @@ Proficiencies.attachSchema(proficiencySchema);
|
||||
|
||||
// Proficiencies.attachBehaviour("softRemovable");
|
||||
makeChild(Proficiencies, ["enabled"]);
|
||||
|
||||
export default Proficiencies;
|
||||
|
||||
76
app/imports/api/creature/removeCreature.js
Normal file
76
app/imports/api/creature/removeCreature.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import Actions from '/imports/api/creature/properties/Actions.js';
|
||||
import Attacks from '/imports/api/creature/properties/Attacks.js';
|
||||
import Attributes from '/imports/api/creature/properties/Attributes.js';
|
||||
import Buffs from '/imports/api/creature/properties/Buffs.js';
|
||||
import Bundles from '/imports/api/creature/properties/Bundles.js';
|
||||
import Classes from '/imports/api/creature/properties/Classes.js';
|
||||
import Conditions from '/imports/api/creature/properties/Conditions.js';
|
||||
import CustomBuffs from '/imports/api/creature/properties/CustomBuffs.js';
|
||||
import DamageMultipliers from '/imports/api/creature/properties/DamageMultipliers.js';
|
||||
import Effects from '/imports/api/creature/properties/Effects.js';
|
||||
import Experiences from '/imports/api/creature/properties/Experiences.js';
|
||||
import Features from '/imports/api/creature/properties/Features.js';
|
||||
import Notes from '/imports/api/creature/properties/Notes.js';
|
||||
import Proficiencies from '/imports/api/creature/properties/Proficiencies.js';
|
||||
import Skills from '/imports/api/creature/properties/Skills.js';
|
||||
import SpellLists from '/imports/api/creature/properties/SpellLists.js';
|
||||
import Spells from '/imports/api/creature/properties/Spells.js';
|
||||
import Items from '/imports/api/inventory/Items.js';
|
||||
import Containers from '/imports/api/inventory/Containers.js';
|
||||
|
||||
const checkRemovePermissions = function(userId, charId, creature){
|
||||
// Must be logged in
|
||||
if (!userId) {
|
||||
throw new Meteor.Error("Creatures.methods.removeCreature.denied",
|
||||
"You need to be logged in to remove a creature");
|
||||
}
|
||||
|
||||
// Creature must exist
|
||||
if (!creature) {
|
||||
throw new Meteor.Error("Creatures.methods.removeCreature.denied",
|
||||
`No creature exists with the given id: ${charId}`);
|
||||
}
|
||||
|
||||
// Must be creatures owner
|
||||
if (creature.owner !== userId){
|
||||
throw new Meteor.Error("Creatures.methods.removeCreature.denied",
|
||||
"Only the owner is allowed to remove a creature, you are not the owner");
|
||||
}
|
||||
}
|
||||
|
||||
const removeRelatedDocuments = function(charId){
|
||||
Actions .remove({charId});
|
||||
Attacks .remove({charId});
|
||||
Attributes .remove({charId});
|
||||
Buffs .remove({charId});
|
||||
Bundles .remove({charId});
|
||||
Classes .remove({charId});
|
||||
Conditions .remove({charId});
|
||||
CustomBuffs .remove({charId});
|
||||
DamageMultipliers.remove({charId});
|
||||
Effects .remove({charId});
|
||||
Experiences .remove({charId});
|
||||
Features .remove({charId});
|
||||
Notes .remove({charId});
|
||||
Proficiencies .remove({charId});
|
||||
Skills .remove({charId});
|
||||
SpellLists .remove({charId});
|
||||
Spells .remove({charId});
|
||||
Items .remove({charId});
|
||||
Containers .remove({charId});
|
||||
};
|
||||
|
||||
const removeCreature = new ValidatedMethod({
|
||||
name: "Creatures.methods.removeCreature", // DDP method name
|
||||
validate: null,
|
||||
run(charId) {
|
||||
let creature = Creatures.findOne(charId);
|
||||
checkRemovePermissions(this.userId, charId, creature);
|
||||
Creatures.remove(charId);
|
||||
this.unblock();
|
||||
removeRelatedDocuments(charId);
|
||||
},
|
||||
});
|
||||
|
||||
export default removeCreature;
|
||||
Reference in New Issue
Block a user