Fixed Incrementing props from stats tab

This commit is contained in:
ThaumRystra
2024-05-03 14:29:42 +02:00
parent de1eb64285
commit 982897897f
4 changed files with 19 additions and 116 deletions

View File

@@ -124,8 +124,8 @@ export default async function applyDamagePropTask(
type: targetProp.type,
}],
contents: [{
name: 'Attribute damaged',
value: `${numberToSignedString(-value)} ${getPropertyTitle(targetProp)}`,
name: increment >= 0 ? 'Attribute damaged' : 'Attribute restored',
value: `${numberToSignedString(-increment)} ${getPropertyTitle(targetProp)}`,
inline: true,
...prop.silent && { silenced: true },
}]

View File

@@ -392,7 +392,6 @@
<script lang="js">
import Creatures from '/imports/api/creature/creatures/Creatures';
import softRemoveProperty from '/imports/api/creature/creatureProperties/methods/softRemoveProperty';
import damageProperty from '/imports/api/creature/creatureProperties/methods/damageProperty';
import HealthBar from '/imports/client/ui/properties/components/attributes/HealthBar.vue';
import AttributeCard from '/imports/client/ui/properties/components/attributes/AttributeCard.vue';
import AbilityListTile from '/imports/client/ui/properties/components/attributes/AbilityListTile.vue';
@@ -412,6 +411,8 @@ import FolderGroupCard from '/imports/client/ui/properties/components/folders/Fo
import { get, set, uniqBy } from 'lodash';
import { docsToForest } from '/imports/api/parenting/parentingFunctions';
import { getFilter } from '/imports/api/parenting/parentingFunctions';
import doAction from '/imports/client/ui/creature/actions/doAction';
import getPropertyTitle from '/imports/client/ui/properties/shared/getPropertyTitle';
function walkDown(forest, callback){
let stack = [...forest];
@@ -517,7 +518,6 @@ export default {
return uniqBy(conditionals, '_id');
},
},
// @ts-ignore Meteor isn't defined on vue
meteor: {
properties() {
const creature = this.creature;
@@ -613,14 +613,23 @@ export default {
});
},
incrementChange(_id, { type, value, ack }) {
damageProperty.call({
_id,
operation: type,
value: -value
}, error => {
const model = CreatureProperties.findOne(_id);
doAction(model, this.$store, model._id, {
subtaskFn: 'damageProp',
prop: model,
targetIds: [model.root.id],
params: {
title: getPropertyTitle(model),
operation: type,
value: -value,
targetProp: model,
}
}).then(() =>{
ack?.();
}).catch((error) => {
if (ack) {
ack(error);
} else if (error) {
} else {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);
}
@@ -637,7 +646,3 @@ export default {
},
};
</script>
<style lang="css" scoped>
</style>

View File

@@ -1,27 +0,0 @@
<template lang="html">
<v-card class="pa-2">
<health-bar
v-for="attribute in attributes"
:key="attribute._id"
:model="attribute"
@change="e => $emit('change', {_id: attribute._id, change: e})"
@click="e => $emit('click', {_id: attribute._id})"
/>
</v-card>
</template>
<script lang="js">
import HealthBar from '/imports/client/ui/properties/components/attributes/HealthBar.vue';
export default {
components: {
HealthBar,
},
props: {
attributes: {
type: Array,
required: true
},
},
}
</script>

View File

@@ -1,75 +0,0 @@
<template lang="html">
<div
v-if="attributes.length"
class="px-2 pt-2"
>
<health-bar-card
:attributes="attributes"
@change="healthBarChanged"
@click="healthBarClicked"
/>
</div>
</template>
<script lang="js">
import Creatures from '/imports/api/creature/creatures/Creatures';
import damageProperty from '/imports/api/creature/creatureProperties/methods/damageProperty';
import HealthBarCard from '/imports/client/ui/properties/components/attributes/HealthBarCard.vue';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
export default {
components: {
HealthBarCard,
},
props: {
creatureId: {
type: String,
required: true
},
},
meteor: {
creature() {
return Creatures.findOne(this.creatureId, { fields: { settings: 1 } });
},
attributes() {
let creature = this.creature;
if (!creature) return;
let filter = {
'ancestors.id': creature._id,
type: 'attribute',
attributeType: 'healthBar',
removed: { $ne: true },
inactive: { $ne: true },
overridden: { $ne: true },
$nor: [
{ hideWhenTotalZero: true, total: 0 },
{ hideWhenValueZero: true, value: 0 },
],
};
if (creature.settings.hideUnusedStats) {
filter.hide = { $ne: true };
}
return CreatureProperties.find(filter, {
sort: { left: 1 }
});
},
},
methods: {
healthBarClicked({ _id }) {
this.$store.commit('pushDialogStack', {
component: 'creature-property-dialog',
elementId: `${_id}`,
data: { _id },
});
},
healthBarChanged({ _id, change }) {
damageProperty.call({
_id,
operation: change.type,
value: change.value
});
},
},
};
</script>