From dfa3b057b06c4f4f4cd28d5291be95e9b8741642 Mon Sep 17 00:00:00 2001 From: Thaum Rystra Date: Wed, 4 Mar 2020 09:56:06 +0200 Subject: [PATCH] Fixed property adjustments on the stats page --- .../api/creature/CreatureProperties.js | 21 +++++++--- .../character/characterSheetTabs/StatsTab.vue | 38 ++++++++----------- .../ui/properties/attributes/HealthBar.vue | 4 +- .../properties/attributes/HealthBarCard.vue | 2 +- .../attributes/HealthBarCardContainer.vue | 13 ++++--- .../ui/properties/attributes/ResourceCard.vue | 2 +- app/imports/ui/properties/forms/SkillForm.vue | 5 ++- 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/app/imports/api/creature/CreatureProperties.js b/app/imports/api/creature/CreatureProperties.js index 7a7e6201..86629ac2 100644 --- a/app/imports/api/creature/CreatureProperties.js +++ b/app/imports/api/creature/CreatureProperties.js @@ -183,7 +183,7 @@ const damageProperty = new ValidatedMethod({ run({_id, operation, value}) { let currentProperty = CreatureProperties.findOne(_id); // Check permissions - assertPropertyEditPermission(currentProperty, this.UserId); + assertPropertyEditPermission(currentProperty, this.userId); // Check if property can take damage let schema = CreatureProperties.simpleSchema(currentProperty); if (!schema.allowsKey('damage')){ @@ -194,23 +194,34 @@ const damageProperty = new ValidatedMethod({ } if (operation === 'set'){ let currentValue = currentProperty.value; + console.log('currentValue is ', currentValue) + console.log('target value is ', value) // Set represents what we want the value to be after damage // So we need the actual damage to get to that value let damage = currentValue - value; + console.log('required damage is ', damage) // Damage can't exceed total value if (damage > currentValue) damage = currentValue; // Damage must be positive if (damage < 0) damage = 0; - CreatureProperties.update(_id, {$set: {damage}}); + CreatureProperties.update(_id, { + $set: {damage} + }, { + selector: currentProperty + }); } else if (operation === 'increment'){ - let currentValue = currentAttribute.value - (currentAttribute.damage || 0); - let currentDamage = currentAttribute.damage; + let currentValue = currentProperty.value - (currentProperty.damage || 0); + let currentDamage = currentProperty.damage; let increment = value; // Can't increase damage above the remaining value if (increment > currentValue) increment = currentValue; // Can't decrease damage below zero if (-increment > currentDamage) increment = -currentDamage; - CreatureProperties.update(_id, {$inc: {damage: increment}}); + CreatureProperties.update(_id, { + $inc: {damage: increment} + }, { + selector: currentProperty + }); } recomputeCreatures(currentProperty); }, diff --git a/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue b/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue index aec233d5..ede09229 100644 --- a/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue +++ b/app/imports/ui/creature/character/characterSheetTabs/StatsTab.vue @@ -15,8 +15,8 @@ @@ -27,7 +27,7 @@ @@ -35,7 +35,7 @@ @@ -43,7 +43,7 @@ @@ -57,7 +57,7 @@ v-bind="hitDie" :data-id="hitDie._id" :key="hitDice._id" - @click="clickAttribute({_id: hitDie._id})" + @click="clickProperty({_id: hitDie._id})" @change="e => incrementChange(hitDie._id, e)" /> @@ -74,7 +74,7 @@ v-bind="save" :key="save._id" :data-id="save._id" - @click="clickSkill({_id: save._id})" + @click="clickProperty({_id: save._id})" /> @@ -89,7 +89,7 @@ v-bind="skill" :key="skill._id" :data-id="skill._id" - @click="clickSkill({_id: skill._id})" + @click="clickProperty({_id: skill._id})" /> @@ -103,7 +103,7 @@ @@ -117,7 +117,7 @@ v-bind="spellSlot" :key="spellSlot._id" :data-id="spellSlot._id" - @click="clickAttribute({_id: spellSlot._id})" + @click="clickProperty({_id: spellSlot._id})" @change="e => incrementChange(spellSlot._id, e)" /> @@ -128,8 +128,7 @@