Skip to content

Commit

Permalink
Merge pull request #89 from nikkorn/#88
Browse files Browse the repository at this point in the history
Added All Node
  • Loading branch information
nikkorn authored Apr 5, 2024
2 parents be57a99 + 22d0f75 commit 86858f2
Show file tree
Hide file tree
Showing 17 changed files with 795 additions and 16 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,40 @@ root {
}
```

### All
This composite node will update each child node concurrently. It will stay in the `RUNNING` state until all of its children have moved to either the `SUCCEEDED` or `FAILED` state, after which this node will move to the `SUCCEEDED` state if any of its children have moved to the `SUCCEEDED` state, otherwise it will move to the `FAILED` state.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=all)

*MDSL*
```
root {
all {
action [Reload]
action [MoveToCover]
}
}
```

*JSON*
```json
{
"type": "root",
"child": {
"type": "all",
"children": [
{
"type": "action",
"call": "Reload"
},
{
"type": "action",
"call": "MoveToCover"
}
]
}
}
```

### Lotto
This composite node will select a single child at random to run as the active running node. The state of this node will reflect the state of the active child.
[Example](https://nikkorn.github.io/mistreevous-visualiser/index.html?example=lotto)
Expand Down
11 changes: 10 additions & 1 deletion dist/BehaviourTreeDefinition.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ export interface RaceNodeDefinition extends CompositeNodeDefinition {
*/
type: "race";
}
/**
* An all node.
*/
export interface AllNodeDefinition extends CompositeNodeDefinition {
/**
* The node type.
*/
type: "all";
}
/**
* A root node.
*/
Expand Down Expand Up @@ -236,7 +245,7 @@ export interface FailNodeDefinition extends DecoratorNodeDefinition {
/**
* A type defining any node definition.
*/
export type AnyNodeDefinition = BranchNodeDefinition | ActionNodeDefinition | ConditionNodeDefinition | WaitNodeDefinition | SequenceNodeDefinition | SelectorNodeDefinition | LottoNodeDefinition | ParallelNodeDefinition | RaceNodeDefinition | RootNodeDefinition | RepeatNodeDefinition | RetryNodeDefinition | FlipNodeDefinition | SucceedNodeDefinition | FailNodeDefinition;
export type AnyNodeDefinition = BranchNodeDefinition | ActionNodeDefinition | ConditionNodeDefinition | WaitNodeDefinition | SequenceNodeDefinition | SelectorNodeDefinition | LottoNodeDefinition | ParallelNodeDefinition | RaceNodeDefinition | AllNodeDefinition | RootNodeDefinition | RepeatNodeDefinition | RetryNodeDefinition | FlipNodeDefinition | SucceedNodeDefinition | FailNodeDefinition;
/**
* A type defining any node type that can be a child of composite parent node.
*/
Expand Down
53 changes: 52 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/index.js.map

Large diffs are not rendered by default.

53 changes: 52 additions & 1 deletion dist/mistreevous.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/mistreevous.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mistreevous.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/mistreevous.min.js.map

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions dist/nodes/composite/All.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Composite from "./Composite";
import Node from "../Node";
import { Agent } from "../../Agent";
import Attribute from "../../attributes/Attribute";
import { BehaviourTreeOptions } from "../../BehaviourTreeOptions";
/**
* An ALL node.
* The child nodes are executed concurrently until all child nodes move to a completed state.
*/
export default class All extends Composite {
/**
* @param attributes The node attributes.
* @param options The behaviour tree options.
* @param children The child nodes.
*/
constructor(attributes: Attribute[], options: BehaviourTreeOptions, children: Node[]);
/**
* Called when the node is being updated.
* @param agent The agent.
*/
protected onUpdate(agent: Agent): void;
/**
* Gets the name of the node.
*/
getName: () => string;
}
9 changes: 9 additions & 0 deletions src/BehaviourTreeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Composite from "./nodes/composite/Composite";
import Decorator from "./nodes/decorator/Decorator";
import Parallel from "./nodes/composite/Parallel";
import Race from "./nodes/composite/Race";
import All from "./nodes/composite/All";
import Selector from "./nodes/composite/Selector";
import Sequence from "./nodes/composite/Sequence";
import Lotto from "./nodes/composite/Lotto";
Expand Down Expand Up @@ -42,6 +43,7 @@ type AnyNode =
| Lotto
| Parallel
| Race
| All
| Repeat
| Retry
| Flip
Expand Down Expand Up @@ -185,6 +187,13 @@ function nodeFactory(
definition.children.map((child) => nodeFactory(child, rootNodeDefinitionMap, options))
);

case "all":
return new All(
attributes,
options,
definition.children.map((child) => nodeFactory(child, rootNodeDefinitionMap, options))
);

case "lotto":
return new Lotto(
attributes,
Expand Down
11 changes: 11 additions & 0 deletions src/BehaviourTreeDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ export interface RaceNodeDefinition extends CompositeNodeDefinition {
type: "race";
}

/**
* An all node.
*/
export interface AllNodeDefinition extends CompositeNodeDefinition {
/**
* The node type.
*/
type: "all";
}

/**
* A root node.
*/
Expand Down Expand Up @@ -265,6 +275,7 @@ export type AnyNodeDefinition =
| LottoNodeDefinition
| ParallelNodeDefinition
| RaceNodeDefinition
| AllNodeDefinition
| RootNodeDefinition
| RepeatNodeDefinition
| RetryNodeDefinition
Expand Down
2 changes: 1 addition & 1 deletion src/BehaviourTreeDefinitionUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function isDecoratorNode(node: NodeDefinition): node is DecoratorNodeDefi
* @returns A value of true if the specified node satisfies the CompositeNodeDefinition type.
*/
export function isCompositeNode(node: NodeDefinition): node is CompositeNodeDefinition {
return ["sequence", "selector", "lotto", "parallel", "race"].includes(node.type);
return ["sequence", "selector", "lotto", "parallel", "race", "all"].includes(node.type);
}

/**
Expand Down
Loading

0 comments on commit 86858f2

Please sign in to comment.