Completed the stats tab, conditions not added yet

This commit is contained in:
Stefan Zermatten
2019-01-21 16:03:05 +02:00
parent e43718f034
commit 60dfba3b46
13 changed files with 310 additions and 49 deletions

View File

@@ -38,6 +38,9 @@ export default () => ({
{"name": "Level 8 Spell Slots", "variableName": "level8SpellSlots", "type": "spellSlot"},
{"name": "Level 9 Spell Slots", "variableName": "level9SpellSlots", "type": "spellSlot"},
{"name": "Proficiency Bonus", "variableName": "proficiencyBonus", "type": "modifier"},
{"name": "initiative", "variableName": "initiative", "type": "modifier"},
{"name": "Carry Capacity Multiplier", "variableName": "carryMultiplier", "type": "utility", "baseValue": 1},
{"name": "Rage Damage", "variableName": "rageDamage", "type": "utility"},
],
@@ -68,9 +71,6 @@ export default () => ({
{"name": "Intelligence Save", "variableName": "intelligenceSave", "ability": "intelligence", "type":"save"},
{"name": "Wisdom Save", "variableName": "wisdomSave", "ability": "wisdom", "type":"save"},
{"name": "Charisma Save", "variableName": "charismaSave", "ability": "charisma", "type":"save"},
{"name": "Proficiency Bonus", "variableName": "proficiencyBonus", "type": "stat"},
{"name": "initiative", "variableName": "initiative", "type": "stat"},
],
"damageMultipliers": [

View File

@@ -2,10 +2,16 @@
// on them disadvantaged as well
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import SimpleSchema from 'simpl-schema';
import Creatures from "/imports/api/creature/Creatures.js";
import Attributes from "/imports/api/creature/Attributes.js";
import Skills from "/imports/api/creature/Skills.js";
import Effects from "/imports/api/creature/Effects.js";
import Attributes from "/imports/api/creature/properties/Attributes.js";
import Skills from "/imports/api/creature/properties/Skills.js";
import Effects from "/imports/api/creature/properties/Effects.js";
import DamageMultipliers from "/imports/api/creature/properties/DamageMultipliers.js";
import Classes from "/imports/api/creature/properties/Classes.js";
// TODO, just checks that a charId is given
const canEditCreature = charId => !!charId;
export const recomputeCreature = new ValidatedMethod({
@@ -70,7 +76,7 @@ export const recomputeCreature = new ValidatedMethod({
* computed and written to the database
*/
function computeCreatureById(charId){
let char = buildCreature();
let char = buildCreature(charId);
char = computeCreature(char);
writeCreature(char);
return char;
@@ -109,19 +115,21 @@ function writeAttributes(char) {
}},
}
}
if (att.mod){
op.updateMany.update.mod = att.mod;
if (typeof att.mod === 'number'){
op.updateMany.update.$set.mod = att.mod;
}
return op;
});
if (Meteor.isServer){
Attributes.rawCollection().bulkWrite( bulkWriteOps, {ordered : false});
Attributes.rawCollection().bulkWrite(bulkWriteOps, {ordered : false}, function(e, r){
if (e) console.warn(JSON.stringify(e, null, 2))
});
} else {
_.each(bulkWriteOps, op => {
Attributes.update(op.updateMany.filter, op.updateMany.update, {multi: true});
});
}
}
};
@@ -149,13 +157,15 @@ function writeSkills(char) {
return op;
});
if (Meteor.isServer){
Skills.rawCollection().bulkWrite( bulkWriteOps, {ordered : false});
Skills.rawCollection().bulkWrite( bulkWriteOps, {ordered : false}, function(e, r){
if (e) console.warn(JSON.stringify(e, null, 2))
});
} else {
_.each(bulkWriteOps, op => {
Skills.update(op.updateMany.filter, op.updateMany.update, {multi: true});
});
}
}
};
/**
* Write all the damange multipliers from the in-memory char object to the docs
@@ -176,13 +186,15 @@ function writeDamageMultipliers(char) {
return op;
});
if (Meteor.isServer){
DamageMultipliers.rawCollection().bulkWrite( bulkWriteOps, {ordered : false});
DamageMultipliers.rawCollection().bulkWrite( bulkWriteOps, {ordered : false}, function(e, r){
if (e) console.warn(JSON.stringify(e, null, 2))
});
} else {
_.each(bulkWriteOps, op => {
DamageMultipliers.update(op.updateMany.filter, op.updateMany.update, {multi: true});
});
}
}
};
/**
@@ -307,7 +319,7 @@ function buildCreature(charId){
}
});
return char;
}
};
/**
@@ -330,7 +342,7 @@ export function computeCreature(char){
computeStat (stat, char);
}
return char;
}
};
/**

View File

@@ -1,4 +1,5 @@
import DEFAULT_CHARACTER_DOCS from '/imports/api/creature/DEFAULT_CHARACTER_DOCS.js';
import { Random } from 'meteor/random';
const setParent = function(charId){
let parent = {
@@ -27,9 +28,12 @@ const getRacialBonusEffect = function(charId, attribute, bonus){
};
};
const giveDocsOrder = function(docArray){
const giveDocsOrderAndIds = function(docArray){
for (i in docArray){
docArray[i].order = +i;
if (!docArray[i]._id){
docArray[i]._id = Random.id();
}
}
};
@@ -164,7 +168,7 @@ const getDefaultCharacterDocs = function(charId, {
// Order the docs
for (collection in docs){
giveDocsOrder(docs[collection]);
giveDocsOrderAndIds(docs[collection]);
}
return docs

View File

@@ -5,7 +5,7 @@ import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js";
let Attributes = new Mongo.Collection("attributes");
/*
* Attributes are whole numbered stats of a character
* Attributes are numbered stats of a character
*/
attributeSchema = new SimpleSchema({
charId: {
@@ -32,7 +32,8 @@ attributeSchema = new SimpleSchema({
allowedValues: [
"ability", //Strength, Dex, Con, etc.
"stat", // Speed, Armor Class
"hitDice",
"modifier", // Proficiency Bonus, Initiative
"hitDice", // d12 hit dice
"healthBar", // Hitpoints, Temporary Hitpoints
"resource", // Rages, sorcery points
"spellSlot", // Level 1, 2, 3... spell slots

View File

@@ -71,15 +71,11 @@ let skillSchema = new SimpleSchema({
type: SimpleSchema.Integer,
optional: true,
},
enabled: {
type: Boolean,
defaultValue: true,
},
});
Skills.attachSchema(skillSchema);
//Skills.attachBehaviour("softRemovable");
makeChild(Skills, ["enabled"]); //children of lots of things
makeChild(Skills); //children of lots of things
export default Skills;