UNPKG

owl-bt

Version:

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.

71 lines (60 loc) 1.57 kB
(function () { 'use strict'; class TreeSelection { constructor(_, TreeNode, AlertList) { this._ = _; this._TreeNode = TreeNode; this._AlertList = AlertList; this._selNode = null; this._selItem = null; this._selItemType = null; } /** * whether is something selected * @return {Boolean} */ hasSelected() { return !this._.isNil(this._selNode) && !this._.isNil(this._selItem); } /** * whether is specified item selected * @return {Boolean} */ isSelected(item) { return this._selItem === item; } selNode() { return this._selNode; } selItem() { return this._selItem; } /** * gets the type of the currently selected item * @return {string} 'node' or 'service' or 'decorator' */ selItemType() { return this._selItemType; } /** * select/deselect specified item * @param {node|service|decorator} item - selected item. null for deselect * @param {node} node - node that contains the specified sub item or the same node as in item in case of selected node */ select(node, item) { this._selNode = node; this._selItem = item; if (item) { if (item === node) { this._selItemType = 'node'; } else { this._selItemType = this._TreeNode.getSubItemType(node, item); } } else { this._selItemType = null; } } } angular.module('editorApp') .service('TreeSelection', TreeSelection); })();