Search in sources :

Example 6 with BehaviorTreeBuilder

use of org.terasology.logic.behavior.core.BehaviorTreeBuilder in project Terasology by MovingBlocks.

the class BehaviorEditor method copyNode.

public void copyNode(RenderableNode node) {
    BehaviorTreeBuilder treeBuilder = CoreRegistry.get(BehaviorTreeBuilder.class);
    String json = treeBuilder.toJson(node.getNode());
    BehaviorNode nodeCopy = treeBuilder.fromJson(json);
    List<RenderableNode> renderables = createRenderables(nodeCopy);
    if (renderables.size() > 0) {
        newNode = renderables.get(0);
        Vector2f oldPos = newNode.getPosition();
        layout(newNode);
        oldPos.sub(newNode.getPosition());
        newNode.move(oldPos);
    }
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) Vector2f(org.terasology.math.geom.Vector2f) BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode)

Example 7 with BehaviorTreeBuilder

use of org.terasology.logic.behavior.core.BehaviorTreeBuilder in project Terasology by MovingBlocks.

the class Example method main.

public static void main(String[] args) {
    BehaviorTreeBuilder treeBuilder = new BehaviorTreeBuilder();
    BehaviorNode node = treeBuilder.fromJson("{ sequence:[ success, success, failure ] }");
    logger.info("{}", new DefaultBehaviorTreeRunner(node, null).step());
    treeBuilder.registerAction("print", Print.class);
    node = treeBuilder.fromJson("{ sequence:[ success, { print:{msg:world} } ] }");
    logger.info("{}", new DefaultBehaviorTreeRunner(node, null).step());
    treeBuilder.registerAction("delay", Delay.class);
    Actor actor = new Actor(null);
    actor.setDelta(0.1f);
    node = treeBuilder.fromJson("{ sequence:[ success, { delay:{duration:1}}, { print:{msg:Hello} }, { delay:{duration:1}}, { print:{msg:World} } ] }");
    DefaultBehaviorTreeRunner tree = new DefaultBehaviorTreeRunner(node, actor);
    for (int i = 0; i < 100; i++) {
        tree.step();
    }
    treeBuilder.registerDecorator("repeat", Repeat.class);
    actor = new Actor(null);
    actor.setDelta(0.1f);
    node = treeBuilder.fromJson("{ sequence:[ " + "{repeat :{ count:5, child:{print:{msg:x}}}}, success, { delay:{duration:1}}, { print:{msg:Hello} }, { delay:{duration:1}}, { print:{msg:World} } " + "] }");
    tree = new DefaultBehaviorTreeRunner(node, actor);
    for (int i = 0; i < 100; i++) {
        tree.step();
    }
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) Actor(org.terasology.logic.behavior.core.Actor) BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode) Print(org.terasology.logic.behavior.actions.Print)

Aggregations

BehaviorTreeBuilder (org.terasology.logic.behavior.core.BehaviorTreeBuilder)7 BehaviorNode (org.terasology.logic.behavior.core.BehaviorNode)4 Before (org.junit.Before)2 GsonBuilder (com.google.gson.GsonBuilder)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Print (org.terasology.logic.behavior.actions.Print)1 Actor (org.terasology.logic.behavior.core.Actor)1 Vector2f (org.terasology.math.geom.Vector2f)1