GithubHelp home page GithubHelp logo

pruttned / owl-bt Goto Github PK

View Code? Open in Web Editor NEW
170.0 16.0 28.0 2.75 MB

owl-bt is editor for Behavior trees. It has been inspired by Unreal engine behavior trees in a way, that it supports special node items like decorators and services. This makes trees smaller and much more readable.

JavaScript 88.45% HTML 4.54% SCSS 7.01%
game behavior tree artificial-intelligence ai behavior-tree

owl-bt's Introduction

owl-bt

owl-bt is editor for Behavior trees. It has been inspired by Unreal engine behavior trees in a way, that it supports special node items like decorators and services. This makes trees smaller and much more readable.

Why

owl-bt has been created because we needed a behavior tree editor for our game Tendril: Echo Received, where we are focusing on live npc behavior.

We have tried some of the existing solutions, but they haven't meet our requirements like:

  • focus on content and not on layout
  • open format - we did not want to be bound to a specific game engine. For instance, we have created some of our game prototypes in Unity and the game itself is developed in MonoGame. In this way, we were able to take behavior trees from prototypes and use them directly in the game itself.
  • ability to fully define item types
  • to have fun developing it ;)

Install

npm install owl-bt -g

Usage

  • help
owlbt -h
  • Create a new project
cd <project-dir>
owlbt i
  • Create a new tree (tree must be under an existing project)
owlbt c <tree-path>
  • Open an existing tree
owlbt o path

Configuration

