Implementing persisting action result mutations
This commit is contained in:
@@ -9,13 +9,13 @@ export const insertAction = new ValidatedMethod({
|
||||
validate: new SimpleSchema({
|
||||
action: ActionSchema
|
||||
}).validator({ clean: true }),
|
||||
run: async function ({ action }: { action: EngineAction }) {
|
||||
run: function ({ action }: { action: EngineAction }) {
|
||||
assertEditPermission(getCreature(action.creatureId), this.userId);
|
||||
// First remove all other actions on this creature
|
||||
// only do one action at a time, don't wait for this to finish
|
||||
EngineActions.removeAsync({ creatureId: action.creatureId });
|
||||
EngineActions.remove({ creatureId: action.creatureId });
|
||||
// Force a random id even if one was provided, we may use it later as the seed for PRNG
|
||||
delete action._id;
|
||||
return EngineActions.insertAsync(action);
|
||||
return EngineActions.insert(action);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ import EngineActions from '/imports/api/engine/action/EngineActions';
|
||||
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
|
||||
import { getCreature } from '/imports/api/engine/loadCreatures';
|
||||
import applyAction from '/imports/api/engine/action/functions/applyAction';
|
||||
import writeChangedAction from '../functions/writeChangedAction';
|
||||
import writeActionResults from '../functions/writeActionResults';
|
||||
import getReplayChoicesInputProvider from '/imports/api/engine/action/functions/userInput/getReplayChoicesInputProvider';
|
||||
|
||||
export const runAction = new ValidatedMethod({
|
||||
@@ -22,7 +22,7 @@ export const runAction = new ValidatedMethod({
|
||||
blackbox: true,
|
||||
},
|
||||
}).validator(),
|
||||
run: async function ({ actionId, decisions }: { actionId: string, decisions: any[] }) {
|
||||
run: async function ({ actionId, decisions = [] }: { actionId: string, decisions?: any[] }) {
|
||||
// Get the action
|
||||
const action = await EngineActions.findOneAsync(actionId);
|
||||
if (!action) throw new Meteor.Error('not-found', 'Action not found');
|
||||
@@ -30,9 +30,6 @@ export const runAction = new ValidatedMethod({
|
||||
// Permissions
|
||||
assertEditPermission(getCreature(action.creatureId), this.userId);
|
||||
|
||||
// Keep a copy of the original so that a diff can be done later to store what changed
|
||||
const originalAction = EJSON.clone(action);
|
||||
|
||||
// Replay the user's decisions as user input
|
||||
const userInput = getReplayChoicesInputProvider(actionId, decisions);
|
||||
|
||||
@@ -40,7 +37,7 @@ export const runAction = new ValidatedMethod({
|
||||
applyAction(action, userInput);
|
||||
|
||||
// Persist changes
|
||||
const writePromise = writeChangedAction(originalAction, action);
|
||||
const writePromise = writeActionResults(action);
|
||||
return writePromise;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user