Package org.terasology.logic.behavior.asset

Examples of org.terasology.logic.behavior.asset.BehaviorTreeLoader$BehaviorTreeGson


            savePath = PathManager.getInstance().getHomeModPath().resolve(BEHAVIORS.toString()).resolve("assets").resolve("behaviors");
        } else {
            Path overridesPath = PathManager.getInstance().getHomeModPath().resolve(BEHAVIORS.toString()).resolve("overrides");
            savePath = overridesPath.resolve(uri.getModuleName().toString()).resolve("behaviors");
        }
        BehaviorTreeLoader loader = new BehaviorTreeLoader();
        try {
            Files.createDirectories(savePath);
            Path file = savePath.resolve(uri.getAssetName() + ".behavior");
            try (FileOutputStream fos = new FileOutputStream(file.toFile())) {
                loader.save(fos, tree.getData());
            }
        } catch (IOException e) {
            throw new RuntimeException("Cannot save asset " + uri + " to " + savePath, e);
        }
    }
View Full Code Here


    public BehaviorTree getTree() {
        return tree;
    }

    public String save() {
        BehaviorTreeLoader loader = new BehaviorTreeLoader();
        ByteArrayOutputStream baos = new ByteArrayOutputStream(10000);
        try {
            loader.save(baos, tree.getData());
            return baos.toString(Charsets.UTF_8.name());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

     * This is useful when in interaction listener, especially.
     */
    public void copyNode(RenderableNode node) {
        BehaviorTreeData data = new BehaviorTreeData();
        data.setRoot(node.getNode());
        BehaviorTreeLoader loader = new BehaviorTreeLoader();
        ByteArrayOutputStream os = new ByteArrayOutputStream(10000);

        try {
            loader.save(os, data);
            BehaviorTreeData copy = loader.load(null, new ByteArrayInputStream(os.toByteArray()), null, Collections.<URL>emptyList());
            Port.OutputPort parent = node.getInputPort().getTargetPort();
            copy.createRenderable();
            RenderableNode copyRenderable = copy.getRenderableNode(copy.getRoot());
            addNode(copyRenderable);
            RenderableNode nodeToLayout;
View Full Code Here

    public void testSaveLoad() throws IOException {
        AssetManager assetManager = mock(AssetManager.class);
        CoreRegistry.put(AssetManager.class, assetManager);
        BehaviorNodeFactory nodeFactory = mock(BehaviorNodeFactory.class);
        CoreRegistry.put(BehaviorNodeFactory.class, nodeFactory);
        BehaviorTreeLoader loader = new BehaviorTreeLoader();
        BehaviorTreeData data = buildSample();

        OutputStream os = new ByteArrayOutputStream(10000);
        loader.save(os, data);
        String jsonExpected = os.toString();
        data = loader.load(null, new ByteArrayInputStream(jsonExpected.getBytes()), null, null);
        os = new ByteArrayOutputStream(10000);
        loader = new BehaviorTreeLoader();
        loader.save(os, data);
        String jsonActual = os.toString();
        Assert.assertEquals(jsonActual, jsonExpected);
    }
View Full Code Here

TOP

Related Classes of org.terasology.logic.behavior.asset.BehaviorTreeLoader$BehaviorTreeGson

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.