owl-bt runs as a service on port 8955 by default. This can be changed in config file .owlbtrc, that must be created in the user`s home directory.

{
	"port" : 1234
}

Tree items

bt node

In owl-bt, there are three types of items:

  • Node - represents a single task that can be executed at once or in multiple ticks. Composite nodes may contain child nodes.
  • Decorator - node sub item, that guards access to its node and transforms node's return value.
    • It is possible to mark decorator as periodic - represents, that the decorator should be reevaluated each tick, if its node is on the execution path.
  • Service - node sub item, that executes a specific task at given times, if its node is on the execution path.

Features

  • Automatic layout - In order to focus only on content creation, there is no option for manually layout the tree. Tree is laid out automatically.
  • Keyboard control - Almost entire tree can be created and edited using just keyboard. owl-bt contains command palette as in Sumblime Text. It can be accessed through ctrl+shift+p

bt node

  • Hot project reload - each change to project file is instantly updated in running editor instance. Therefore it is easy to define or update node items without reloading tree, that is currently being edited.

bt node

  • Undo/redo - owl-bt supports undo/redo for all actions
  • Json format - trees and project are stored as simple json files, which makes it easy to integrate with more or less any game engine

Project file

Project file (owl-bt.json) defines all nodes and node item types that can be used in trees.

Node

  • name - (required) node type name
  • base - item to inherit from
  • isAbstract - whether to allow creating items of this type - mainly for inheritance purposes
  • icon - node icon (name of the icon from font-awesome without fa- prefix)
  • color - custom color (css syntax - e.g. '#bada55' or 'green')
  • description - node description. It may contain placeholders for properties {{PropertyName}}
  • isComposite - whether node may contain another child nodes
  • properties - list of node properties (see property definition)

Decorator

  • name - (required) decorator type name
  • base - item to inherit from
  • isAbstract - whether to allow creating items of this type - mainly for inheritance purposes
  • icon - decorator icon (name of the icon from font-awesome without fa- prefix)
  • color - custom color (css syntax - e.g. '#bada55' or 'green')
  • description - decorator description. It may contain placeholders for properties {{PropertyName}}
  • properties - list of decorator properties (see property definition)

Service

  • name - (required) service type name
  • base - item to inherit from
  • isAbstract - whether to allow creating items of this type - mainly for inheritance purposes
  • icon - service icon (name of the icon from font-awesome without fa- prefix)
  • color - custom color (css syntax - e.g. '#bada55' or 'green')
  • description - service description. It may contain placeholders for properties {{PropertyName}}
  • properties - list of service properties (see property definition)

Property

  • name - (required)
  • default - default value
  • type - type of the property
    • string
    • number
    • bool
    • enum
    • custom type defined in project file
  • values- (required for enum type) - list of possible enum values
  • min- (for number type) - min allowed value
  • max- (for number type) - max allowed value

Types

Enables to define custom property types

  • type - (required) base type for this custom type ['string' or 'number']
  • pattern - regular expression for validation purposes

Example:

{
  "types":{
    "myString" : {
      "type" : "string",
      "pattern" : "v[0-9]"
    }
  },
  "nodes": [
    {
      "name": "SetAlertLevel",
      "icon": "exclamation",
      "description": "Set alert level to \"{{Level}}\"",
      "isComposite": false,
      "properties": [
        {
          "name": "Level",
          "default": "None",
          "type": "enum",
          "values": [
            "None",
            "Investigate",
            "HighAlert",
            "Panic"
          ]
        }
      ]
    }
  ],
  "decorators": [
    {
      "name": "HasZoneReportedEnemy",
      "icon": "phone",
      "properties": [
        {
          "name": "MaxReportAge",
          "default": 1,
          "type": "number"
        }
      ]
    }
  ],
  "services": [
    {
      "name": "ReadPlayerPos",
      "icon": "pencil",
      "description": "Store player pos to \"{{BlackboardKey}}\"",
      "properties": [
        {
          "name": "BlackboardKey",
          "default": "Target",
          "type": "string"
        }
      ]
    }
  ]
}

Tree file

{
	"type": "Selector",
	"name": "rootNode",
	"childNodes": [
		{
			"type": "Sequence",
			"services": [
				{
					"type": "Sample service"
				}
			],
			"decorators": [
				{
					"type": "IsBlackboardValueSet",
					"properties": [
						{
							"name": "Field",
							"value": "myValue"
						}
					],
					"periodic": true
				}
			]
		}
	]
}

Inheritance

It is possible to derive a node item type from another type using base setting.

It is possible to use string or array of strings for base setting. In case of array, base item types are applied in a specified order. That means, that the later item type overrides item specified before it.

E.q. we may create a base node:

{
      "name": "MyBaseNode",
      "icon": "arrow-right",
      "color": "red",
      "isAbstract" : true,
      "properties": [
        {
          "name": "prop-from-base1",
          "type": "string"
        },
        {
          "name": "prop-from-base2",
          "type": "number"
        }
      ]
    },

And derived node:

{
      "name": "MyDerivedNode",
      "color": "blue",
      "base": "MyBaseNode",
      "properties": [
        {
          "name": "prop1",
          "type": "string"
        },
        {
          "name": "prop-from-base2",
          "default" : "abc",          
          "type": "string"
        }
      ]
    },

Resulting node after applying inheritance is going to look like:

{
      "name": "MyDerivedNode",
      "icon": "arrow-right",      
      "color": "blue",
      "base": "MyBaseNode",
      "properties": [
        {
          "name": "prop-from-base1",
          "type": "string"
        },
        {
          "name": "prop-from-base2",
          "default" : "abc",          
          "type": "string"
        },
        {
          "name": "prop1",
          "type": "string"
        }
      ]
    },

Plugins

owl-bt.js file in the same directory as project file owl-bt.json is considered plugin. Plugin js file exports object with plugin functions.

module.exports = {
	onTreeSave: ({ tree, path, project, projectPath }) => {
	},
	onTreeLoad: ({ tree, path, project, projectPath }) => {
	}
}
  • onTreeSave - executed before the tree json file is saved to disk. Only modifications of tree object are allowed.
    • tree - tree object (according to tree json file)
    • path - tree file path
    • project - project object (according to owl-bt.json file)
    • projectPath - project file path
    • return - when the return value is false or a string, then the save is prevented and error is returned to client
  • onTreeLoad - executed after loading tree json file from disk. Only modifications of tree object are allowed.
    • tree - tree object (according to tree json file)
    • path - tree file path
    • project - project object (according to owl-bt.json file)
    • projectPath - project file path

It is possible for example to create a custom tree file formats using onTreeSave and onTreeLoad. If we wanted to have project path stored in the tree file, we could create the following plugin:

module.exports = {
	onTreeSave: ({ tree, path, project, projectPath }) => {
		tree.projectPath = projectPath;
	}
}

Changelog

1.1.0

  • Add support for tree item type inheritance - see base and isAbstract properties in project definition
  • Add support to override tree item type color
  • Add support to remove items from MRU list
  • Add support to modify tree before save and after load through plugins
  • Prevent save of tree when current node item has validation errors in property editor
  • Add support for custom property types
  • Add item color to new item selection dialog
  • Add item palette side panel
  • Make side panels collapsible

1.2.0

  • Add support for multiple base types. Thanks to dauryg
  • Add save success notification message

1.3.0

  • Add support to prevent save of a tree in plugin
  • Add reloading of plugins
  • Prevent losing values of invalid properties in property editor form
  • Add highlighting of all tree items with invalid properties
  • Add save confirmation before saving a tree with invalid properties

2.0.0

  • Add option to change type of an existing node. (ctrl+shift+p->'core:Set Node Type' or rmb->'Set Node Type')
  • (breaking change): Fontawesome upgraded to 5.*
  • (chore): Convert from Grunt+Bower+Karma to Webpack+Jest

2.1.0

  • Add custom label to node items
  • Add comment to node items

owl-bt's People

Contributors

dauryg avatar dependabot[bot] avatar mok-sk avatar pruttned avatar rubenwardy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

owl-bt's Issues

enhacement: plugins

When I started playing around with the plugins, I realized how powerful they can be. They were a great addition to owl-bt.

At first, defining a plugin was a little confusing because of catching and because changes to plugin js files are not hot-loaded. Changes made to the plugin files didn't seem to affect existing tree files. Then I realized what's happening. Not that it's a bug; it's just that it could be confusing to a new user. You might want to mention it in the documentation:

  1. owl-bt will not remove existing fields in tree files. If a field is there when the tree file is loaded, it will be written when the file is saved. This confused me because I added a field via plugin, but then deleted the plugin code, but the field was still in the file whenever I saved it. I removed the field manually, restarted owl-bt, and then saved the file and the field was gone.
  2. For changes in owl-bt.js to take effect, owl-bt needs to be restarted. This, combined with 1, was making me think that the plugin wasn't working. Changes to other files are hot-loaded, so it caught me by surprise.

ENHANCEMENT REQUEST:

A) I'm guessing that if you didn't support hot-loading owl-bt.js was because of technical reasons. If this is possible, however, it would be a really nice to have.

B) There is an opportunity to make plugins also work as validators: make the return value of 'onTreeSave' and 'onTreeLoad' determine whether the file can be saved or loaded. Maybe something like this:

  • onTreeSave: If return value is true, file will be saved. If return value if false, file will not be saved, and there will be a generic error shown to the user that the file was not saved. If the return value is a string, then the file is not saved, and the error message shown to the user is the value of the string. This will allow plugins to be used as validator -- you can perform checks on the tree, according to your own logic, and if you find something funky, you'll get a message of what the validation error was. This would be really nice, because you can guarantee that the file saved is 100% valid, according to the user's particular requirements.

Latest updates?

This is, easily, the best BehaviorTree editor out on the internet that's not tied to a specific tool.
It would be really cool if you released whatever updates you have made since April 2017.

Many of us Indies have been fan of this tool for a while. Specially because we don't have the skill to create one like this. We're waiting your updates with excitement.

enhancement: function calls for nodes

Hello, I truely love this behavior tree editor! Thanks!
I find that it is not possible to make function calls for Action Nodes.
Like
var optionCheckPara:Parallel = new Parallel();
optionCheckPara.withPolicy(new PolicySequence());

Thanks in advance.

travis

integrate with travis

enhancement: add name tag for nodes

As the tree grows, it becomes harder to tell which node is which. It would be great if a name tag could get displayed in the Node's box in view. Something like "Sequence (chaseEnemy)"

Feedback

I've been playing around with this editor. Thanks for this!

Here is some feedback.

Main Criticism

  • Doesn't appear to be any way to copy/move nodes and subtrees. This should be possible using both standard keyboard shortcuts and mouse.
  • No way to change root node type
  • Disallow loading owl-bt.json file as a tree. I got confused between projects and trees
  • The way file loading and stuff was confusing to begin with - maybe only require users to open owlbt with a project dir, and allow creating tree files from within the web UI
  • Update font awesome, the first icon I found - running wasn't available in this editor

Minor suggestions

  • Nodes with no description don't align properly

    image

  • Split programmatic name and readable (ie: shown) labels for nodes. Ability to comment / give custom labels.

  • Logically, shouldn't decorators be above a node because they run before the node? They are like this in unreal

    image

  • Minor thing - when adding new nodes, maybe move camera with/relative to the parent to avoid this:

    image

    Ie: if the parent node moves 10 pixels, move the camera 10 pixels

The good stuff

  • It looks and feels great
  • owl-bt.json is a nice way to define nodes

enhancement: temp disable tree nodes

I think it would be great to have a feature like disabling tree node and its sub nodes. (They may get greyed out). This would be very useful for testing AI's behavior for a specific part.

Allow users to add comments/labels

Could be done by allowing the label of a node to be varied per node.

I'm wondering whether this would be better to be done by the user as a custom decorator

Minor bug: Inverted colors for decorators and services in the Item Palette panel.

This is a minor bug. Only affects display.

On the left-hand side panel, the colors for Services and Decorators are inverted.

The services have the color blue, but they should be green.
The decorators have the color green, but they should be blue.

When the node is placed in the workarea, the colors are displayed correctly: blue for decorators, green for services.

Enhancement: Multiple inheritance

Allow derived nodes to be created from multiple defined base nodes.

for example with these base nodes:

{
    "name": "BaseNodeA",
    "isAbstract" : true,
    "properties": [
      {
        "name": "prop-from-baseA-1",
        "type": "string"
      },
      {
        "name": "prop-from-baseA-2",
        "type": "number"
      }
    ]
},
{
    "name": "BaseNodeB",
    "isAbstract" : true,
    "properties": [
      {
        "name": "prop-from-baseB-1",
        "type": "string"
      },
      {
        "name": "prop-from-baseB-2",
        "type": "number"
      }
    ]
}

and derived node:

{
    "name": "DerivedNode",
    "base": ["BaseNodeA", "BaseNodeB"]
}

would produce node:

{
    "name": "DerivedNode",
    "properties": [
      {
        "name": "prop-from-baseA-1",
        "type": "string"
      },
      {
        "name": "prop-from-baseA-2",
        "type": "number"
      },
      {
        "name": "prop-from-baseB-1",
        "type": "string"
      },
      {
        "name": "prop-from-baseB-2",
        "type": "number"
      }
    ]
}

Add human-readable node type to node

Consider allowing node types to specify a human readable name which can be different to the actual name, and used in place of the programmatic name when rendering. This will aid in translations.

{
    "name": "MyNode",
    "label": "A {{ Arg }} node"
}

GitHub Sponsors?

Love the tool!
Ever thought about signing up for github sponsors to get some sponsorships on it?

Error on npm install

I installed owl-bt from npm originally, and that worked fine.

Now, I'm attempting to get a development version running so I can make some simple pull requests.

I did the following

# installed ruby, ruby-sass, and bootstrap-sass systemwide
npm install

I get the following error:

 Warning: Error: File to import not found or unreadable: bootstrap-sass/assets/stylesheets/bootstrap.
           Load paths:
             /home/user/dev/owl-bt/src/client/bower_components
             /home/user/dev/owl-bt/src/client/app
             /home/user/dev/owl-bt/src/client/components
            on line 4 of src/client/app/app.scss

versions:

  • npm - 6.14.1
  • node - 13.9.0
  • ruby - 2.7
  • sass - 3.7.4
  • bootstrap-sass - 3.4.1

Update font awesome

Font awesome is out of date - at 4.7.0. The latest version is 5.12.1. I see that the version is limited to below 5 in the config, is this due to not having got around to fixing the breaking changes or some other reasons?

Add ability to change root type

This could either by done using a general way to change a node's type, or by allowing the a new node to be placed as the parent of the old root node

enhancement: user-defined types

On the 1.1 addition of user-define types.

A) When a property has a user-defined type, and then you set the value of that property to a bad value, the field will turn red -- that's good. However, if you click away from the node, the value for the field is lost. Instead, the value for the field should remain, and the color should remain red. Making a mistake with the value is penalized by losing the value, which is not optimal. Keeping the value in place will make it easier to fix the error.

B) If you put a bad value on a property with a user-defined type, and then go to save the file, it will not save. That's good. However, there is no message telling you that the file was not saved. There should be a message saying that the file was not saved because of a bad property value. Ideally, the message would mention the node type and the property name, so that it's easy to locate.

Do this project have a specific licence?

Hi, pruttned!
We want to use owl-bt project to generate bt structure and use it in our robotics project. So I wonder if there is a licence for this ?
And I have some advice while using it. It is not that convenient to edit the tree when the tree becomes large, as I can not use mouse to drug the tree. Maybe my interaction is wrong.
Hope to hear response from u ASAP.
Thanks!

Charles.

Typo in readme.md

The example given under "Open an existing tree" should probably be: "owlbt o path" and not "owlbt c path".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.