feat: tool setup

This commit is contained in:
cha0s 2019-06-12 22:22:51 -05:00
parent 0221a525b4
commit 2164a43bfd

View File

@ -12,12 +12,16 @@ export class Tool extends decorate(Trait) {
static defaultParams() {
return {
actions: {
type: 'actions',
traversals: [],
},
condition: {
type: 'condition',
operator: 'or',
operands: [],
},
actions: {
setup: {
type: 'actions',
traversals: [],
},
@ -46,8 +50,9 @@ export class Tool extends decorate(Trait) {
throw new Error("Tool::params.target.width must be odd!");
}
this.targets = [];
this.toolCondition = behaviorItemFromJSON(this.params.condition);
this.toolActions = behaviorItemFromJSON(this.params.actions);
this.toolCondition = behaviorItemFromJSON(this.params.condition);
this.toolSetup = behaviorItemFromJSON(this.params.setup);
}
calculateTargetStart() {
@ -239,6 +244,8 @@ export class Tool extends decorate(Trait) {
for (let i = 0; i < this.targets.length; ++i) {
const target = this.targets[i];
const context = this.createTargetContext(target);
// Initial setup.
this.toolSetup.tick(context, 0);
// Each target checks condition.
if (!this.toolCondition.get(context)) {
continue;