Search in sources :

Example 1 with BehaviorTree

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

the class TerasologyEngine method initAssets.

private void initAssets() {
    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
    assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
    assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
    AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
    assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
    assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
    assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
    assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
    assetTypeManager.createAssetType(ByteBufferAsset.class, ByteBufferAsset::new, "mesh");
    for (EngineSubsystem subsystem : allSubsystems) {
        subsystem.registerCoreAssetTypes(assetTypeManager);
    }
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) BlockShapeImpl(org.terasology.engine.world.block.shapes.BlockShapeImpl) UIElement(org.terasology.nui.asset.UIElement) UISkinAsset(org.terasology.nui.skin.UISkinAsset) BlockFamilyDefinitionFormat(org.terasology.engine.world.block.loader.BlockFamilyDefinitionFormat) BlockTile(org.terasology.engine.world.block.tiles.BlockTile) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) ByteBufferAsset(org.terasology.engine.rendering.gltf.ByteBufferAsset) BlockSounds(org.terasology.engine.world.block.sounds.BlockSounds) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) EngineSubsystem(org.terasology.engine.core.subsystem.EngineSubsystem) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition)

Example 2 with BehaviorTree

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

the class CollectiveBehaviorSystem method initialise.

@Override
public void initialise() {
    List<ResourceUrn> uris = Lists.newArrayList();
    uris.addAll(new ArrayList<>(assetManager.getAvailableAssets(StaticSound.class)));
    for (ResourceUrn uri : assetManager.getAvailableAssets(BehaviorTree.class)) {
        Optional<BehaviorTree> asset = assetManager.getAsset(uri, BehaviorTree.class);
        if (asset.isPresent()) {
            trees.add(asset.get());
        } else {
            logger.warn("Failed to load behavior tree asset {}.", uri);
        }
    }
}
Also used : ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree)

Example 3 with BehaviorTree

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

the class CollectiveBehaviorSystem method addEntity.

private void addEntity(EntityRef entityRef, CollectiveBehaviorComponent collectiveInterpreter) {
    if (collectiveInterpreter.collectiveInterpreter == null) {
        Set<Actor> newActors = new HashSet<>();
        newActors.add(new Actor(entityRef));
        collectiveInterpreter.collectiveInterpreter = new CollectiveInterpreter(newActors);
        BehaviorTree tree = collectiveInterpreter.tree;
        if (tree != null) {
            collectiveInterpreter.collectiveInterpreter.setTree(tree);
        }
    }
}
Also used : Actor(org.terasology.engine.logic.behavior.core.Actor) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) HashSet(java.util.HashSet)

Example 4 with BehaviorTree

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

the class BehaviorEditorScreen method initialise.

@Override
public void initialise() {
    entityProperties = find("entity_properties", PropertyLayout.class);
    behaviorEditor = find("tree", BehaviorEditor.class);
    properties = find("properties", PropertyLayout.class);
    selectTree = find("select_tree", UIDropdown.class);
    selectEntity = find("select_entity", UIDropdown.class);
    palette = find("palette", UIList.class);
    behaviorEditor.initialize(context);
    behaviorEditor.bindSelection(new Binding<RenderableNode>() {

        private PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), providerFactory);

        @Override
        public RenderableNode get() {
            return selectedNode;
        }

        @Override
        public void set(RenderableNode value) {
            onNodeSelected(value, provider);
        }
    });
    Binding<List<BehaviorTree>> treeBinding = new ReadOnlyBinding<List<BehaviorTree>>() {

        @Override
        public List<BehaviorTree> get() {
            return behaviorSystem.getTrees();
        }
    };
    selectTree.bindOptions(treeBinding);
    providerFactory.register("behaviorTrees", treeBinding);
    selectTree.bindSelection(new Binding<BehaviorTree>() {

        @Override
        public BehaviorTree get() {
            return behaviorEditor.getTree();
        }

        @Override
        public void set(BehaviorTree value) {
            onTreeSelected(value);
        }
    });
    selectEntity.bindOptions(new ReadOnlyBinding<List<Interpreter>>() {

        @Override
        public List<Interpreter> get() {
            return behaviorSystem.getInterpreters();
        }
    });
    selectEntity.bindSelection(new Binding<Interpreter>() {

        private PropertyProvider provider = new PropertyProvider(context.get(ReflectFactory.class), providerFactory);

        @Override
        public Interpreter get() {
            return selectedInterpreter;
        }

        @Override
        public void set(Interpreter value) {
            onEntitySelected(value, provider);
        }
    });
    palette.bindSelection(new Binding<BehaviorNodeComponent>() {

        @Override
        public BehaviorNodeComponent get() {
            return null;
        }

        @Override
        public void set(BehaviorNodeComponent value) {
            onPaletteSelected(value);
        }
    });
    palette.bindList(new ReadOnlyBinding<List<BehaviorNodeComponent>>() {

        @Override
        public List<BehaviorNodeComponent> get() {
            return paletteItems;
        }
    });
    palette.setItemRenderer(new ToStringTextRenderer<BehaviorNodeComponent>() {

        @Override
        public String getTooltip(BehaviorNodeComponent value) {
            return value.description;
        }
    });
    WidgetUtil.trySubscribe(this, "copy", button -> onCopyPressed());
    WidgetUtil.trySubscribe(this, "layout", button -> onLayoutPressed());
    WidgetUtil.trySubscribe(this, "new", button -> onNewPressed());
    WidgetUtil.trySubscribe(this, "assign", button -> onAssignPressed());
    WidgetUtil.trySubscribe(this, "remove", button -> onRemovePressed());
    WidgetUtil.trySubscribe(this, "debug_run", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.run();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_pause", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.pause();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_reset", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.reset();
        }
    });
    WidgetUtil.trySubscribe(this, "debug_step", button -> {
        if (selectedInterpreter != null) {
            selectedInterpreter.tick(0.1f);
        }
    });
    paletteItems = findPaletteItems();
}
Also used : Interpreter(org.terasology.engine.logic.behavior.Interpreter) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) UIList(org.terasology.nui.widgets.UIList) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) PropertyProvider(org.terasology.nui.properties.PropertyProvider) UIDropdown(org.terasology.nui.widgets.UIDropdown) List(java.util.List) UIList(org.terasology.nui.widgets.UIList)

