Iterated on action dialog

This commit is contained in:
Thaum Rystra
2023-12-06 19:58:01 +02:00
parent 64a1bfeda5
commit 8fe040a12a
3 changed files with 23 additions and 19 deletions

View File

@@ -14,9 +14,10 @@ import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
const Actions = new Mongo.Collection<ActionWithId>('actions'); const Actions = new Mongo.Collection<Action>('actions');
export interface Action { export interface Action {
_id?: string;
creatureId: string; creatureId: string;
rootPropId: string; rootPropId: string;
targetIds?: string[]; targetIds?: string[];
@@ -25,10 +26,6 @@ export interface Action {
results: TaskResult[]; results: TaskResult[];
} }
interface ActionWithId extends Action {
_id: string;
}
type Task = PropTask | DamagePropTask; type Task = PropTask | DamagePropTask;
interface BaseTask { interface BaseTask {
@@ -275,8 +272,9 @@ export const insertAction: ValidatedMethod = new ValidatedMethod({
// First remove all other actions on this creature // First remove all other actions on this creature
// only do one action at a time, don't wait for this to finish // only do one action at a time, don't wait for this to finish
Actions.removeAsync({ creatureId: action.creatureId }); Actions.removeAsync({ creatureId: action.creatureId });
const actionId = await Actions.insertAsync(action); // Force a random id even if one was provided, we may use it later as the seed for PRNG
return actionId; delete action._id;
return await Actions.insertAsync(action);
}, },
}); });
@@ -306,7 +304,7 @@ export const runAction = new ValidatedMethod({
}); });
// Run an already created action // 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 given an actionId, find the action document
if (typeof action === 'string') { if (typeof action === 'string') {
const foundAction = await Actions.findOneAsync(action); 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 = {}; const $set = {};
for (const key of ActionSchema.objectKeys()) { for (const key of ActionSchema.objectKeys()) {
if (!EJSON.equals(original[key], changed[key])) { if (!EJSON.equals(original[key], changed[key])) {
$set[key] = changed[key]; $set[key] = changed[key];
} }
} }
if (!isEmpty($set)) { if (!isEmpty($set) && original._id) {
return Actions.updateAsync(original._id, { $set }); return Actions.updateAsync(original._id, { $set });
} }
} }

View File

@@ -10,6 +10,11 @@
{{ actionJson }} {{ actionJson }}
</code> </code>
</pre> </pre>
<tree-node-view
v-for="prop in taskProps"
:key="prop._id"
:model="prop"
/>
<v-btn <v-btn
slot="actions" slot="actions"
text text
@@ -38,10 +43,13 @@
<script lang="js"> <script lang="js">
import DialogBase from '/imports/client/ui/dialogStack/DialogBase.vue'; import DialogBase from '/imports/client/ui/dialogStack/DialogBase.vue';
import Actions, { runAction } from '/imports/api/engine/actions/Actions'; 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 { export default {
components: { components: {
DialogBase, DialogBase,
TreeNodeView,
}, },
props: { props: {
actionId: { actionId: {
@@ -58,6 +66,12 @@ export default {
action() { action() {
return Actions.findOne(this.actionId); return Actions.findOne(this.actionId);
}, },
taskProps() {
if (!this.action) return;
return this.action.taskQueue.map(task => {
return CreatureProperties.findOne(task.propId);
});
},
}, },
computed: { computed: {
actionJson() { actionJson() {

View File

@@ -219,17 +219,9 @@ export default {
click(e) { click(e) {
this.$emit('click', e); this.$emit('click', e);
}, },
doAction({ advantage }) { doAction() {
this.doActionLoading = true;
this.shwing();
doAction(this.model, this.$store, this.model._id); doAction(this.model, this.$store, this.model._id);
}, },
shwing() {
this.activated = true;
setTimeout(() => {
this.activated = undefined;
}, 150);
}
} }
} }
</script> </script>