From 3129b86ef04b90f22df9825c7d663f9b40951c8f Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Mon, 18 Feb 2019 15:52:17 +0200 Subject: [PATCH] Improved action and attack schemas --- .../api/creature/properties/Actions.js | 29 ++++++++++++----- .../api/creature/properties/Attacks.js | 29 ++++------------- .../creature/subSchemas/AdjustmentSchema.js | 15 +++++++++ .../api/creature/subSchemas/DamageSchema.js | 31 +++++++++++++++++++ app/imports/ui/character/CharacterSheet.vue | 5 --- 5 files changed, 73 insertions(+), 36 deletions(-) create mode 100644 app/imports/api/creature/subSchemas/AdjustmentSchema.js create mode 100644 app/imports/api/creature/subSchemas/DamageSchema.js diff --git a/app/imports/api/creature/properties/Actions.js b/app/imports/api/creature/properties/Actions.js index 431abf8a..f134768f 100644 --- a/app/imports/api/creature/properties/Actions.js +++ b/app/imports/api/creature/properties/Actions.js @@ -1,8 +1,10 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; -import {makeChild} from "/imports/api/parenting.js"; +import {makeChild} from '/imports/api/parenting.js'; +import AdjustmentSchema from '/imports/api/creature/subSchemas/AdjustmentSchema.js'; +import DamageSchema from '/imports/api/creature/subSchemas/DamageSchema.js'; -let Actions = new Mongo.Collection("actions"); +let Actions = new Mongo.Collection('actions'); /* * Actions are given to a character by items and features @@ -18,6 +20,10 @@ let actionSchema = schema({ optional: true, trim: false, }, + enabled: { + type: Boolean, + defaultValue: true, + }, description: { type: String, optional: true, @@ -25,22 +31,29 @@ let actionSchema = schema({ }, type: { type: String, - allowedValues: ["action, bonus, reaction, free"], - defaultValue: "action", + allowedValues: ['action', 'bonus', 'reaction', 'free'], + defaultValue: 'action', }, //the immediate impact of doing this action (eg. -1 rages) adjustments: { type: Array, defaultValue: [], }, - "adjustments.$": { - type: Object, + 'adjustments.$': { + type: AdjustmentSchema, + }, + damages: { + type: Array, + defaultValue: [], + }, + 'damages.$': { + type: DamageSchema, }, }); Actions.attachSchema(actionSchema); -// Actions.attachBehaviour("softRemovable"); -makeChild(Actions); +// Actions.attachBehaviour('softRemovable'); +makeChild(Actions, ["name", "enabled"]); export default Actions diff --git a/app/imports/api/creature/properties/Attacks.js b/app/imports/api/creature/properties/Attacks.js index 948b3b42..dac22795 100644 --- a/app/imports/api/creature/properties/Attacks.js +++ b/app/imports/api/creature/properties/Attacks.js @@ -1,6 +1,7 @@ import SimpleSchema from 'simpl-schema'; import schema from '/imports/api/schema.js'; import {makeChild} from "/imports/api/parenting.js"; +import DamageSchema from '/imports/api/creature/subSchemas/DamageSchema.js'; let Attacks = new Mongo.Collection("attacks"); @@ -30,30 +31,12 @@ attackSchema = schema({ optional: true, trim: false, }, - damage: { - type: String, - defaultValue: "1d8 + {strengthMod}", - optional: true, - trim: false, + damages: { + type: Array, + defaultValue: [], }, - damageType: { - type: String, - allowedValues: [ - "bludgeoning", - "piercing", - "slashing", - "acid", - "cold", - "fire", - "force", - "lightning", - "necrotic", - "poison", - "psychic", - "radiant", - "thunder", - ], - defaultValue: "slashing", + 'damages.$': { + type: DamageSchema, }, enabled: { type: Boolean, diff --git a/app/imports/api/creature/subSchemas/AdjustmentSchema.js b/app/imports/api/creature/subSchemas/AdjustmentSchema.js new file mode 100644 index 00000000..cff0e434 --- /dev/null +++ b/app/imports/api/creature/subSchemas/AdjustmentSchema.js @@ -0,0 +1,15 @@ +import SimpleSchema from 'simpl-schema'; +import schema from '/imports/api/schema.js'; + +const AdjustmentSchema = schema({ + stat: { + type: String, + optional: true, + }, + roll: { + type: String, + optional: true, + }, +}); + +export default AdjustmentSchema; diff --git a/app/imports/api/creature/subSchemas/DamageSchema.js b/app/imports/api/creature/subSchemas/DamageSchema.js new file mode 100644 index 00000000..71d81b63 --- /dev/null +++ b/app/imports/api/creature/subSchemas/DamageSchema.js @@ -0,0 +1,31 @@ +import SimpleSchema from 'simpl-schema'; +import schema from '/imports/api/schema.js'; + +const DamageSchema = schema({ + type: { + type: String, + allowedValues: [ + "bludgeoning", + "piercing", + "slashing", + "acid", + "cold", + "fire", + "force", + "lightning", + "necrotic", + "poison", + "psychic", + "radiant", + "thunder", + ], + defaultValue: "slashing", + }, + roll: { + type: String, + optional: true, + defaultValue: '1d8 + strengthMod', + }, +}); + +export default DamageSchema; diff --git a/app/imports/ui/character/CharacterSheet.vue b/app/imports/ui/character/CharacterSheet.vue index 25ef34a3..5b20c029 100644 --- a/app/imports/ui/character/CharacterSheet.vue +++ b/app/imports/ui/character/CharacterSheet.vue @@ -55,11 +55,6 @@ StatsTab, CharacterTreeView, }, - watch: { - charId(newValue){ - console.log(newValue) - }, - }, data(){return { theme, tab: 0,