Search in sources :

Example 1 with BehaviorTreeBuilder

use of org.terasology.logic.behavior.core.BehaviorTreeBuilder 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 2 with BehaviorTreeBuilder

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

the class CounterTest method setup.

@Before
public void setup() {
    treeBuilder = new BehaviorTreeBuilder();
    treeBuilder.registerAction("print", Print.class);
    treeBuilder.registerDecorator("counter", CounterAction.class);
    treeBuilder.registerDecorator("timeout", TimeoutAction.class);
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) Before(org.junit.Before)

Example 3 with BehaviorTreeBuilder

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

the class BehaviorTreeFormat method load.

@Override
public BehaviorTreeData load(ResourceUrn resourceUrn, List<AssetDataFile> list) throws IOException {
    BehaviorTreeBuilder builder = CoreRegistry.get(BehaviorTreeBuilder.class);
    if (builder == null) {
        builder = new BehaviorTreeBuilder();
        CoreRegistry.put(BehaviorTreeBuilder.class, builder);
    }
    try (InputStream stream = list.get(0).openStream()) {
        return load(stream);
    }
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) InputStream(java.io.InputStream)

Example 4 with BehaviorTreeBuilder

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

the class BehaviorTreeFormat method load.

public BehaviorTreeData load(InputStream stream) {
    BehaviorTreeBuilder builder = CoreRegistry.get(BehaviorTreeBuilder.class);
    if (builder == null) {
        builder = new BehaviorTreeBuilder();
        CoreRegistry.put(BehaviorTreeBuilder.class, builder);
    }
    BehaviorNode node = builder.fromJson(stream);
    BehaviorTreeData data = new BehaviorTreeData();
    data.setRoot(node);
    return data;
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) BehaviorNode(org.terasology.logic.behavior.core.BehaviorNode)

Example 5 with BehaviorTreeBuilder

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

the class BehaviorTreeFormat method save.

public void save(OutputStream stream, BehaviorTreeData data) throws IOException {
    BehaviorTreeBuilder builder = CoreRegistry.get(BehaviorTreeBuilder.class);
    OutputStreamWriter writer = new OutputStreamWriter(stream, Charsets.UTF_8);
    writer.write(builder.toJson(data.getRoot()));
    writer.close();
}
Also used : BehaviorTreeBuilder(org.terasology.logic.behavior.core.BehaviorTreeBuilder) OutputStreamWriter(java.io.OutputStreamWriter)

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