refactored action engine into individual files
This commit is contained in:
135
app/imports/api/engine/action/EngineActions.ts
Normal file
135
app/imports/api/engine/action/EngineActions.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import TaskResult from './tasks/TaskResult';
|
||||
import LogContentSchema from '/imports/api/creature/log/LogContentSchema';
|
||||
|
||||
const EngineActions = new Mongo.Collection<EngineAction>('actions');
|
||||
|
||||
export interface EngineAction {
|
||||
_id?: string;
|
||||
_isSimulation?: boolean;
|
||||
_stepThrough?: boolean;
|
||||
creatureId: string;
|
||||
rootPropId: string;
|
||||
targetIds?: string[];
|
||||
results: TaskResult[];
|
||||
taskCount: number;
|
||||
}
|
||||
|
||||
const ActionSchema = new SimpleSchema({
|
||||
creatureId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
rootPropId: {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
targetIds: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'targetIds.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
userInputNeeded: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
|
||||
// Applied properties
|
||||
results: {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'results.$': {
|
||||
type: Object,
|
||||
},
|
||||
// The property and target ids popped off the task stack
|
||||
// Pushing these to the top of the stack and deleting the results from this point onwards
|
||||
// Should re-run the action identically from this point
|
||||
'results.$.propId': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
'results.$.targetIds': {
|
||||
type: Array,
|
||||
defaultValue: [],
|
||||
},
|
||||
'results.$.targetIds.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
// Changes that override the local scope
|
||||
'results.$.scope': {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
// Changes that consume pushed values from the local scope
|
||||
'results.$.popScope': {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
// Changes that push values to the local scope
|
||||
'results.$.pushScope': {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
// database changes
|
||||
'results.$.mutations': {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'results.$.mutations.$': {
|
||||
type: Object,
|
||||
},
|
||||
'results.$.mutations.$.targetIds': {
|
||||
type: Array,
|
||||
},
|
||||
'results.$.mutations.$.targetIds.$': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
'results.$.mutations.$.updates': {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'results.$.mutations.$.updates.$': {
|
||||
type: Object,
|
||||
},
|
||||
'results.$.mutations.$.updates.$.propId': {
|
||||
type: String,
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
},
|
||||
// Required, because CreatureProperties.update requires a selector of { type }
|
||||
'results.$.mutations.$.updates.$.type': {
|
||||
type: String,
|
||||
},
|
||||
'results.$.mutations.$.updates.$.set': {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
'results.$.mutations.$.updates.$.inc': {
|
||||
type: Object,
|
||||
optional: true,
|
||||
blackbox: true,
|
||||
},
|
||||
'results.$.mutations.$.contents': {
|
||||
type: Array,
|
||||
optional: true,
|
||||
},
|
||||
'results.$.mutations.$.contents.$': {
|
||||
type: LogContentSchema,
|
||||
},
|
||||
});
|
||||
|
||||
// @ts-expect-error Collections2 lacks TypeScript support
|
||||
EngineActions.attachSchema(ActionSchema);
|
||||
|
||||
export default EngineActions;
|
||||
export { ActionSchema }
|
||||
Reference in New Issue
Block a user