Renamed Characters to Creatures

This commit is contained in:
Stefan Zermatten
2018-10-12 08:52:14 +02:00
parent d330e15dce
commit b2eed9a672

View File

@@ -1,9 +1,9 @@
import { ValidatedMethod } from 'meteor/mdg:validated-method'; import { ValidatedMethod } from 'meteor/mdg:validated-method';
//set up the collection for characters //set up the collection for creatures
Characters = new Mongo.Collection("characters"); Creatures = new Mongo.Collection("creatures");
Schemas.Character = new SimpleSchema({ Schemas.Creature = new SimpleSchema({
//strings //strings
name: {type: String, defaultValue: "", trim: false, optional: true}, name: {type: String, defaultValue: "", trim: false, optional: true},
urlName: {type: String, defaultValue: "-", trim: false, optional: true}, urlName: {type: String, defaultValue: "-", trim: false, optional: true},
@@ -34,7 +34,7 @@ Schemas.Character = new SimpleSchema({
allowedValues: _.pluck(colorOptions, "key"), allowedValues: _.pluck(colorOptions, "key"),
defaultValue: "q", defaultValue: "q",
}, },
//TODO add per-character settings //TODO add per-creature settings
//how many experiences to load at a time in XP table //how many experiences to load at a time in XP table
"settings.experiencesInc": {type: Number, defaultValue: 20}, "settings.experiencesInc": {type: Number, defaultValue: 20},
//slowed down by carrying too much? //slowed down by carrying too much?
@@ -56,11 +56,11 @@ Schemas.Character = new SimpleSchema({
"settings.newUserExperience": {type: Boolean, optional: true}, "settings.newUserExperience": {type: Boolean, optional: true},
}); });
Characters.attachSchema(Schemas.Character); Creatures.attachSchema(Schemas.Creature);
Characters.calculate = { Creatures.calculate = {
xpLevel: function(charId){ xpLevel: function(charId){
var xp = Characters.calculate.experience(charId); var xp = Creatures.calculate.experience(charId);
for (var i = 0; i < 19; i++){ for (var i = 0; i < 19; i++){
if (xp < XP_TABLE[i]){ if (xp < XP_TABLE[i]){
return i; return i;
@@ -71,9 +71,9 @@ Characters.calculate = {
}, },
}; };
const insertCharacterMethod = new ValidatedMethod({ const insertCreatureMethod = new ValidatedMethod({
name: "Characters.methods.insert", // DDP method name name: "Creatures.methods.insert", // DDP method name
validate: new SimpleSchema({ validate: new SimpleSchema({
name: { name: {
@@ -84,12 +84,12 @@ const insertCharacterMethod = new ValidatedMethod({
run({name}) { run({name}) {
if (!this.userId) { if (!this.userId) {
throw new Meteor.Error("Characters.methods.insert.denied", throw new Meteor.Error("Creatures.methods.insert.denied",
"You need to be logged in to insert a character"); "You need to be logged in to insert a creature");
} }
// Create the character document // Create the creature document
Characters.insert({name, owner: this.userId}); Creatures.insert({name, owner: this.userId});
this.unblock(); this.unblock();
//Add all the required attributes to it //Add all the required attributes to it
if (Meteor.isServer){ if (Meteor.isServer){
@@ -100,16 +100,16 @@ const insertCharacterMethod = new ValidatedMethod({
}); });
const addDefaultStats = function(charId){ const addDefaultStats = function(charId){
const defaultDocs = getDefaultCharacterDocs(charId); const defaultDocs = getDefaultCreatureDocs(charId);
Attributes.rawCollection().insert(defaultDocs.attributes, {ordered: false}); Attributes.rawCollection().insert(defaultDocs.attributes, {ordered: false});
Skills.rawCollection().insert(defaultDocs.skills, {ordered: false}); Skills.rawCollection().insert(defaultDocs.skills, {ordered: false});
DamageMultipliers.rawCollection().insert(defaultDocs.damageMultipliers, {ordered: false}); DamageMultipliers.rawCollection().insert(defaultDocs.damageMultipliers, {ordered: false});
}; };
//clean up all data related to that character before removing it //clean up all data related to that creature before removing it
if (Meteor.isServer){ if (Meteor.isServer){
Characters.after.remove(function(userId, character) { Creatures.after.remove(function(userId, creature) {
let charId = character._id; let charId = creature._id;
Actions .remove({charId}); Actions .remove({charId});
Attacks .remove({charId}); Attacks .remove({charId});
Attributes .remove({charId}); Attributes .remove({charId});
@@ -127,22 +127,22 @@ if (Meteor.isServer){
Items .remove({charId}); Items .remove({charId});
Containers .remove({charId}); Containers .remove({charId});
}); });
Characters.after.update(function(userId, doc, fieldNames, modifier, options) { Creatures.after.update(function(userId, doc, fieldNames, modifier, options) {
if (_.contains(fieldNames, "name")){ if (_.contains(fieldNames, "name")){
var urlName = getSlug(doc.name, {maintainCase: true}) || "-"; var urlName = getSlug(doc.name, {maintainCase: true}) || "-";
Characters.update(doc._id, {$set: {urlName}}); Creatures.update(doc._id, {$set: {urlName}});
} }
}); });
Characters.before.insert(function(userId, doc) { Creatures.before.insert(function(userId, doc) {
doc.urlName = getSlug(doc.name, {maintainCase: true}) || "-"; doc.urlName = getSlug(doc.name, {maintainCase: true}) || "-";
// The first character a user creates should have the new user experience // The first creature a user creates should have the new user experience
if (!Characters.find({owner: userId}).count()){ if (!Creatures.find({owner: userId}).count()){
doc.settings.newUserExperience = true; doc.settings.newUserExperience = true;
} }
}); });
} }
Characters.allow({ Creatures.allow({
insert: function(userId, doc) { insert: function(userId, doc) {
// the user must be logged in, and the document must be owned by the user // the user must be logged in, and the document must be owned by the user
return (userId && doc.owner === userId); return (userId && doc.owner === userId);
@@ -159,7 +159,7 @@ Characters.allow({
fetch: ["owner", "writers"], fetch: ["owner", "writers"],
}); });
Characters.deny({ Creatures.deny({
update: function(userId, docs, fields, modifier) { update: function(userId, docs, fields, modifier) {
// can't change owners // can't change owners
return _.contains(fields, "owner"); return _.contains(fields, "owner");