Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/BehaviorTreeImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Sequence from './Sequence'
import Task from './Task'
import AlwaysFailDecorator from './decorators/AlwaysFailDecorator'
import AlwaysSucceedDecorator from './decorators/AlwaysSucceedDecorator'
import AlwaysRunningDecorator from './decorators/AlwaysRunningDecorator'
import CooldownDecorator from './decorators/CooldownDecorator'
import InvertDecorator from './decorators/InvertDecorator'
import LoopDecorator from './decorators/LoopDecorator'
Expand All @@ -20,6 +21,7 @@ export default class BehaviorTreeImporter {
invert: InvertDecorator,
fail: AlwaysFailDecorator,
succeed: AlwaysSucceedDecorator,
running: AlwaysRunningDecorator,
cooldown: CooldownDecorator,
loop: LoopDecorator
}
Expand Down
12 changes: 12 additions & 0 deletions src/decorators/AlwaysRunningDecorator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RUNNING, SUCCESS } from '../constants'
import Decorator from '../Decorator'

export default class AlwaysRunningDecorator extends Decorator {
nodeType = 'AlwaysRunningDecorator'

decorate (run) {
const result = run()
if ([RUNNING, SUCCESS].indexOf(result) !== -1) return RUNNING
return result
}
}
22 changes: 22 additions & 0 deletions src/decorators/AlwaysRunningDecorator.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-env jest */
import { RUNNING, SUCCESS, FAILURE } from '../constants'
import AlwaysRunningDecorator from './AlwaysRunningDecorator'
import Task from '../Task'

describe('AlwaysRunningDecorator', () => {
const task = new Task({
run (blackboard) {
return blackboard.result
}
})
const decoratedTask = new AlwaysRunningDecorator({ node: task })

it('changes SUCCESS to RUNNING', () => {
expect(decoratedTask.run({ result: SUCCESS })).toEqual(RUNNING)
expect(decoratedTask.run({ result: RUNNING })).toEqual(RUNNING)
})

it('fails on FAILURE', () => {
expect(decoratedTask.run({ result: FAILURE })).toEqual(FAILURE)
})
})
1 change: 1 addition & 0 deletions src/decorators/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export AlwaysFailDecorator from './AlwaysFailDecorator'
export AlwaysRunningDecorator from './AlwaysRunningDecorator'
export AlwaysSucceedDecorator from './AlwaysSucceedDecorator'
export CooldownDecorator from './CooldownDecorator'
export InvertDecorator from './InvertDecorator'
Expand Down