Search in sources :

Example 6 with BehaviorNode

use of org.terasology.engine.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);
    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();
    }
    assertEquals(expectedOutput, Print.output.toString());
}
Also used : Actor(org.terasology.engine.logic.behavior.core.Actor) BehaviorNode(org.terasology.engine.logic.behavior.core.BehaviorNode) BehaviorTreeRunner(org.terasology.engine.logic.behavior.core.BehaviorTreeRunner) Print(org.terasology.engine.logic.behavior.actions.Print)

Example 7 with BehaviorNode

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

the class CountCallsTest method init.

@BeforeEach
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.engine.logic.behavior.core.BehaviorTreeBuilder) GsonBuilder(com.google.gson.GsonBuilder) BehaviorNode(org.terasology.engine.logic.behavior.core.BehaviorNode) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with BehaviorNode

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

the class BehaviorEditorScreen method onNodeSelected.

private void onNodeSelected(RenderableNode value, PropertyProvider provider) {
    selectedNode = value;
    properties.clear();
    if (value != null) {
        BehaviorNode underlyingNode = value.getNode();
        if (underlyingNode instanceof ActionNode) {
            this.properties.addProperties("Behavior Node", provider.createProperties(((ActionNode) underlyingNode).getAction()));
        }
        properties.addProperties("Behavior Node", provider.createProperties(value.getNode()));
    }
}
Also used : ActionNode(org.terasology.engine.logic.behavior.core.ActionNode) BehaviorNode(org.terasology.engine.logic.behavior.core.BehaviorNode)

Example 9 with BehaviorNode

use of org.terasology.engine.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.engine.logic.behavior.core.BehaviorNode)

Aggregations

BehaviorNode (org.terasology.engine.logic.behavior.core.BehaviorNode)9 BehaviorTreeBuilder (org.terasology.engine.logic.behavior.core.BehaviorTreeBuilder)4 Print (org.terasology.engine.logic.behavior.actions.Print)2 Actor (org.terasology.engine.logic.behavior.core.Actor)2 GsonBuilder (com.google.gson.GsonBuilder)1 Vector2f (org.joml.Vector2f)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ActionNode (org.terasology.engine.logic.behavior.core.ActionNode)1 BehaviorState (org.terasology.engine.logic.behavior.core.BehaviorState)1 BehaviorTreeRunner (org.terasology.engine.logic.behavior.core.BehaviorTreeRunner)1