Search in sources :

Example 1 with BehaviorNode

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;
}
Also used : BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode)

Example 2 with BehaviorNode

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));
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) GsonBuilder(com.google.gson.GsonBuilder) BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode) Before(org.junit.Before)

Example 3 with BehaviorNode

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);
}
Also used : BehaviorState(org.terasology.logic.behavior.core.BehaviorState) BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode)

Example 4 with BehaviorNode

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());
}
Also used : Actor(org.terasology.logic.behavior.core.Actor) BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode) BehaviorTreeRunner(org.terasology.logic.behavior.core.BehaviorTreeRunner) Print(org.terasology.logic.behavior.actions.Print)

Example 5 with BehaviorNode

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);
        }
    }
}
Also used : BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode)

Aggregations

BehaviorNode (org.terasology.logic.behavior.core.BehaviorNode)9 BehaviorTreeBuilder (org.terasology.logic.behavior.core.BehaviorTreeBuilder)4 Print (org.terasology.logic.behavior.actions.Print)2 Actor (org.terasology.logic.behavior.core.Actor)2 GsonBuilder (com.google.gson.GsonBuilder)1 Before (org.junit.Before)1 ActionNode (org.terasology.logic.behavior.core.ActionNode)1 BehaviorState (org.terasology.logic.behavior.core.BehaviorState)1 BehaviorTreeRunner (org.terasology.logic.behavior.core.BehaviorTreeRunner)1 Vector2f (org.terasology.math.geom.Vector2f)1