Tested and fixed triggers in new action engine
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
|||||||
allMutations,
|
allMutations,
|
||||||
allUpdates,
|
allUpdates,
|
||||||
createTestCreature,
|
createTestCreature,
|
||||||
randomIds,
|
getRandomIds,
|
||||||
removeAllCreaturesAndProps,
|
removeAllCreaturesAndProps,
|
||||||
runActionById
|
runActionById
|
||||||
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
|
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
|
||||||
@@ -17,7 +17,7 @@ const [
|
|||||||
usesActionId, attackMissId, attackNoTargetId, usesResourcesActionId, ammoId, resourceAttId,
|
usesActionId, attackMissId, attackNoTargetId, usesResourcesActionId, ammoId, resourceAttId,
|
||||||
consumeAmmoId, consumeResourceId, noUsesActionId, insufficientResourcesActionId,
|
consumeAmmoId, consumeResourceId, noUsesActionId, insufficientResourcesActionId,
|
||||||
attributeResetByEventId, eventActionId, advantageAttackId, advantageEffectId, disadvantageAttackId, disadvantageEffectId,
|
attributeResetByEventId, eventActionId, advantageAttackId, advantageEffectId, disadvantageAttackId, disadvantageEffectId,
|
||||||
] = randomIds;
|
] = getRandomIds(100);
|
||||||
|
|
||||||
const actionTestCreature = {
|
const actionTestCreature = {
|
||||||
_id: creatureId,
|
_id: creatureId,
|
||||||
|
|||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import { assert } from 'chai';
|
||||||
|
import {
|
||||||
|
allLogContent,
|
||||||
|
createTestCreature,
|
||||||
|
getRandomIds,
|
||||||
|
removeAllCreaturesAndProps,
|
||||||
|
runActionById
|
||||||
|
} from '/imports/api/engine/action/functions/actionEngineTest.testFn';
|
||||||
|
import CreatureProperties from '/imports/api/creature/creatureProperties/CreatureProperties';
|
||||||
|
|
||||||
|
const [
|
||||||
|
creatureId, targetCreatureId, targetCreature2Id, actionWithTriggerId, triggerBeforeActionId,
|
||||||
|
triggerAfterActionId, triggerAfterActionChildrenId
|
||||||
|
] = getRandomIds(100);
|
||||||
|
|
||||||
|
const actionTestCreature = {
|
||||||
|
_id: creatureId,
|
||||||
|
props: [
|
||||||
|
// Action with triggers
|
||||||
|
{
|
||||||
|
_id: actionWithTriggerId,
|
||||||
|
type: 'action',
|
||||||
|
tags: ['trigger tag'],
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
type: 'note',
|
||||||
|
name: 'Action Child'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
_id: triggerBeforeActionId,
|
||||||
|
type: 'trigger',
|
||||||
|
targetTags: ['trigger tag'],
|
||||||
|
name: 'Before Action Trigger',
|
||||||
|
event: 'doActionProperty',
|
||||||
|
actionPropertyType: 'action',
|
||||||
|
timing: 'before',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
_id: triggerAfterActionId,
|
||||||
|
type: 'trigger',
|
||||||
|
targetTags: ['trigger tag'],
|
||||||
|
name: 'After Action Trigger',
|
||||||
|
event: 'doActionProperty',
|
||||||
|
actionPropertyType: 'action',
|
||||||
|
timing: 'after',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
_id: triggerAfterActionChildrenId,
|
||||||
|
type: 'trigger',
|
||||||
|
targetTags: ['trigger tag'],
|
||||||
|
name: 'After Action Children Trigger',
|
||||||
|
event: 'doActionProperty',
|
||||||
|
actionPropertyType: 'action',
|
||||||
|
timing: 'afterChildren',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionTargetCreature = {
|
||||||
|
_id: targetCreatureId,
|
||||||
|
props: [
|
||||||
|
{
|
||||||
|
type: 'attribute',
|
||||||
|
attributeType: 'stat',
|
||||||
|
variableName: 'armor',
|
||||||
|
baseValue: { calculation: '10' },
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
const actionTargetCreature2 = {
|
||||||
|
_id: targetCreature2Id,
|
||||||
|
props: [
|
||||||
|
{
|
||||||
|
type: 'attribute',
|
||||||
|
attributeType: 'stat',
|
||||||
|
variableName: 'armor',
|
||||||
|
baseValue: { calculation: '10' },
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Triggers', function () {
|
||||||
|
// Increase timeout
|
||||||
|
this.timeout(8000);
|
||||||
|
|
||||||
|
before(async function () {
|
||||||
|
await removeAllCreaturesAndProps();
|
||||||
|
await createTestCreature(actionTestCreature);
|
||||||
|
await createTestCreature(actionTargetCreature);
|
||||||
|
await createTestCreature(actionTargetCreature2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should run triggers on actions', async function () {
|
||||||
|
const actionProp = CreatureProperties.findOne(actionWithTriggerId);
|
||||||
|
assert.deepEqual(actionProp.triggerIds, {
|
||||||
|
before: [triggerBeforeActionId],
|
||||||
|
after: [triggerAfterActionId],
|
||||||
|
afterChildren: [triggerAfterActionChildrenId],
|
||||||
|
}, 'Prop\'s triggerIds should be set');
|
||||||
|
const action = await runActionById(actionWithTriggerId);
|
||||||
|
assert.exists(action);
|
||||||
|
assert.deepEqual(allLogContent(action), [
|
||||||
|
{
|
||||||
|
name: 'Before Action Trigger',
|
||||||
|
}, {
|
||||||
|
name: 'Action',
|
||||||
|
}, {
|
||||||
|
name: 'After Action Trigger',
|
||||||
|
}, {
|
||||||
|
name: 'Action Child',
|
||||||
|
}, {
|
||||||
|
name: 'After Action Children Trigger',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import { EngineAction } from '/imports/api/engine/action/EngineActions';
|
||||||
|
import { applyDefaultAfterPropTasks } from '/imports/api/engine/action/functions/applyTaskGroups';
|
||||||
|
import { PropTask } from '/imports/api/engine/action/tasks/Task';
|
||||||
|
import getPropertyTitle from '/imports/api/utility/getPropertyTitle';
|
||||||
|
|
||||||
|
|
||||||
|
export default async function applyTriggerProperty(
|
||||||
|
task: PropTask, action: EngineAction, result, userInput
|
||||||
|
): Promise<void> {
|
||||||
|
const prop = task.prop;
|
||||||
|
result.appendLog({
|
||||||
|
name: getPropertyTitle(prop),
|
||||||
|
...prop.silent && { silenced: true },
|
||||||
|
})
|
||||||
|
return applyDefaultAfterPropTasks(action, prop, task.targetIds, userInput);
|
||||||
|
}
|
||||||
@@ -1,3 +1,8 @@
|
|||||||
|
import { EngineAction } from '/imports/api/engine/action/EngineActions';
|
||||||
|
import InputProvider from '/imports/api/engine/action/functions/userInput/InputProvider';
|
||||||
|
import { PropTask } from '/imports/api/engine/action/tasks/Task';
|
||||||
|
import TaskResult from '/imports/api/engine/action/tasks/TaskResult';
|
||||||
|
|
||||||
import action from './applyActionProperty';
|
import action from './applyActionProperty';
|
||||||
import adjustment from './applyAdjustmentProperty';
|
import adjustment from './applyAdjustmentProperty';
|
||||||
import branch from './applyBranchProperty';
|
import branch from './applyBranchProperty';
|
||||||
@@ -9,8 +14,11 @@ import note from './applyNoteProperty';
|
|||||||
import roll from './applyRollProperty';
|
import roll from './applyRollProperty';
|
||||||
import savingThrow from './applySavingThrowProperty';
|
import savingThrow from './applySavingThrowProperty';
|
||||||
import toggle from './applyToggleProperty';
|
import toggle from './applyToggleProperty';
|
||||||
|
import trigger from './applyTriggerProperty';
|
||||||
|
|
||||||
export default {
|
const applyPropertyByType: {
|
||||||
|
[key: string]: (task: PropTask, action: EngineAction, result: TaskResult, input: InputProvider) => Promise<void>
|
||||||
|
} = {
|
||||||
action,
|
action,
|
||||||
adjustment,
|
adjustment,
|
||||||
branch,
|
branch,
|
||||||
@@ -23,4 +31,7 @@ export default {
|
|||||||
savingThrow,
|
savingThrow,
|
||||||
propertySlot: folder,
|
propertySlot: folder,
|
||||||
toggle,
|
toggle,
|
||||||
|
trigger,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default applyPropertyByType;
|
||||||
@@ -54,9 +54,9 @@ type TestCreature = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of 100 random Ids
|
* get a list of random Ids
|
||||||
*/
|
*/
|
||||||
export const randomIds = new Array(100).fill(undefined).map(() => Random.id());
|
export const getRandomIds = (count) => new Array(count).fill(undefined).map(() => Random.id());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Engine Action and applies the specified creature property
|
* Creates a new Engine Action and applies the specified creature property
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ type Task = PropTask | DamagePropTask | ItemAsAmmoTask | CheckTask | ResetTask;
|
|||||||
export default Task;
|
export default Task;
|
||||||
|
|
||||||
type BaseTask = {
|
type BaseTask = {
|
||||||
prop: { [key: string]: any };
|
prop: { type: string, [key: string]: any };
|
||||||
targetIds: string[];
|
targetIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export default function writeAlteredProperties(computation) {
|
|||||||
'left',
|
'left',
|
||||||
'right',
|
'right',
|
||||||
'parentId',
|
'parentId',
|
||||||
|
'triggerIds',
|
||||||
...schema.objectKeys(),
|
...schema.objectKeys(),
|
||||||
];
|
];
|
||||||
op = addChangedKeysToOp(op, keys, original, changed);
|
op = addChangedKeysToOp(op, keys, original, changed);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ const ComputedOnlyTriggerSchema = createPropertySchema({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const ComputedTriggerSchema = new SimpleSchema()
|
const ComputedTriggerSchema = new SimpleSchema({})
|
||||||
.extend(TriggerSchema)
|
.extend(TriggerSchema)
|
||||||
.extend(ComputedOnlyTriggerSchema);
|
.extend(ComputedOnlyTriggerSchema);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user