From 0097696cc85625d960e0242a8d645e057acdbca5 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Wed, 6 Oct 2021 14:57:13 +0200 Subject: [PATCH] Began merging attacks into actions --- .../buildComputation/linkTypeDependencies.js | 1 - .../computeComputation/computeByType.js | 2 +- app/imports/api/properties/Actions.js | 10 ++++ app/imports/api/properties/Attacks.js | 46 ------------------- .../computedOnlyPropertySchemasIndex.js | 2 - .../computedPropertySchemasIndex.js | 2 - .../api/properties/propertySchemasIndex.js | 2 - .../migrations/server/2.0-beta.33-dbv1.js | 11 +++-- .../components/actions/ActionCard.vue | 7 +-- .../ui/properties/forms/ActionForm.vue | 11 ++--- 10 files changed, 23 insertions(+), 71 deletions(-) delete mode 100644 app/imports/api/properties/Attacks.js diff --git a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js index ae68ba30..d6e30222 100644 --- a/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js +++ b/app/imports/api/engine/computation/buildComputation/linkTypeDependencies.js @@ -1,6 +1,5 @@ const linkDependenciesByType = { action: linkResources, - attack: linkResources, attribute: linkAttribute, class: linkVariableName, classLevel: linkClassLevel, diff --git a/app/imports/api/engine/computation/computeComputation/computeByType.js b/app/imports/api/engine/computation/computeComputation/computeByType.js index 522a5c5c..45ce9316 100644 --- a/app/imports/api/engine/computation/computeComputation/computeByType.js +++ b/app/imports/api/engine/computation/computeComputation/computeByType.js @@ -7,8 +7,8 @@ import container from './computeByType/computeContainer.js'; export default Object.freeze({ _variable, action, - attack: action, attribute, container, slot, + spell: action, }); diff --git a/app/imports/api/properties/Actions.js b/app/imports/api/properties/Actions.js index caa3c51e..fef5eb67 100644 --- a/app/imports/api/properties/Actions.js +++ b/app/imports/api/properties/Actions.js @@ -40,6 +40,12 @@ let ActionSchema = createPropertySchema({ 'multipleTargets', ], }, + // Some actions have an attack roll + attackRoll: { + type: 'fieldToCompute', + optional: true, + defaultValue: 'strength.modifier + proficiencyBonus', + }, // Calculation of how many times this action can be used uses: { type: 'fieldToCompute', @@ -129,6 +135,10 @@ const ComputedOnlyActionSchema = createPropertySchema({ optional: true, removeBeforeCompute: true, }, + attackRoll: { + type: 'computedOnlyField', + optional: true, + }, uses: { type: 'computedOnlyField', optional: true, diff --git a/app/imports/api/properties/Attacks.js b/app/imports/api/properties/Attacks.js deleted file mode 100644 index ce4a6687..00000000 --- a/app/imports/api/properties/Attacks.js +++ /dev/null @@ -1,46 +0,0 @@ -import SimpleSchema from 'simpl-schema'; -import { ActionSchema, ComputedOnlyActionSchema } from '/imports/api/properties/Actions.js'; -import createPropertySchema from '/imports/api/properties/subSchemas/createPropertySchema.js'; -import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js'; - -// Attacks are special instances of actions -let AttackSchema = new SimpleSchema() - .extend(ActionSchema) - .extend(createPropertySchema({ - // What gets added to the d20 roll - rollBonus: { - type: 'fieldToCompute', - optional: true, - defaultValue: 'strength.modifier + proficiencyBonus', - }, - // Set better defaults for the action - actionType: { - type: String, - defaultValue: 'attack', - max: STORAGE_LIMITS.name, - }, - tags: { - type: Array, - defaultValue: ['attack'], - maxCount: STORAGE_LIMITS.tagCount, - }, - 'tags.$': { - type: String, - max: STORAGE_LIMITS.tagLength, - }, - })); - -const ComputedOnlyAttackSchema = new SimpleSchema() - .extend(ComputedOnlyActionSchema) - .extend(createPropertySchema({ - rollBonus: { - type: 'computedOnlyField', - optional: true, - }, - })); - -const ComputedAttackSchema = new SimpleSchema() - .extend(AttackSchema) - .extend(ComputedOnlyAttackSchema); - -export { AttackSchema, ComputedOnlyAttackSchema, ComputedAttackSchema }; diff --git a/app/imports/api/properties/computedOnlyPropertySchemasIndex.js b/app/imports/api/properties/computedOnlyPropertySchemasIndex.js index b01bd38d..7affc14c 100644 --- a/app/imports/api/properties/computedOnlyPropertySchemasIndex.js +++ b/app/imports/api/properties/computedOnlyPropertySchemasIndex.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import { ComputedOnlyActionSchema } from '/imports/api/properties/Actions.js'; import { ComputedOnlyAdjustmentSchema } from '/imports/api/properties/Adjustments.js'; -import { ComputedOnlyAttackSchema } from '/imports/api/properties/Attacks.js'; import { ComputedOnlyAttributeSchema } from '/imports/api/properties/Attributes.js'; import { ComputedOnlyBuffSchema } from '/imports/api/properties/Buffs.js'; import { ComputedOnlyClassSchema } from '/imports/api/properties/Classes.js'; @@ -29,7 +28,6 @@ import { ComputedOnlyToggleSchema } from '/imports/api/properties/Toggles.js'; const propertySchemasIndex = { action: ComputedOnlyActionSchema, adjustment: ComputedOnlyAdjustmentSchema, - attack: ComputedOnlyAttackSchema, attribute: ComputedOnlyAttributeSchema, buff: ComputedOnlyBuffSchema, class: ComputedOnlyClassSchema, diff --git a/app/imports/api/properties/computedPropertySchemasIndex.js b/app/imports/api/properties/computedPropertySchemasIndex.js index e9dc3fea..7ede8fd8 100644 --- a/app/imports/api/properties/computedPropertySchemasIndex.js +++ b/app/imports/api/properties/computedPropertySchemasIndex.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import { ComputedActionSchema } from '/imports/api/properties/Actions.js'; import { ComputedAdjustmentSchema } from '/imports/api/properties/Adjustments.js'; -import { ComputedAttackSchema } from '/imports/api/properties/Attacks.js'; import { ComputedAttributeSchema } from '/imports/api/properties/Attributes.js'; import { ComputedBuffSchema } from '/imports/api/properties/Buffs.js'; import { ComputedClassSchema } from '/imports/api/properties/Classes.js'; @@ -29,7 +28,6 @@ import { ComputedToggleSchema } from '/imports/api/properties/Toggles.js'; const propertySchemasIndex = { action: ComputedActionSchema, adjustment: ComputedAdjustmentSchema, - attack: ComputedAttackSchema, attribute: ComputedAttributeSchema, buff: ComputedBuffSchema, class: ComputedClassSchema, diff --git a/app/imports/api/properties/propertySchemasIndex.js b/app/imports/api/properties/propertySchemasIndex.js index c4c9eec8..d799559d 100644 --- a/app/imports/api/properties/propertySchemasIndex.js +++ b/app/imports/api/properties/propertySchemasIndex.js @@ -1,7 +1,6 @@ import SimpleSchema from 'simpl-schema'; import { ActionSchema } from '/imports/api/properties/Actions.js'; import { AdjustmentSchema } from '/imports/api/properties/Adjustments.js'; -import { AttackSchema } from '/imports/api/properties/Attacks.js'; import { AttributeSchema } from '/imports/api/properties/Attributes.js'; import { BuffSchema } from '/imports/api/properties/Buffs.js'; import { ClassSchema } from '/imports/api/properties/Classes.js'; @@ -29,7 +28,6 @@ import { ItemSchema } from '/imports/api/properties/Items.js'; const propertySchemasIndex = { action: ActionSchema, adjustment: AdjustmentSchema, - attack: AttackSchema, attribute: AttributeSchema, buff: BuffSchema, class: ClassSchema, diff --git a/app/imports/migrations/server/2.0-beta.33-dbv1.js b/app/imports/migrations/server/2.0-beta.33-dbv1.js index d5ed8489..eced0aac 100644 --- a/app/imports/migrations/server/2.0-beta.33-dbv1.js +++ b/app/imports/migrations/server/2.0-beta.33-dbv1.js @@ -74,7 +74,9 @@ const transformsByPropType = { ], 'attack': [ ...actionTransforms, - ...getComputedPropertyTransforms('rollBonus'), + ...getComputedPropertyTransforms('rollBonus', 'attackRoll'), + //change type to action + {from: 'type', to: 'type', up: () => 'action'}, ], 'attribute': [ ...getComputedPropertyTransforms('baseValue'), @@ -158,11 +160,12 @@ const transformsByPropType = { ], }; -function getComputedPropertyTransforms(key){ +function getComputedPropertyTransforms(key, toKey){ + if (!toKey) toKey = key; return [ {from: key, to: `${key}.calculation`}, - {from: `${key}Result`, to: `${key}.value`, up: nanToNull}, - {from: `${key}Errors`, to: `${key}.errors`, up: trimErrors}, + {from: `${key}Result`, to: `${toKey}.value`, up: nanToNull}, + {from: `${key}Errors`, to: `${toKey}.errors`, up: trimErrors}, ]; } diff --git a/app/imports/ui/properties/components/actions/ActionCard.vue b/app/imports/ui/properties/components/actions/ActionCard.vue index 5ec693fd..05a577b5 100644 --- a/app/imports/ui/properties/components/actions/ActionCard.vue +++ b/app/imports/ui/properties/components/actions/ActionCard.vue @@ -15,7 +15,7 @@ :disabled="model.insufficientResources || !context.editPermission" @click.stop="doAction" > -