use of org.terasology.logic.behavior.core.BehaviorNode in project Terasology by MovingBlocks.
the class BehaviorEditor method createNode.
public RenderableNode createNode(BehaviorNodeComponent data) {
if (tree == null) {
return null;
}
BehaviorNode node = behaviorNodeFactory.createNode(data);
newNode = createRenderableNode(node);
behaviorSystem.treeModified(tree);
return newNode;
}
use of org.terasology.logic.behavior.core.BehaviorNode in project Terasology by MovingBlocks.
the class CountCallsTest method init.
@Before
public void init() {
constructCalled.clear();
destructCalled.clear();
executeCalled.clear();
nextId2 = 1;
gsonBuilder = new GsonBuilder();
BehaviorTreeBuilder builder = new BehaviorTreeBuilder() {
@Override
public BehaviorNode createNode(BehaviorNode node) {
return new CountDelegate(node);
}
};
gsonBuilder.registerTypeAdapter(BehaviorNode.class, builder);
// gsonBuilder.registerTypeAdapter(Action.class, new InheritanceAdapter<Action>("delay", Delay.class));
}
use of org.terasology.logic.behavior.core.BehaviorNode in project Terasology by MovingBlocks.
the class CountCallsTest method assertBT.
public void assertBT(String tree, List<BehaviorState> result, List<Integer> executed, boolean step) {
BehaviorNode node = fromJson(tree);
node.construct(null);
List<BehaviorState> actualStates = Lists.newArrayList();
for (int i = 0; i < result.size(); i++) {
BehaviorState state = node.execute(null);
actualStates.add(state);
}
node.destruct(null);
Assert.assertEquals(result, actualStates);
Assert.assertEquals(executed, executeCalled);
}
use of org.terasology.logic.behavior.core.BehaviorNode in project Terasology by MovingBlocks.
the class CounterTest method assertRun.
private void assertRun(String tree, int executions, String expectedOutput) {
Print.output = new StringBuilder();
BehaviorNode node = treeBuilder.fromJson(tree);
String json = treeBuilder.toJson(node);
BehaviorNode n2 = treeBuilder.fromJson(json);
String json2 = treeBuilder.toJson(n2);
Assert.assertEquals(json, json2);
Actor actor = new Actor(null);
actor.setDelta(0.5f);
BehaviorTreeRunner runner = new DefaultBehaviorTreeRunner(node, actor);
for (int i = 0; i < executions; i++) {
runner.step();
}
Assert.assertEquals(expectedOutput, Print.output.toString());
}
use of org.terasology.logic.behavior.core.BehaviorNode in project Terasology by MovingBlocks.
the class LookupAction method construct.
@Override
public void construct(Actor actor) {
if (tree != null) {
BehaviorNode root = tree.getRoot().deepCopy();
if (root != null) {
actor.setValue(getId(), root);
root.construct(actor);
}
}
}
Aggregations