Fixed property adjustments on the stats page
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
<ability-list-tile
|
||||
v-bind="ability"
|
||||
:key="ability._id"
|
||||
:data-id="`ability-list-tile-${ability._id}`"
|
||||
@click="clickAttribute({_id: ability._id})"
|
||||
:data-id="ability._id"
|
||||
@click="clickProperty({_id: ability._id})"
|
||||
/>
|
||||
</template>
|
||||
</v-list>
|
||||
@@ -27,7 +27,7 @@
|
||||
<attribute-card
|
||||
v-bind="stat"
|
||||
:data-id="stat._id"
|
||||
@click="clickAttribute({_id: stat._id})"
|
||||
@click="clickProperty({_id: stat._id})"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<attribute-card modifier
|
||||
v-bind="modifier"
|
||||
:data-id="modifier._id"
|
||||
@click="clickAttribute({_id: modifier._id})"
|
||||
@click="clickProperty({_id: modifier._id})"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<attribute-card modifier
|
||||
v-bind="check"
|
||||
:data-id="check._id"
|
||||
@click="clickSkill({_id: check._id})"
|
||||
@click="clickProperty({_id: check._id})"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -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)"
|
||||
/>
|
||||
</template>
|
||||
@@ -74,7 +74,7 @@
|
||||
v-bind="save"
|
||||
:key="save._id"
|
||||
:data-id="save._id"
|
||||
@click="clickSkill({_id: save._id})"
|
||||
@click="clickProperty({_id: save._id})"
|
||||
/>
|
||||
</v-list>
|
||||
</v-card>
|
||||
@@ -89,7 +89,7 @@
|
||||
v-bind="skill"
|
||||
:key="skill._id"
|
||||
:data-id="skill._id"
|
||||
@click="clickSkill({_id: skill._id})"
|
||||
@click="clickProperty({_id: skill._id})"
|
||||
/>
|
||||
</v-list>
|
||||
</v-card>
|
||||
@@ -103,7 +103,7 @@
|
||||
<resource-card
|
||||
v-bind="resource"
|
||||
:data-id="resource._id"
|
||||
@click="clickAttribute({_id: resource._id})"
|
||||
@click="clickProperty({_id: resource._id})"
|
||||
@change="e => incrementChange(resource._id, e)"
|
||||
/>
|
||||
</div>
|
||||
@@ -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)"
|
||||
/>
|
||||
</v-list>
|
||||
@@ -128,8 +128,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
|
||||
import CreatureProperties, { damageProperty } from '/imports/api/creature/CreatureProperties.js';
|
||||
import AttributeCard from '/imports/ui/properties/attributes/AttributeCard.vue';
|
||||
import AbilityListTile from '/imports/ui/properties/attributes/AbilityListTile.vue';
|
||||
import ColumnLayout from '/imports/ui/components/ColumnLayout.vue';
|
||||
@@ -217,7 +216,7 @@
|
||||
conMod,
|
||||
key: hd._id,
|
||||
maxValue: hd.value,
|
||||
value: hd.value + (hd.adjustment || 0),
|
||||
value: hd.value - (hd.damage || 0),
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -250,23 +249,16 @@
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
clickAttribute({_id}){
|
||||
clickProperty({_id}){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'creature-property-dialog',
|
||||
elementId: `ability-list-tile-${_id}`,
|
||||
data: {_id},
|
||||
});
|
||||
},
|
||||
clickSkill({_id}){
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'creature-property-dialog',
|
||||
elementId: _id,
|
||||
elementId: `${_id}`,
|
||||
data: {_id},
|
||||
});
|
||||
},
|
||||
incrementChange(_id, {type, value}){
|
||||
if (type === 'increment'){
|
||||
adjustAttribute.call({_id, increment: value});
|
||||
damageProperty.call({_id, operation: 'increment' ,value: -value});
|
||||
}
|
||||
},
|
||||
insertAttribute(){
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</v-progress-linear>
|
||||
<span
|
||||
class="value"
|
||||
style="margin-top: -20px; z-index: 1; font-size: 16px; font-weight: 600; height: 20px;"
|
||||
style="margin-top: -20px; z-index: 1; font-size: 15px; font-weight: 600; height: 20px;"
|
||||
>
|
||||
{{ value }} / {{ maxValue }}
|
||||
</span>
|
||||
@@ -130,7 +130,7 @@
|
||||
this.editing = false;
|
||||
let value = +this.$refs.editInput.lazyValue;
|
||||
let type = this.operation === null ? 'set' : 'increment';
|
||||
if (this.operation === 1) {
|
||||
if (this.operation === 0) {
|
||||
value = -value;
|
||||
}
|
||||
this.$emit('change', { type, value });
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<health-bar
|
||||
v-for="attribute in attributes"
|
||||
:key="attribute._id"
|
||||
:value="attribute.value + (attribute.adjustment || 0)"
|
||||
:value="attribute.value - (attribute.damage || 0)"
|
||||
:maxValue="attribute.value"
|
||||
:name="attribute.name"
|
||||
:_id="attribute._id"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
import CreatureProperties, { damageProperty } from '/imports/api/creature/CreatureProperties.js';
|
||||
import HealthBarCard from '/imports/ui/properties/attributes/HealthBarCard.vue';
|
||||
|
||||
export default {
|
||||
@@ -31,16 +31,17 @@
|
||||
},
|
||||
methods: {
|
||||
healthBarClicked({_id}){
|
||||
this.$store.commit("pushDialogStack", {
|
||||
component: "attribute-dialog-container",
|
||||
elementId: _id,
|
||||
this.$store.commit('pushDialogStack', {
|
||||
component: 'creature-property-dialog',
|
||||
elementId: `${_id}`,
|
||||
data: {_id},
|
||||
});
|
||||
},
|
||||
healthBarChanged({_id, change}){
|
||||
adjustAttribute.call({
|
||||
damageProperty.call({
|
||||
_id,
|
||||
[change.type]: change.value
|
||||
operation: change.type,
|
||||
value: change.value
|
||||
});
|
||||
},
|
||||
},
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
},
|
||||
computed: {
|
||||
currentValue(){
|
||||
return this.value + (this.adjustment || 0);
|
||||
return this.value - (this.damage || 0);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
clearable
|
||||
:value="model.baseProficiency"
|
||||
:error-messages="errors.baseProficiency"
|
||||
@change="(value, ack) => $emit('change', {path: ['baseProficiency'], value, ack})"
|
||||
@change="(value, ack) => {$emit('change', {path: ['baseProficiency'], value: value || 0, ack}); log({value, ack})}"
|
||||
/>
|
||||
</div>
|
||||
</form-section>
|
||||
@@ -114,6 +114,9 @@
|
||||
},
|
||||
]
|
||||
};},
|
||||
methods: {
|
||||
log: console.log,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user