From 15ead403a5b94051f4bb36f14d39f18b565b8476 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Wed, 9 Feb 2022 16:47:38 +0200 Subject: [PATCH] Added UI for action branches --- .../creatureProperties/methods/dealDamage.js | 1 - .../applyPropertyByType/applyAction.js | 19 ++++- .../applyPropertyByType/applyBranch.js | 9 +++ .../api/properties/{Branch.js => Branches.js} | 3 + .../computedOnlyPropertySchemasIndex.js | 2 + .../computedPropertySchemasIndex.js | 2 + .../api/properties/propertySchemasIndex.js | 2 + app/imports/constants/PROPERTIES.js | 12 ++- app/imports/migrations/server/index.js | 2 +- .../ui/properties/forms/BranchForm.vue | 75 +++++++++++++++++++ .../forms/shared/propertyFormIndex.js | 2 + .../treeNodeViews/BranchTreeNode.vue | 36 +++++++++ .../treeNodeViews/treeNodeViewIndex.js | 2 + .../ui/properties/viewers/BranchViewer.vue | 56 ++++++++++++++ .../viewers/shared/propertyViewerIndex.js | 2 + app/imports/ui/router.js | 3 +- 16 files changed, 219 insertions(+), 9 deletions(-) rename app/imports/api/properties/{Branch.js => Branches.js} (94%) create mode 100644 app/imports/ui/properties/forms/BranchForm.vue create mode 100644 app/imports/ui/properties/treeNodeViews/BranchTreeNode.vue create mode 100644 app/imports/ui/properties/viewers/BranchViewer.vue diff --git a/app/imports/api/creature/creatureProperties/methods/dealDamage.js b/app/imports/api/creature/creatureProperties/methods/dealDamage.js index 45eb8583..b93aa495 100644 --- a/app/imports/api/creature/creatureProperties/methods/dealDamage.js +++ b/app/imports/api/creature/creatureProperties/methods/dealDamage.js @@ -39,7 +39,6 @@ const dealDamage = new ValidatedMethod({ }); export function dealDamageWork({creature, damageType, amount}){ - console.log({damageType, amount}) // Get all the health bars and do damage to them let healthBars = CreatureProperties.find({ 'ancestors.id': creature._id, diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyAction.js b/app/imports/api/engine/actions/applyPropertyByType/applyAction.js index 776e2f15..2f5a5be0 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyAction.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyAction.js @@ -54,9 +54,24 @@ function applyAttackWithoutTarget({prop, scope, log}){ scope['$attackRoll'] = {value}; let criticalHitTarget = scope.criticalHitTarget?.value || 20; let criticalHit = value >= criticalHitTarget; - if (criticalHit) scope['$criticalHit'] = {value: true}; + if (criticalHit){ + scope['$criticalHit'] = {value: true}; + scope['$attackHit'] = {value: true}; + } else { + let criticalMiss = value === 1; + if (criticalMiss){ + scope['$criticalMiss'] = 1; + log.content.push({ + name: 'Critical Miss!', + }); + scope['$attackMiss'] = {value: true}; + } else { + // Untargeted attacks hit by default + scope['$attackHit'] = {value: true} + } + } let result = value + prop.attackRoll.value; - scope['$toHit'] = {value: result}; + scope['$attackRoll'] = {value: result}; log.content.push({ name: criticalHit ? 'Critical Hit!' : 'To Hit', value: `1d20 [${value}] + ${prop.attackRoll.value} = ` + result, diff --git a/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js b/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js index 925e131c..63aa2e1d 100644 --- a/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js +++ b/app/imports/api/engine/actions/applyPropertyByType/applyBranch.js @@ -1,5 +1,6 @@ import applyProperty from '../applyProperty.js'; import recalculateCalculation from './shared/recalculateCalculation.js'; +import rollDice from '/imports/parser/rollDice.js'; export default function applyBranch(node, { creature, targets, scope, log @@ -27,6 +28,14 @@ export default function applyBranch(node, { case 'successfulSave': if (scope['$saveSucceeded']?.value) applyChildren(); break; + case 'random': + if (node.children.length){ + let index = rollDice(1, node.children.length)[0] - 1; + applyProperty(node.children[index], { + creature, targets, scope, log + }); + } + break; case 'eachTarget': if (targets.length){ targets.forEach(target => { diff --git a/app/imports/api/properties/Branch.js b/app/imports/api/properties/Branches.js similarity index 94% rename from app/imports/api/properties/Branch.js rename to app/imports/api/properties/Branches.js index f1222fc6..758d88fa 100644 --- a/app/imports/api/properties/Branch.js +++ b/app/imports/api/properties/Branches.js @@ -16,11 +16,14 @@ let BranchSchema = createPropertySchema({ 'successfulSave', // Iterate through targets 'eachTarget', + // Pick one child at random + 'random', // if it has option children, asks to select one // Otherwise presents its own text with yes/no //'choice', //'option', ], + defaultValue: 'if', }, text: { type: String, diff --git a/app/imports/api/properties/computedOnlyPropertySchemasIndex.js b/app/imports/api/properties/computedOnlyPropertySchemasIndex.js index 7affc14c..d47d560d 100644 --- a/app/imports/api/properties/computedOnlyPropertySchemasIndex.js +++ b/app/imports/api/properties/computedOnlyPropertySchemasIndex.js @@ -3,6 +3,7 @@ import { ComputedOnlyActionSchema } from '/imports/api/properties/Actions.js'; import { ComputedOnlyAdjustmentSchema } from '/imports/api/properties/Adjustments.js'; import { ComputedOnlyAttributeSchema } from '/imports/api/properties/Attributes.js'; import { ComputedOnlyBuffSchema } from '/imports/api/properties/Buffs.js'; +import { ComputedOnlyBranchSchema } from '/imports/api/properties/Branches.js'; import { ComputedOnlyClassSchema } from '/imports/api/properties/Classes.js'; import { ComputedOnlyClassLevelSchema } from '/imports/api/properties/ClassLevels.js'; import { ComputedOnlyConstantSchema } from '/imports/api/properties/Constants.js'; @@ -30,6 +31,7 @@ const propertySchemasIndex = { adjustment: ComputedOnlyAdjustmentSchema, attribute: ComputedOnlyAttributeSchema, buff: ComputedOnlyBuffSchema, + branch: ComputedOnlyBranchSchema, class: ComputedOnlyClassSchema, classLevel: ComputedOnlyClassLevelSchema, constant: ComputedOnlyConstantSchema, diff --git a/app/imports/api/properties/computedPropertySchemasIndex.js b/app/imports/api/properties/computedPropertySchemasIndex.js index 7ede8fd8..1fa8c9d8 100644 --- a/app/imports/api/properties/computedPropertySchemasIndex.js +++ b/app/imports/api/properties/computedPropertySchemasIndex.js @@ -3,6 +3,7 @@ import { ComputedActionSchema } from '/imports/api/properties/Actions.js'; import { ComputedAdjustmentSchema } from '/imports/api/properties/Adjustments.js'; import { ComputedAttributeSchema } from '/imports/api/properties/Attributes.js'; import { ComputedBuffSchema } from '/imports/api/properties/Buffs.js'; +import { ComputedBranchSchema } from '/imports/api/properties/Branches.js'; import { ComputedClassSchema } from '/imports/api/properties/Classes.js'; import { ComputedClassLevelSchema } from '/imports/api/properties/ClassLevels.js'; import { ConstantSchema } from '/imports/api/properties/Constants.js'; @@ -30,6 +31,7 @@ const propertySchemasIndex = { adjustment: ComputedAdjustmentSchema, attribute: ComputedAttributeSchema, buff: ComputedBuffSchema, + branch: ComputedBranchSchema, class: ComputedClassSchema, classLevel: ComputedClassLevelSchema, constant: ConstantSchema, diff --git a/app/imports/api/properties/propertySchemasIndex.js b/app/imports/api/properties/propertySchemasIndex.js index d799559d..0cba80a0 100644 --- a/app/imports/api/properties/propertySchemasIndex.js +++ b/app/imports/api/properties/propertySchemasIndex.js @@ -3,6 +3,7 @@ import { ActionSchema } from '/imports/api/properties/Actions.js'; import { AdjustmentSchema } from '/imports/api/properties/Adjustments.js'; import { AttributeSchema } from '/imports/api/properties/Attributes.js'; import { BuffSchema } from '/imports/api/properties/Buffs.js'; +import { BranchSchema } from '/imports/api/properties/Branches.js'; import { ClassSchema } from '/imports/api/properties/Classes.js'; import { ClassLevelSchema } from '/imports/api/properties/ClassLevels.js'; import { ConstantSchema } from '/imports/api/properties/Constants.js'; @@ -30,6 +31,7 @@ const propertySchemasIndex = { adjustment: AdjustmentSchema, attribute: AttributeSchema, buff: BuffSchema, + branch: BranchSchema, class: ClassSchema, classLevel: ClassLevelSchema, constant: ConstantSchema, diff --git a/app/imports/constants/PROPERTIES.js b/app/imports/constants/PROPERTIES.js index 18237814..4c35c038 100644 --- a/app/imports/constants/PROPERTIES.js +++ b/app/imports/constants/PROPERTIES.js @@ -16,12 +16,18 @@ const PROPERTIES = Object.freeze({ icon: '$vuetify.icons.attribute_damage', name: 'Attribute damage', helpText: 'Attribute damage reduces the current value of an attribute when it is applied by an action. A negative value causes the attribute to increase instead, up to its normal maximum.', - suggestedParents: ['action', 'attack', 'savingThrow', 'spell'], + suggestedParents: ['action', 'attack', 'savingThrow', 'spell', 'branch'], }, buff: { icon: '$vuetify.icons.buff', name: 'Buff', helpText: 'When a buff is activated as a child of an action, it will copy the properties under itself onto a target character.', + suggestedParents: ['action', 'attack', 'savingThrow', 'spell', 'branch'], + }, + branch: { + icon: 'mdi-file-tree', + name: 'Branch', + helpText: 'When a branch is activated as a child of an action, it can control which of its children get activated.', suggestedParents: ['action', 'attack', 'savingThrow', 'spell'], }, class: { @@ -53,7 +59,7 @@ const PROPERTIES = Object.freeze({ icon: '$vuetify.icons.damage', name: 'Damage', helpText: 'When damage is activated by an action it reduces the hit points of the target creature by the calculated amount.', - suggestedParents: ['action', 'attack', 'savingThrow', 'spell'], + suggestedParents: ['action', 'attack', 'savingThrow', 'spell', 'branch'], }, damageMultiplier: { icon: '$vuetify.icons.damage_multiplier', @@ -102,7 +108,7 @@ const PROPERTIES = Object.freeze({ icon: '$vuetify.icons.roll', name: 'Roll', helpText: 'When activated by an action, rolls perform a calculation and temporarily store the result for other properties under the same action to use', - suggestedParents: ['action', 'attack', 'savingThrow', 'spell'], + suggestedParents: ['action', 'attack', 'savingThrow', 'spell', 'branch'], }, reference: { icon: 'mdi-vector-link', diff --git a/app/imports/migrations/server/index.js b/app/imports/migrations/server/index.js index 74860df8..54ca97d0 100644 --- a/app/imports/migrations/server/index.js +++ b/app/imports/migrations/server/index.js @@ -1 +1 @@ -import './v1/dbv1.js'; +import './dbv1/dbv1.js'; diff --git a/app/imports/ui/properties/forms/BranchForm.vue b/app/imports/ui/properties/forms/BranchForm.vue new file mode 100644 index 00000000..ed54318a --- /dev/null +++ b/app/imports/ui/properties/forms/BranchForm.vue @@ -0,0 +1,75 @@ + + + + + diff --git a/app/imports/ui/properties/forms/shared/propertyFormIndex.js b/app/imports/ui/properties/forms/shared/propertyFormIndex.js index 42037893..2e28b01c 100644 --- a/app/imports/ui/properties/forms/shared/propertyFormIndex.js +++ b/app/imports/ui/properties/forms/shared/propertyFormIndex.js @@ -3,6 +3,7 @@ const AdjustmentForm = () => import('/imports/ui/properties/forms/AdjustmentForm const AttackForm = () => import('/imports/ui/properties/forms/AttackForm.vue'); const AttributeForm = () => import('/imports/ui/properties/forms/AttributeForm.vue'); const BuffForm = () => import('/imports/ui/properties/forms/BuffForm.vue'); +const BranchForm = () => import('/imports/ui/properties/forms/BranchForm.vue'); const ClassLevelForm = () => import('/imports/ui/properties/forms/ClassLevelForm.vue'); const ConstantForm = () => import('/imports/ui/properties/forms/ConstantForm.vue'); const ContainerForm = () => import('/imports/ui/properties/forms/ContainerForm.vue'); @@ -30,6 +31,7 @@ export default { attack: AttackForm, attribute: AttributeForm, buff: BuffForm, + branch: BranchForm, constant: ConstantForm, container: ContainerForm, classLevel: ClassLevelForm, diff --git a/app/imports/ui/properties/treeNodeViews/BranchTreeNode.vue b/app/imports/ui/properties/treeNodeViews/BranchTreeNode.vue new file mode 100644 index 00000000..7c0c96e6 --- /dev/null +++ b/app/imports/ui/properties/treeNodeViews/BranchTreeNode.vue @@ -0,0 +1,36 @@ + + + diff --git a/app/imports/ui/properties/treeNodeViews/treeNodeViewIndex.js b/app/imports/ui/properties/treeNodeViews/treeNodeViewIndex.js index 3ce03502..26d52ca0 100644 --- a/app/imports/ui/properties/treeNodeViews/treeNodeViewIndex.js +++ b/app/imports/ui/properties/treeNodeViews/treeNodeViewIndex.js @@ -1,5 +1,6 @@ import DefaultTreeNode from '/imports/ui/properties/treeNodeViews/DefaultTreeNode.vue'; import AdjustmentTreeNode from '/imports/ui/properties/treeNodeViews/AdjustmentTreeNode.vue'; +import BranchTreeNode from '/imports/ui/properties/treeNodeViews/BranchTreeNode.vue'; import ItemTreeNode from '/imports/ui/properties/treeNodeViews/ItemTreeNode.vue'; import DamageTreeNode from '/imports/ui/properties/treeNodeViews/DamageTreeNode.vue'; import EffectTreeNode from '/imports/ui/properties/treeNodeViews/EffectTreeNode.vue'; @@ -10,6 +11,7 @@ import ReferenceTreeNode from '/imports/ui/properties/treeNodeViews/ReferenceTre export default { default: DefaultTreeNode, adjustment: AdjustmentTreeNode, + branch: BranchTreeNode, classLevel: ClassLevelTreeNode, damage: DamageTreeNode, effect: EffectTreeNode, diff --git a/app/imports/ui/properties/viewers/BranchViewer.vue b/app/imports/ui/properties/viewers/BranchViewer.vue new file mode 100644 index 00000000..bc5c64c2 --- /dev/null +++ b/app/imports/ui/properties/viewers/BranchViewer.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/app/imports/ui/properties/viewers/shared/propertyViewerIndex.js b/app/imports/ui/properties/viewers/shared/propertyViewerIndex.js index 014ad3b1..8845fac6 100644 --- a/app/imports/ui/properties/viewers/shared/propertyViewerIndex.js +++ b/app/imports/ui/properties/viewers/shared/propertyViewerIndex.js @@ -2,6 +2,7 @@ const ActionViewer = () => import ('/imports/ui/properties/viewers/ActionViewer. const AdjustmentViewer = () => import ('/imports/ui/properties/viewers/AdjustmentViewer.vue'); const AttributeViewer = () => import ('/imports/ui/properties/viewers/AttributeViewer.vue'); const BuffViewer = () => import ('/imports/ui/properties/viewers/BuffViewer.vue'); +const BranchViewer = () => import ('/imports/ui/properties/viewers/BranchViewer.vue'); const ContainerViewer = () => import ('/imports/ui/properties/viewers/ContainerViewer.vue'); const ClassLevelViewer = () => import ('/imports/ui/properties/viewers/ClassLevelViewer.vue'); const ConstantViewer = () => import ('/imports/ui/properties/viewers/ConstantViewer.vue'); @@ -28,6 +29,7 @@ export default { adjustment: AdjustmentViewer, attribute: AttributeViewer, buff: BuffViewer, + branch: BranchViewer, container: ContainerViewer, class: SlotViewer, classLevel: ClassLevelViewer, diff --git a/app/imports/ui/router.js b/app/imports/ui/router.js index 30bd9540..347f3eb7 100644 --- a/app/imports/ui/router.js +++ b/app/imports/ui/router.js @@ -269,8 +269,7 @@ RouterFactory.configure(router => { function redirectIfMaintenance(to, from, next){ if (!MAINTENANCE_MODE) return next(); - console.log(to); - if (to?.path === '/admin' || to?.path === '/maintenance') return next(); + if (to?.path === '/admin' || to?.path === '/maintenance' || to?.path === '/sign-in') return next(); Tracker.autorun((computation) => { if (userSubscription.ready()){ computation.stop();