From cb10b53a1062a4926560038f01c2ee30ba6c7dae Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Tue, 28 Sep 2021 14:25:11 +0200 Subject: [PATCH] Updated forms and some UI for new data structure --- .../tests/computeAttribute.testFn.js | 2 + .../writeAlteredProperties.js | 6 +-- app/imports/api/engine/computeCreature.js | 2 + .../api/engine/oldActions/applyAttack.js | 2 +- .../engine/oldActions/castSpellWithSlot.js | 2 +- app/imports/api/properties/Attacks.js | 2 - .../character/CharacterSheetToolbar.vue | 5 --- .../character/characterSheetTabs/StatsTab.vue | 2 +- .../components/actions/ActionCard.vue | 18 +++----- .../actions/AttributeConsumedView.vue | 2 +- .../components/actions/ItemConsumedView.vue | 11 +++-- .../components/attributes/AbilityListTile.vue | 8 ++-- .../components/attributes/AttributeCard.vue | 4 +- .../components/attributes/AttributeEffect.vue | 15 +++++-- .../components/attributes/HealthBarCard.vue | 4 +- .../components/attributes/HitDiceListTile.vue | 11 ++--- .../components/attributes/ResourceCard.vue | 30 ++++++------- .../attributes/SpellSlotListTile.vue | 13 +++--- .../components/features/FeatureCard.vue | 2 +- .../components/persona/NoteCard.vue | 9 ++-- .../ui/properties/forms/ActionForm.vue | 38 ++++++++--------- .../ui/properties/forms/AdjustmentForm.vue | 7 ++-- .../forms/AttributeConsumedForm.vue | 8 ++-- .../ui/properties/forms/AttributeForm.vue | 21 +++++----- app/imports/ui/properties/forms/BuffForm.vue | 22 +++++----- .../ui/properties/forms/ClassLevelForm.vue | 12 ++---- .../ui/properties/forms/ContainerForm.vue | 11 +++-- .../ui/properties/forms/DamageForm.vue | 8 ++-- .../ui/properties/forms/EffectForm.vue | 9 ++-- .../ui/properties/forms/FeatureForm.vue | 20 ++++----- .../ui/properties/forms/ItemConsumedForm.vue | 7 ++-- app/imports/ui/properties/forms/ItemForm.vue | 11 +++-- app/imports/ui/properties/forms/NoteForm.vue | 20 ++++----- app/imports/ui/properties/forms/RollForm.vue | 10 ++--- .../ui/properties/forms/SavingThrowForm.vue | 9 ++-- app/imports/ui/properties/forms/SkillForm.vue | 21 ++++------ app/imports/ui/properties/forms/SlotForm.vue | 28 ++++++------- app/imports/ui/properties/forms/SpellForm.vue | 10 ++--- .../ui/properties/forms/SpellListForm.vue | 36 +++++++--------- .../ui/properties/forms/ToggleForm.vue | 12 ++---- .../properties/forms/shared/ComputedField.vue | 3 +- .../forms/shared/InlineComputationField.vue | 42 +++++++++++++++++++ .../forms/shared/propertyFormMixin.js | 7 ++++ .../treeNodeViews/AdjustmentTreeNode.vue | 11 +++-- .../treeNodeViews/DamageTreeNode.vue | 2 +- .../treeNodeViews/EffectTreeNode.vue | 3 +- .../ui/properties/viewers/ActionViewer.vue | 32 +++++++------- .../properties/viewers/AdjustmentViewer.vue | 8 ++-- .../ui/properties/viewers/AttributeViewer.vue | 13 +++--- .../ui/properties/viewers/BuffViewer.vue | 8 ++-- .../properties/viewers/ClassLevelViewer.vue | 4 +- .../ui/properties/viewers/SkillViewer.vue | 2 +- 52 files changed, 304 insertions(+), 301 deletions(-) create mode 100644 app/imports/ui/properties/forms/shared/InlineComputationField.vue diff --git a/app/imports/api/engine/computation/computeComputation/tests/computeAttribute.testFn.js b/app/imports/api/engine/computation/computeComputation/tests/computeAttribute.testFn.js index 2a9e4f3c..9eb5858a 100644 --- a/app/imports/api/engine/computation/computeComputation/tests/computeAttribute.testFn.js +++ b/app/imports/api/engine/computation/computeComputation/tests/computeAttribute.testFn.js @@ -7,10 +7,12 @@ export default function(){ const computation = buildComputationFromProps(testProperties); computeCreatureComputation(computation); const prop = id => computation.propsById[id]; + const scope = variableName => computation.scope[variableName]; assert.equal(prop('emptyId').value, 0); assert.equal(prop('noVariableNameId').value, 8); assert.equal(prop('strengthId').value, 12); assert.equal(prop('strengthId').modifier, 1); + assert.equal(scope('strength').modifier, 1); assert.equal(prop('referencesDexId').value, 4); assert.equal(prop('hitDiceId').constitutionMod, 5); assert.equal( diff --git a/app/imports/api/engine/computation/writeComputation/writeAlteredProperties.js b/app/imports/api/engine/computation/writeComputation/writeAlteredProperties.js index 0d7bcbe6..932975e6 100644 --- a/app/imports/api/engine/computation/writeComputation/writeAlteredProperties.js +++ b/app/imports/api/engine/computation/writeComputation/writeAlteredProperties.js @@ -36,9 +36,6 @@ function addChangedKeysToOp(op, keys, original, changed) { // and compile an operation that sets all those keys for (let key of keys){ if (!isEqual(original[key], changed[key])){ - console.log('not equal: ', key); - console.log(original[key]) - console.log(changed[key]) if (!op) op = newOperation(original._id, changed.type); let value = changed[key]; if (value === undefined){ @@ -86,7 +83,6 @@ function addUnsetOp(op, key){ // compensation without needing to roll back changes, which causes multiple // expensive redraws of the character sheet function writePropertiesSequentially(bulkWriteOps){ - console.log({opsLength: bulkWriteOps.length}); bulkWriteOps.forEach(op => { let updateOneOrMany = op.updateOne || op.updateMany; CreatureProperties.update(updateOneOrMany.filter, updateOneOrMany.update, { @@ -95,7 +91,7 @@ function writePropertiesSequentially(bulkWriteOps){ bypassCollection2: true, }); }); - console.log('finished writing ops'); + if (bulkWriteOps.length) console.log(`Wrote ${bulkWriteOps.length} props`); } // This is more efficient on the database, but significantly less efficient diff --git a/app/imports/api/engine/computeCreature.js b/app/imports/api/engine/computeCreature.js index 9d404289..9817f754 100644 --- a/app/imports/api/engine/computeCreature.js +++ b/app/imports/api/engine/computeCreature.js @@ -3,9 +3,11 @@ import computeCreatureComputation from './computation/computeCreatureComputation import writeAlteredProperties from './computation/writeComputation/writeAlteredProperties.js'; export default function computeCreature(creatureId){ + console.time('Compute creature'); const computation = buildCreatureComputation(creatureId); computeCreatureComputation(computation); writeAlteredProperties(computation); + console.timeEnd('Compute creature'); } // For now just recompute the whole creature, TODO only recompute a single diff --git a/app/imports/api/engine/oldActions/applyAttack.js b/app/imports/api/engine/oldActions/applyAttack.js index e3774041..fb157ec5 100644 --- a/app/imports/api/engine/oldActions/applyAttack.js +++ b/app/imports/api/engine/oldActions/applyAttack.js @@ -9,7 +9,7 @@ export default function applyAttack({ let value = roll(1, 20)[0]; actionContext.attackRoll = {value}; let criticalHitTarget = creature.variables.criticalHitTarget && - creature.variables.criticalHitTarget.currentValue || 20; + creature.variables.criticalHitTarget.value || 20; let criticalHit = value >= criticalHitTarget; if (criticalHit) actionContext.criticalHit = {value: true}; let result = value + prop.rollBonusResult; diff --git a/app/imports/api/engine/oldActions/castSpellWithSlot.js b/app/imports/api/engine/oldActions/castSpellWithSlot.js index 54d4686c..74ef41c3 100644 --- a/app/imports/api/engine/oldActions/castSpellWithSlot.js +++ b/app/imports/api/engine/oldActions/castSpellWithSlot.js @@ -49,7 +49,7 @@ const castSpellWithSlot = new ValidatedMethod({ throw new Meteor.Error('No slot', 'Slot not found to cast spell'); } - if (!slot.currentValue){ + if (!slot.value){ throw new Meteor.Error('No slot', 'Slot depleted'); } diff --git a/app/imports/api/properties/Attacks.js b/app/imports/api/properties/Attacks.js index c0e947d5..ce4a6687 100644 --- a/app/imports/api/properties/Attacks.js +++ b/app/imports/api/properties/Attacks.js @@ -10,7 +10,6 @@ let AttackSchema = new SimpleSchema() // What gets added to the d20 roll rollBonus: { type: 'fieldToCompute', - parseLevel: 'compile', optional: true, defaultValue: 'strength.modifier + proficiencyBonus', }, @@ -36,7 +35,6 @@ const ComputedOnlyAttackSchema = new SimpleSchema() .extend(createPropertySchema({ rollBonus: { type: 'computedOnlyField', - parseLevel: 'compile', optional: true, }, })); diff --git a/app/imports/ui/creature/character/CharacterSheetToolbar.vue b/app/imports/ui/creature/character/CharacterSheetToolbar.vue index d8b4c549..ab087d56 100644 --- a/app/imports/ui/creature/character/CharacterSheetToolbar.vue +++ b/app/imports/ui/creature/character/CharacterSheetToolbar.vue @@ -225,11 +225,6 @@ export default { }, }, meteor: { - $subscribe: { - 'singleCharacter'(){ - return [this.creatureId]; - }, - }, creature(){ return Creatures.findOne(this.creatureId); }, diff --git a/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue b/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue index 678f55ca..e36938e8 100644 --- a/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue +++ b/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue @@ -142,7 +142,7 @@ class="resource" > {{ model.actionType }} -
- {{ usesLeft }} uses +
+ {{ model.usesLeft }} uses
@@ -71,9 +71,7 @@ diff --git a/app/imports/ui/properties/viewers/SkillViewer.vue b/app/imports/ui/properties/viewers/SkillViewer.vue index df8be16a..8f78a69b 100644 --- a/app/imports/ui/properties/viewers/SkillViewer.vue +++ b/app/imports/ui/properties/viewers/SkillViewer.vue @@ -222,7 +222,7 @@ export default { let creature = Creatures.findOne(creatureId) return creature && creature.variables.proficiencyBonus && - creature.variables.proficiencyBonus.currentValue; + creature.variables.proficiencyBonus.value; }, }, }