Search in sources :

Example 1 with BehaviorTreeFormat

use of org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat in project Terasology by MovingBlocks.

the class BehaviorSystem method save.

public void save(BehaviorTree tree) {
    Path savePath;
    ResourceUrn uri = tree.getUrn();
    if (BEHAVIORS.equals(uri.getModuleName())) {
        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");
    }
    BehaviorTreeFormat loader = new BehaviorTreeFormat();
    try {
        Files.createDirectories(savePath);
        Path file = savePath.resolve(uri.getResourceName() + ".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);
    }
}
Also used : Path(java.nio.file.Path) BehaviorTreeFormat(org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Example 2 with BehaviorTreeFormat

use of org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat in project Terasology by MovingBlocks.

the class BehaviorEditor method save.

public String save() {
    BehaviorTreeFormat loader = new BehaviorTreeFormat();
    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);
    }
}
Also used : BehaviorTreeFormat(org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with BehaviorTreeFormat

use of org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat in project Terasology by MovingBlocks.

the class CollectiveBehaviorSystem method save.

public void save(BehaviorTree tree) {
    Path savePath;
    ResourceUrn uri = tree.getUrn();
    if (BEHAVIORS.equals(uri.getModuleName())) {
        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");
    }
    BehaviorTreeFormat loader = new BehaviorTreeFormat();
    try {
        Files.createDirectories(savePath);
        Path file = savePath.resolve(uri.getResourceName() + ".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);
    }
}
Also used : Path(java.nio.file.Path) BehaviorTreeFormat(org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn)

Aggregations

IOException (java.io.IOException)3 BehaviorTreeFormat (org.terasology.engine.logic.behavior.asset.BehaviorTreeFormat)3 FileOutputStream (java.io.FileOutputStream)2 Path (java.nio.file.Path)2 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1