Refactored character insertion and continued work on creation dialog
This commit is contained in:
39
app/imports/api/creature/insertCreature.js
Normal file
39
app/imports/api/creature/insertCreature.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import getDefaultCreatureDocs from '/imports/api/creature/getDefaultCreatureDocs.js';
|
||||
|
||||
const addDefaultStats = function(charId){
|
||||
const defaultDocs = getDefaultCreatureDocs(charId);
|
||||
Attributes.rawCollection().insert(getDefa.attributes, {ordered: false});
|
||||
Skills.rawCollection().insert(getDefa.skills, {ordered: false});
|
||||
DamageMultipliers.rawCollection().insert(getDefa.damageMultipliers, {ordered: false});
|
||||
};
|
||||
|
||||
const insertCreature = new ValidatedMethod({
|
||||
|
||||
name: "Creatures.methods.insertCharacter", // DDP method name
|
||||
|
||||
validate: new SimpleSchema({
|
||||
name: {
|
||||
type: String,
|
||||
optional: true,
|
||||
},
|
||||
}).validator(),
|
||||
|
||||
run({name}) {
|
||||
if (!this.userId) {
|
||||
throw new Meteor.Error("Creatures.methods.insert.denied",
|
||||
"You need to be logged in to insert a creature");
|
||||
}
|
||||
|
||||
// Create the creature document
|
||||
let charId = Creatures.insert({name, owner: this.userId});
|
||||
this.unblock();
|
||||
//Add all the required attributes to it
|
||||
if (Meteor.isServer){
|
||||
addDefaultStats(charId);
|
||||
}
|
||||
return charId;
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
export default insertCreature;
|
||||
Reference in New Issue
Block a user