Replaced damageProperty with new action engine

This commit is contained in:
ThaumRystra
2024-05-04 10:37:25 +02:00
parent 982897897f
commit c5f6ce81bd
9 changed files with 93 additions and 213 deletions

View File

@@ -12,7 +12,7 @@
v-for="healthBar in properties.attribute.healthBar"
:key="healthBar._id"
:model="healthBar"
@change="({ type, value }) => incrementChange(healthBar._id, { type, value: -value })"
@change="({ type, value }) => incrementChange(healthBar._id, { type, value })"
@click="clickProperty({_id: healthBar._id})"
/>
</v-card>
@@ -614,6 +614,7 @@ export default {
},
incrementChange(_id, { type, value, ack }) {
const model = CreatureProperties.findOne(_id);
if (type === 'increment') value = -value;
doAction(model, this.$store, model._id, {
subtaskFn: 'damageProp',
prop: model,
@@ -621,7 +622,7 @@ export default {
params: {
title: getPropertyTitle(model),
operation: type,
value: -value,
value,
targetProp: model,
}
}).then(() =>{

View File

@@ -72,7 +72,6 @@
<script lang="js">
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
import damageProperty from '/imports/api/creature/creatureProperties/methods/damageProperty';
import pushToProperty from '/imports/api/creature/creatureProperties/methods/pushToProperty';
import pullFromProperty from '/imports/api/creature/creatureProperties/methods/pullFromProperty';
import softRemoveProperty from '/imports/api/creature/creatureProperties/methods/softRemoveProperty';
@@ -94,6 +93,7 @@ import Breadcrumbs from '/imports/client/ui/creature/creatureProperties/Breadcru
import insertPropertyFromLibraryNode from '/imports/api/creature/creatureProperties/methods/insertPropertyFromLibraryNode';
import PropertyViewer from '/imports/client/ui/properties/shared/PropertyViewer.vue';
import copyPropertyToLibrary from '/imports/api/creature/creatureProperties/methods/copyPropertyToLibrary';
import doAction from '/imports/client/ui/creature/actions/doAction';
export default {
components: {
@@ -177,7 +177,27 @@ export default {
updateCreatureProperty.call({_id: this.currentId, path, value}, ack);
},
damage({operation, value, ack}){
damageProperty.call({_id: this.currentId, operation, value}, ack);
const model = this.model;
doAction(model, this.$store, model._id, {
subtaskFn: 'damageProp',
prop: model,
targetIds: [model.root.id],
params: {
title: getPropertyTitle(model),
operation: operation,
value,
targetProp: model,
}
}).then(() =>{
ack?.();
}).catch((error) => {
if (ack) {
ack(error);
} else {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);
}
});
},
push({path, value, ack}){
pushToProperty.call({_id: this.currentId, path, value}, ack);

View File

@@ -151,8 +151,9 @@ export default {
cancelEdit() {
this.editing = false;
},
changeIncrementMenu(e) {
this.$emit('change', e);
changeIncrementMenu({ type, value }) {
if (type === 'increment') value = -value;
this.$emit('change', { type, value });
this.editing = false;
}
},

View File

@@ -64,9 +64,10 @@
</template>
<script lang="js">
import damageProperty from '/imports/api/creature/creatureProperties/methods/damageProperty';
import numberToSignedString from '/imports/api/utility/numberToSignedString';
import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue';
import doAction from '/imports/client/ui/creature/actions/doAction';
import getPropertyTitle from '/imports/client/ui/properties/shared/getPropertyTitle';
export default {
inject: {
@@ -97,14 +98,24 @@ export default {
// return true
return false;
},
damageProperty({type, value, ack}) {
damageProperty.call({
_id: this.model._id,
operation: type,
value: value
}, error => {
if (ack) ack(error);
if (error) {
damageProperty({ type, value, ack }) {
const model = this.model;
doAction(model, this.$store, model._id, {
subtaskFn: 'damageProp',
prop: model,
targetIds: [model.root.id],
params: {
title: getPropertyTitle(model),
operation: type,
value,
targetProp: model,
}
}).then(() =>{
ack?.();
}).catch((error) => {
if (ack) {
ack(error);
} else {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);
}

View File

@@ -13,7 +13,7 @@
v-else-if="model.attributeType === 'hitDice'"
:model="model"
@click="$emit('click')"
@change="({ type, value }) => damageProperty({type, value: -value})"
@change="damageProperty"
/>
<health-bar
v-else-if="model.attributeType === 'healthBar'"
@@ -30,7 +30,7 @@
v-else-if="model.attributeType === 'resource'"
:model="model"
@click="$emit('click')"
@change="({ type, value, ack }) => damageProperty({type, value: -value, ack})"
@change="damageProperty"
@mouseover="hover = true"
@mouseleave="hover = false"
/>
@@ -62,8 +62,9 @@ import ResourceCardContent from '/imports/client/ui/properties/components/attrib
import AttributeCardContent from '/imports/client/ui/properties/components/attributes/AttributeCardContent.vue';
import CardHighlight from '/imports/client/ui/components/CardHighlight.vue';
import FolderGroupChildren from '/imports/client/ui/properties/components/folders/folderGroupComponents/FolderGroupChildren.vue';
import damageProperty from '/imports/api/creature/creatureProperties/methods/damageProperty';
import doAction from '/imports/client/ui/creature/actions/doAction';
import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue';
import getPropertyTitle from '/imports/client/ui/properties/shared/getPropertyTitle';
export default {
components: {
@@ -91,20 +92,30 @@ export default {
hover: false,
}},
methods: {
damageProperty(change) {
damageProperty.call({
_id: this.model._id,
operation: change.type,
value: change.value
}, e => {
console.log(change);
change.ack?.(e);
damageProperty({value, type, ack}) {
const model = this.model;
if (type === 'increment') value = -value;
doAction(model, this.$store, model._id, {
subtaskFn: 'damageProp',
prop: model,
targetIds: [model.root.id],
params: {
title: getPropertyTitle(model),
operation: type,
value,
targetProp: model,
}
}).then(() =>{
ack?.();
}).catch((error) => {
if (ack) {
ack(error);
} else {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);
}
});
},
log({_id}) {
console.log(...arguments)
this.$emit('click-property', { _id });
}
}
}
</script>

View File

@@ -141,12 +141,13 @@
import propertyViewerMixin from '/imports/client/ui/properties/viewers/shared/propertyViewerMixin'
import numberToSignedString from '../../../../api/utility/numberToSignedString';
import AttributeEffect from '/imports/client/ui/properties/components/attributes/AttributeEffect.vue';
import damageProperty from '/imports/api/creature/creatureProperties/methods/damageProperty';
import IncrementButton from '/imports/client/ui/components/IncrementButton.vue';
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
import getProficiencyIcon from '/imports/client/ui/utility/getProficiencyIcon';
import {snackbar} from '/imports/client/ui/components/snackbars/SnackbarQueue';
import sortEffects from '/imports/client/ui/utility/sortEffects';
import doAction from '/imports/client/ui/creature/actions/doAction';
import getPropertyTitle from '/imports/client/ui/properties/shared/getPropertyTitle';
export default {
components: {
@@ -208,18 +209,24 @@
data: {_id: id},
});
},
damageProperty({type, value}) {
damageProperty({ type, value }) {
const model = this.model;
this.damagePropertyLoading = true;
damageProperty.call({
_id: this.model._id,
operation: type,
value: value
}, error => {
this.damagePropertyLoading = false;
if (error){
snackbar({text: error.reason});
console.error(error);
doAction(model, this.$store, model._id, {
subtaskFn: 'damageProp',
prop: model,
targetIds: [model.root.id],
params: {
title: getPropertyTitle(model),
operation: type,
value,
targetProp: model,
}
}).catch((error) => {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);
}).finally(() => {
this.damagePropertyLoading = false;
});
},
},