Added simple feature UI components and insertion dialog
This commit is contained in:
@@ -36,6 +36,9 @@ let creatureSchema = schema({
|
||||
level: {type: SimpleSchema.Integer, defaultValue: 0},
|
||||
type: {type: String, defaultValue: "pc", allowedValues: ["pc", "npc", "monster"]},
|
||||
|
||||
//computed
|
||||
variables: {type: Object, blackbox: true},
|
||||
|
||||
//permissions
|
||||
owner: {type: String, regEx: SimpleSchema.RegEx.Id, index: 1},
|
||||
readers: {type: Array, defaultValue: [], index: 1},
|
||||
|
||||
@@ -94,9 +94,48 @@ function writeCreature(char) {
|
||||
writeSkills(char);
|
||||
writeDamageMultipliers(char);
|
||||
writeEffects(char);
|
||||
Creatures.update(char.id, {$set: {level: char.level}});
|
||||
writeCreatureDoc(char);
|
||||
};
|
||||
|
||||
function writeCreatureDoc(char) {
|
||||
// Store all the variables, using the same priority as computation evaluation
|
||||
// Attributes
|
||||
let variables = {};
|
||||
for (let key in char.atts){
|
||||
variables[key] = char.atts[key].result;
|
||||
if (
|
||||
char.atts[key].attributeType === 'ability' &&
|
||||
!variables.hasOwnProperty(key + 'Mod')
|
||||
){
|
||||
variables[key + 'Mod'] = char.atts[key].mod;
|
||||
}
|
||||
}
|
||||
for (let key in char.skills){
|
||||
if (!variables.hasOwnProperty(key)){
|
||||
variables[key] = char.skills[key].result;
|
||||
}
|
||||
}
|
||||
// Damage Multipliers
|
||||
for (let key in char.dms){
|
||||
if (!variables.hasOwnProperty(key)){
|
||||
variables[key] = char.dms[key].result;
|
||||
}
|
||||
}
|
||||
// Class levels
|
||||
for (let key in char.classes){
|
||||
if (!variables.hasOwnProperty(key + 'Level')){
|
||||
variables[key + 'Level'] = char.classes[key].level;
|
||||
}
|
||||
}
|
||||
// Creature level
|
||||
if (!variables.hasOwnProperty('level')){
|
||||
variables['level'] = char.level;
|
||||
}
|
||||
|
||||
// Write the creature
|
||||
Creatures.update(char.id, {$set: {level: char.level, variables}});
|
||||
}
|
||||
|
||||
/*
|
||||
* Write all the attributes from the in-memory char object to the Attirbute docs
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ import {makeChild} from "/imports/api/parenting.js";
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import schema from '/imports/api/schema.js';
|
||||
import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js";
|
||||
import OrderSchema from "/imports/api/creature/subSchemas/OrderSchema.js";
|
||||
import { canEditCreature } from '/imports/api/creature/creaturePermission.js';
|
||||
import { recomputeCreatureById } from '/imports/api/creature/creatureComputation.js'
|
||||
import { getHighestOrder } from '/imports/api/order.js';
|
||||
@@ -29,12 +30,6 @@ let attributeSchema = schema({
|
||||
regEx: /^\w*[a-z]\w*$/i,
|
||||
index: 1,
|
||||
},
|
||||
// Attributes need to store their order to keep the sheet consistent
|
||||
order: {
|
||||
type: SimpleSchema.Integer,
|
||||
// Indexed because we update order in bulk using the current order as a query
|
||||
index: 1,
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
allowedValues: [
|
||||
@@ -58,6 +53,10 @@ let attributeSchema = schema({
|
||||
type: Number,
|
||||
defaultValue: 0,
|
||||
},
|
||||
enabled: {
|
||||
type: Boolean,
|
||||
defaultValue: true,
|
||||
},
|
||||
// The computed modifier, provided the attribute is an ability
|
||||
mod: {
|
||||
type: SimpleSchema.Integer,
|
||||
@@ -82,6 +81,8 @@ let attributeSchema = schema({
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
// Attributes need to store their order to keep the sheet consistent
|
||||
order: OrderSchema(),
|
||||
color: ColorSchema(),
|
||||
});
|
||||
|
||||
@@ -108,10 +109,9 @@ const insertAttribute = new ValidatedMethod({
|
||||
|
||||
validate: schema({
|
||||
attribute: {
|
||||
type: Object,
|
||||
blackbox: true,
|
||||
type: attributeSchema.omit('order', 'parent'),
|
||||
},
|
||||
}).validator(),
|
||||
}).validator({ clean: true }),
|
||||
|
||||
run({attribute}) {
|
||||
const charId = attribute.charId;
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import schema from '/imports/api/schema.js';
|
||||
import ColorSchema from "/imports/api/creature/subSchemas/ColorSchema.js";
|
||||
import OrderSchema from "/imports/api/creature/subSchemas/OrderSchema.js";
|
||||
import { canEditCreature } from '/imports/api/creature/creaturePermission.js';
|
||||
import { recomputeCreatureById } from '/imports/api/creature/creatureComputation.js'
|
||||
import { getHighestOrder } from '/imports/api/order.js';
|
||||
import {makeParent} from "/imports/api/parenting.js";
|
||||
|
||||
let Features = new Mongo.Collection("features");
|
||||
@@ -13,17 +17,58 @@ let featureSchema = schema({
|
||||
used: {type: SimpleSchema.Integer, defaultValue: 0},
|
||||
reset: {
|
||||
type: String,
|
||||
allowedValues: ["manual", "longRest", "shortRest"],
|
||||
defaultValue: "manual",
|
||||
allowedValues: ["longRest", "shortRest"],
|
||||
optional: true,
|
||||
},
|
||||
enabled: {type: Boolean, defaultValue: true},
|
||||
alwaysEnabled:{type: Boolean, defaultValue: true},
|
||||
order: {
|
||||
type: SimpleSchema.Integer,
|
||||
// Indexed because we update order in bulk using the current order as a query
|
||||
index: 1,
|
||||
defaultValue: 0,
|
||||
},
|
||||
order: OrderSchema(),
|
||||
color: ColorSchema(),
|
||||
});
|
||||
|
||||
Features.attachSchema(featureSchema);
|
||||
Features.attachSchema(ColorSchema);
|
||||
|
||||
//Features.attachBehaviour("softRemovable");
|
||||
makeParent(Features, ["name", "enabled"]); //parents of effects and attacks
|
||||
|
||||
const insertFeature = new ValidatedMethod({
|
||||
|
||||
name: "Features.methods.insert",
|
||||
|
||||
validate: schema({
|
||||
feature: {
|
||||
type: featureSchema.omit('order', 'parent'),
|
||||
},
|
||||
}).validator({clean: true}),
|
||||
|
||||
run({feature}) {
|
||||
const charId = feature.charId;
|
||||
if (canEditCreature(charId, this.userId)){
|
||||
// Set order
|
||||
feature.order = getHighestOrder({
|
||||
collection: Features,
|
||||
charId,
|
||||
}) + 1;
|
||||
|
||||
// Set parent
|
||||
feature.parent = {
|
||||
id: charId,
|
||||
collection: 'Creatures',
|
||||
};
|
||||
|
||||
// Insert
|
||||
let featureId = Features.insert(feature);
|
||||
recomputeCreatureById(charId);
|
||||
return featureId;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default Features;
|
||||
export { insertFeature }
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import schema from '/imports/api/schema.js';
|
||||
|
||||
const ColorSchema = ({optional = false} = {}) => ({
|
||||
type: String,
|
||||
defaultValue: "#9E9E9E",
|
||||
|
||||
6
app/imports/api/creature/subSchemas/OrderSchema.js
Normal file
6
app/imports/api/creature/subSchemas/OrderSchema.js
Normal file
@@ -0,0 +1,6 @@
|
||||
const OrderSchema = () => ({
|
||||
type: Number,
|
||||
index: true,
|
||||
});
|
||||
|
||||
export default OrderSchema;
|
||||
Reference in New Issue
Block a user