Refactored actions, 'cast a spell' task now works

This commit is contained in:
Thaum Rystra
2024-10-28 12:28:36 +02:00
parent 804c5f3aee
commit 8f8c9c28aa
39 changed files with 423 additions and 399 deletions

View File

@@ -92,14 +92,19 @@ export default {
},
check() {
this.checkLoading = true;
doAction(this.model, this.$store, `check-btn-${this.model._id}`, {
subtaskFn: 'check',
prop: this.model,
targetIds: [this.model.root.id],
advantage: this.model.advantage,
skillVariableName: undefined,
abilityVariableName: this.model.variableName,
dc: null,
doAction({
creatureId: this.model.root.id,
$store: this.$store,
elementId: `check-btn-${this.model._id}`,
task: {
subtaskFn: 'check',
prop: this.model,
targetIds: [this.model.root.id],
advantage: this.model.advantage,
skillVariableName: undefined,
abilityVariableName: this.model.variableName,
dc: null,
},
}).catch(error => {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);

View File

@@ -77,14 +77,19 @@ export default {
signed: numberToSignedString,
check(){
this.checkLoading = true;
doAction(this.model, this.$store, `check-btn-${this.model._id}`, {
subtaskFn: 'check',
prop: this.model,
targetIds: [this.model.root.id],
advantage: this.model.advantage,
skillVariableName: this.model.variableName,
abilityVariableName: this.model.ability,
dc: null,
doAction({
creatureId: this.model.root.id,
$store: this.$store,
elementId: `check-btn-${this.model._id}`,
task: {
subtaskFn: 'check',
prop: this.model,
targetIds: [this.model.root.id],
advantage: this.model.advantage,
skillVariableName: this.model.variableName,
abilityVariableName: this.model.ability,
dc: null,
},
}).catch(error => {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);

View File

@@ -22,6 +22,7 @@
color="accent"
style="width: 100%;"
outlined
data-id="cast-spell-btn"
@click="castSpell"
>
Cast a spell
@@ -32,8 +33,8 @@
<script lang="js">
import SpellSlotListTile from '/imports/client/ui/properties/components/attributes/SpellSlotListTile.vue';
import doAction from '/imports/client/ui/creature/actions/doAction';
import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue';
import doCastSpell from '/imports/api/engine/action/methods/doCastSpell';
export default {
components: {
@@ -50,38 +51,31 @@ export default {
default: () => [],
},
},
data(){return {
castSpellLoading: false,
}},
methods: {
castSpell() {
this.$store.commit('pushDialogStack', {
component: 'cast-spell-with-slot-dialog',
elementId: 'spell-slot-card',
data: {
creatureId: this.creatureId,
},
callback({ spellId, slotId, advantage, ritual } = {}) {
if (!spellId) return;
doCastSpell.call({
spellId,
slotId,
ritual,
scope: {
'~attackAdvantage': { value: advantage },
},
}, error => {
if (!error) return;
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);
});
},
this.castSpellLoading = true;
doAction({
creatureId: this.model.root.id,
propId: this.model._id,
$store: this.$store,
elementId: `spell-slot-card-${this.model._id}`
}).catch(error => {
snackbar({ text: error.reason || error.message || error.toString() });
console.error(error);
}).finally(() => {
this.castSpellLoading = false;
});
},
clickProperty({ _id }) {
this.$store.commit('pushDialogStack', {
component: 'creature-property-dialog',
elementId: `spell-slot-card-${_id}`,
elementId: 'cast-spell-btn',
data: { _id },
});
},
}
}
</script>../../../../../api/engine/action/methods/doCastSpell
</script>

View File

@@ -1,6 +1,7 @@
<template lang="html">
<v-list-item
:key="model._id"
:data-id="`spell-slot-list-tile-${model._id}`"
class="spell-slot-list-tile"
v-bind="$attrs"
v-on="hasClickListener ? {click} : {}"
@@ -91,16 +92,15 @@ export default {
this.$emit('click', e);
},
disabled(i) {
if (!this.context.editPermission) return true;
// Use these if only the next filled or empty slot can be clicked
// if (this.model.value === i) return false;
// if (this.model.value === i - 1) return false;
// return true
return false;
return !this.context.editPermission;
},
damageProperty({ type, value, ack }) {
const model = this.model;
doAction(model, this.$store, model._id, {
doAction({
creatureId: model.root.id,
$store: this.$store,
elementId: `spell-slot-list-tile-${model._id}`,
task: {
subtaskFn: 'damageProp',
prop: model,
targetIds: [model.root.id],
@@ -110,7 +110,7 @@ export default {
value,
targetProp: model,
}
}).then(() =>{
}}).then(() =>{
ack?.();
}).catch((error) => {
if (ack) {