Action interruption progress

This commit is contained in:
Thaum Rystra
2024-03-26 23:25:18 +02:00
parent 57220c7972
commit e083490cb3
12 changed files with 184 additions and 62 deletions

View File

@@ -0,0 +1,3 @@
import './insertAction';
import './runAction';
import './updateAction';

View File

@@ -4,7 +4,7 @@ import EngineActions, { EngineAction, ActionSchema } from '/imports/api/engine/a
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
import { getCreature } from '/imports/api/engine/loadCreatures';
export const insertAction: ValidatedMethod = new ValidatedMethod({
export const insertAction = new ValidatedMethod({
name: 'actions.insertAction',
validate: new SimpleSchema({
action: ActionSchema
@@ -16,6 +16,6 @@ export const insertAction: ValidatedMethod = new ValidatedMethod({
EngineActions.removeAsync({ 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 await EngineActions.insertAsync(action);
return EngineActions.insertAsync(action);
},
});

View File

@@ -0,0 +1,22 @@
import { ValidatedMethod } from 'meteor/mdg:validated-method';
import EngineActions from '/imports/api/engine/action/EngineActions';
import { assertEditPermission } from '/imports/api/sharing/sharingPermissions';
import { getCreature } from '/imports/api/engine/loadCreatures';
export const updateAction = new ValidatedMethod({
name: 'actions.updateAction',
validate({ _id, path, value }) {
if (!_id) throw new Meteor.Error('No _id', '_id is required');
// We cannot change these fields with a simple update
if (path !== 'targetIds') throw new Meteor.Error('Can only update target ids');
if (!Array.isArray(value)) throw new Meteor.Error('TargetIds must be an array');
},
run: async function ({ _id, path, value }: { _id: string, path: 'targetIds', value: string[] }) {
const action = await EngineActions.findOneAsync(_id);
if (!action) {
throw new Meteor.Error('not found', 'The given action was not found');
}
assertEditPermission(getCreature(action.creatureId), this.userId);
return EngineActions.updateAsync(_id, { $set: { [path]: value } });
},
});