use of org.terasology.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);
}
}
use of org.terasology.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);
}
}
Aggregations