From 8fe040a12a38b71ba916589d5fcec13648f994cf Mon Sep 17 00:00:00 2001 From: Thaum Rystra <9525416+ThaumRystra@users.noreply.github.com> Date: Wed, 6 Dec 2023 19:58:01 +0200 Subject: [PATCH] Iterated on action dialog --- app/imports/api/engine/actions/Actions.ts | 18 ++++++++---------- .../ui/creature/actions/ActionDialog.vue | 14 ++++++++++++++ .../components/actions/ActionCard.vue | 10 +--------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/imports/api/engine/actions/Actions.ts b/app/imports/api/engine/actions/Actions.ts index 26592361..de2bebe4 100644 --- a/app/imports/api/engine/actions/Actions.ts +++ b/app/imports/api/engine/actions/Actions.ts @@ -14,9 +14,10 @@ import { assertEditPermission } from '/imports/api/sharing/sharingPermissions'; /* eslint-disable @typescript-eslint/no-explicit-any */ -const Actions = new Mongo.Collection('actions'); +const Actions = new Mongo.Collection('actions'); export interface Action { + _id?: string; creatureId: string; rootPropId: string; targetIds?: string[]; @@ -25,10 +26,6 @@ export interface Action { results: TaskResult[]; } -interface ActionWithId extends Action { - _id: string; -} - type Task = PropTask | DamagePropTask; interface BaseTask { @@ -275,8 +272,9 @@ export const insertAction: ValidatedMethod = new ValidatedMethod({ // First remove all other actions on this creature // only do one action at a time, don't wait for this to finish Actions.removeAsync({ creatureId: action.creatureId }); - const actionId = await Actions.insertAsync(action); - return actionId; + // Force a random id even if one was provided, we may use it later as the seed for PRNG + delete action._id; + return await Actions.insertAsync(action); }, }); @@ -306,7 +304,7 @@ export const runAction = new ValidatedMethod({ }); // Run an already created action -export async function runActionWork(action: string | ActionWithId, stepThrough?: boolean, userInput?) { +export async function runActionWork(action: string | Action, stepThrough?: boolean, userInput?) { // If given an actionId, find the action document if (typeof action === 'string') { const foundAction = await Actions.findOneAsync(action); @@ -384,14 +382,14 @@ async function applyNextTask(action: Action, userInput?) { }); } -function writeChangedAction(original: ActionWithId, changed: ActionWithId) { +function writeChangedAction(original: Action, changed: Action) { const $set = {}; for (const key of ActionSchema.objectKeys()) { if (!EJSON.equals(original[key], changed[key])) { $set[key] = changed[key]; } } - if (!isEmpty($set)) { + if (!isEmpty($set) && original._id) { return Actions.updateAsync(original._id, { $set }); } } diff --git a/app/imports/client/ui/creature/actions/ActionDialog.vue b/app/imports/client/ui/creature/actions/ActionDialog.vue index 6fc2dc8d..1dd84c04 100644 --- a/app/imports/client/ui/creature/actions/ActionDialog.vue +++ b/app/imports/client/ui/creature/actions/ActionDialog.vue @@ -10,6 +10,11 @@ {{ actionJson }} + import DialogBase from '/imports/client/ui/dialogStack/DialogBase.vue'; import Actions, { runAction } from '/imports/api/engine/actions/Actions'; +import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties'; +import TreeNodeView from '/imports/client/ui/properties/treeNodeViews/TreeNodeView.vue'; export default { components: { DialogBase, + TreeNodeView, }, props: { actionId: { @@ -58,6 +66,12 @@ export default { action() { return Actions.findOne(this.actionId); }, + taskProps() { + if (!this.action) return; + return this.action.taskQueue.map(task => { + return CreatureProperties.findOne(task.propId); + }); + }, }, computed: { actionJson() { diff --git a/app/imports/client/ui/properties/components/actions/ActionCard.vue b/app/imports/client/ui/properties/components/actions/ActionCard.vue index 19970705..df49a0d4 100644 --- a/app/imports/client/ui/properties/components/actions/ActionCard.vue +++ b/app/imports/client/ui/properties/components/actions/ActionCard.vue @@ -219,17 +219,9 @@ export default { click(e) { this.$emit('click', e); }, - doAction({ advantage }) { - this.doActionLoading = true; - this.shwing(); + doAction() { doAction(this.model, this.$store, this.model._id); }, - shwing() { - this.activated = true; - setTimeout(() => { - this.activated = undefined; - }, 150); - } } }