Example 5 with BehaviorTree

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

the class UniverseSetupScreen method initAssets.

private void initAssets() {
    ModuleEnvironment environment = context.get(ModuleManager.class).getEnvironment();
    BlockFamilyLibrary library = new BlockFamilyLibrary(environment, context);
    // cast lambdas explicitly to avoid inconsistent compiler behavior wrt. type inference
    assetTypeManager.createAssetType(Prefab.class, PojoPrefab::new, "prefabs");
    assetTypeManager.createAssetType(BlockShape.class, BlockShapeImpl::new, "shapes");
    assetTypeManager.createAssetType(BlockSounds.class, BlockSounds::new, "blockSounds");
    assetTypeManager.createAssetType(BlockTile.class, BlockTile::new, "blockTiles");
    AssetType<BlockFamilyDefinition, BlockFamilyDefinitionData> blockFamilyDefinitionDataAssetType = assetTypeManager.createAssetType(BlockFamilyDefinition.class, BlockFamilyDefinition::new, "blocks");
    assetTypeManager.getAssetFileDataProducer(blockFamilyDefinitionDataAssetType).addAssetFormat(new BlockFamilyDefinitionFormat(assetTypeManager.getAssetManager()));
    assetTypeManager.createAssetType(UISkinAsset.class, UISkinAsset::new, "skins");
    assetTypeManager.createAssetType(BehaviorTree.class, BehaviorTree::new, "behaviors");
    assetTypeManager.createAssetType(UIElement.class, UIElement::new, "ui");
}
Also used : PojoPrefab(org.terasology.engine.entitySystem.prefab.internal.PojoPrefab) BlockShapeImpl(org.terasology.engine.world.block.shapes.BlockShapeImpl) UIElement(org.terasology.nui.asset.UIElement) UISkinAsset(org.terasology.nui.skin.UISkinAsset) BlockFamilyDefinitionFormat(org.terasology.engine.world.block.loader.BlockFamilyDefinitionFormat) BlockFamilyLibrary(org.terasology.engine.world.block.family.BlockFamilyLibrary) BlockTile(org.terasology.engine.world.block.tiles.BlockTile) ModuleManager(org.terasology.engine.core.module.ModuleManager) BehaviorTree(org.terasology.engine.logic.behavior.asset.BehaviorTree) BlockSounds(org.terasology.engine.world.block.sounds.BlockSounds) BlockFamilyDefinitionData(org.terasology.engine.world.block.loader.BlockFamilyDefinitionData) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) BlockFamilyDefinition(org.terasology.engine.world.block.loader.BlockFamilyDefinition)

Aggregations

BehaviorTree (org.terasology.engine.logic.behavior.asset.BehaviorTree)10 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)4 Name (org.terasology.gestalt.naming.Name)3 IOException (java.io.IOException)2 ModuleManager (org.terasology.engine.core.module.ModuleManager)2 PojoPrefab (org.terasology.engine.entitySystem.prefab.internal.PojoPrefab)2 BehaviorTreeData (org.terasology.engine.logic.behavior.asset.BehaviorTreeData)2 BlockFamilyDefinition (org.terasology.engine.world.block.loader.BlockFamilyDefinition)2 BlockFamilyDefinitionData (org.terasology.engine.world.block.loader.BlockFamilyDefinitionData)2 BlockFamilyDefinitionFormat (org.terasology.engine.world.block.loader.BlockFamilyDefinitionFormat)2 BlockShapeImpl (org.terasology.engine.world.block.shapes.BlockShapeImpl)2 BlockSounds (org.terasology.engine.world.block.sounds.BlockSounds)2 BlockTile (org.terasology.engine.world.block.tiles.BlockTile)2 AssetManager (org.terasology.gestalt.assets.management.AssetManager)2 UIElement (org.terasology.nui.asset.UIElement)2 UISkinAsset (org.terasology.nui.skin.UISkinAsset)2 GsonBuilder (com.google.gson.GsonBuilder)1 JsonReader (com.google.gson.stream.JsonReader)1 JsonWriter (com.google.gson.stream.JsonWriter)1 Files (java.nio.file.Files)1