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

@@ -16,6 +16,7 @@
:style="{
fontSize: '24px'
}"
data-id="do-action-button"
:color="model.color || 'primary'"
:loading="doActionLoading"
:disabled="model.insufficientResources || !context.editPermission"
@@ -217,7 +218,12 @@ export default {
doAction() {
this.doActionLoading = true;
this.$emit('close-menu')
doAction(this.model, this.$store, this.model._id).catch((e) => {
doAction({
propId: this.model._id,
creatureId: this.model.root.id,
$store: this.$store,
elementId: 'do-action-button',
}).catch((e) => {
console.error(e);
snackbar({ text: e.message || e.reason || e.toString() });
}).finally(() => {

View File

@@ -57,8 +57,6 @@
import { getPropertyName } from '/imports/constants/PROPERTIES.js';
import numberToSignedString from '/imports/api/utility/numberToSignedString.js';
import doAction from '/imports/client/ui/creature/actions/doAction';
import AttributeConsumedView from '/imports/client/ui/properties/components/actions/AttributeConsumedView.vue';
import ItemConsumedView from '/imports/client/ui/properties/components/actions/ItemConsumedView.vue';
import PropertyIcon from '/imports/client/ui/properties/shared/PropertyIcon.vue';
import MarkdownText from '/imports/client/ui/components/MarkdownText.vue';
import { snackbar } from '/imports/client/ui/components/snackbars/SnackbarQueue.js';
@@ -69,8 +67,6 @@ import { some } from 'lodash';
export default {
components: {
AttributeConsumedView,
ItemConsumedView,
MarkdownText,
PropertyIcon,
TreeNodeList,
@@ -175,7 +171,12 @@ export default {
doAction() {
this.doActionLoading = true;
this.$emit('close-menu')
doAction(this.model, this.$store, this.model._id).catch((e) => {
doAction({
propId: this.model._id,
creatureId: this.model.root.id,
$store: this.$store,
elementId: 'do-action-button',
}).catch((e) => {
console.error(e);
snackbar({ text: e.message || e.reason || e.toString() });
}).finally(() => {

View File

@@ -166,7 +166,9 @@ export default {
actions(){
return getProperties(this.activeCreatureId, { type: 'action', actionType: { $ne: 'event'} });
},
moreTargets(){
moreTargets() {
// Disable portrait targeting for now, they aren't used by the action engine yet
return false;
const activeAction = CreatureProperties.findOne(this.activeActionId);
if (!activeAction) return;
if (activeAction.target === 'singleTarget') {

View File

@@ -52,6 +52,7 @@
<v-card
v-else-if="activeIcon && activeIcon.tab"
style="width: 300px"
data-id="tabletop-standard-card"
>
<v-card-title>
<v-icon left>
@@ -167,33 +168,15 @@ import CreatureProperties from '/imports/api/creature/creatureProperties/Creatur
import TabletopActionCard from '/imports/client/ui/tabletop/TabletopActionCard.vue';
import TabletopBuffCard from '/imports/client/ui/tabletop/TabletopBuffCard.vue';
import CreatureBarIcon from '/imports/client/ui/tabletop/selectedCreatureBar/CreatureBarIcon.vue';
import { compact } from 'lodash';
//import TabletopPortrait from '/imports/client/ui/tabletop/selectedCreatureBar/TabletopPortrait.vue';
//import TabletopBuffIcons from '/imports/client/ui/tabletop/selectedCreatureBar/TabletopBuffIcons.vue';
//import TabletopActions from '/imports/client/ui/tabletop/selectedCreatureBar/TabletopActions.vue';
//import TabletopGroupedFolders from '/imports/client/ui/tabletop/selectedCreatureBar/TabletopGroupedFolders.vue';
//import TabletopResources from '/imports/client/ui/tabletop/selectedCreatureBar/TabletopResources.vue';
//import TabletopCreatureSheetTabs from '/imports/client/ui/tabletop/selectedCreatureBar/TabletopCreatureSheetTabs.vue';
//import TabletopDetailPopover from '/imports/client/ui/tabletop/selectedCreatureBar/TabletopDetailPopover.vue';
import { compact, chunk } from 'lodash';
import doAction from '../../creature/actions/doAction';
function splitToNChunks(inputArray, n) {
let result = [];
const array = [...inputArray] // Create shallow copy, because splice mutates array
for (let i = n; i > 0; i--) {
result.push(array.splice(0, Math.ceil(array.length / i)));
}
return result;
return chunk(inputArray, Math.ceil(inputArray.length / n));
}
export default {
components: {
//TabletopPortrait,
//TabletopBuffIcons,
//TabletopActions,
//TabletopGroupedFolders,
//TabletopResources,
//TabletopCreatureSheetTabs,
CreatureBarIcon,
TabletopActionCard,
TabletopBuffCard,
@@ -261,6 +244,7 @@ export default {
}
if (icon.actionName) {
this.openStandardAction(icon.standardId)
return;
}
if (this.selectedIcon === icon) {
this.selectedIcon = undefined;
@@ -285,6 +269,7 @@ export default {
return outside;
},
openCharacterSheet(tab, elementId) {
this.menuOpen = false;
this.$store.commit(
'setTabForCharacterSheet',
{ id: this.creatureId, tab }
@@ -296,13 +281,26 @@ export default {
creatureId: this.creatureId,
},
});
this.menuOpen = false;
},
openStandardAction(standardId) {
// TODO standard action dialogs
this.menuOpen = false;
if (standardId === 'cast-spell') {
doAction({
creatureId: this.creatureId,
$store: this.$store,
elementId: standardId,
task: {
subtaskFn: 'castSpell',
targetIds: [],
params: {
spellId: undefined,
},
},
});
}
},
openPropertyDetails(elementId) {
this.menuOpen = false;
const propId = this.selectedProp._id;
this.$store.commit('pushDialogStack', {
component: 'creature-property-dialog',
@@ -310,8 +308,6 @@ export default {
data: { _id: propId },
callback: () => propId
});
// Close the menu while the dialog is open
this.menuOpen = false;
},
},
meteor: {
@@ -344,7 +340,7 @@ export default {
// Get the folders that could hide a property
const folderGroupsById = {};
CreatureProperties.find({
CreatureProperties.find({
'root.id': this.creatureId,
type: 'folder',
groupStats: true,
@@ -475,4 +471,4 @@ export default {
.tabletop-prop-menu.rows-4 {
bottom: 212px;
}
</style>
</style>