Last Modified: 2023-12-19
Behavior Tree in Editor
This is experimental. A Behavior tree implemetation enables a conditional call for an action node. If conditions are not satisfied for a button, the associated action to the button will not be executed when user clicks it
editor/controller/BTree/selectors.tree
BTree calls BThandler when actionNode is activated. The parameters are stored in backboard.
editor.index
M.commands = { {name="selectApp", btree=nil}, {name="selectBook", btree="load book"}, {name="selectPage", btree="load page"}, {name="selectLayer", btree="load layer"}, {name="selectPageProps", btree=nil}, -- {name="selectAction", btree=""}, {name="selectTool", btree="editor component"}, -- {name="selectActionCommand", btree=""} {name="selectAudio", btree="load audio"}, {name="selectGroup", btree="load group"}, {name="selectTimer", btree="load timer"}, {name="selectVariable", btree="load variable"}, -- {name="selectVideo", btree="load video"}, } -- connects with BTree ---- local BTMap = {} for i=1, #M.commands do if M.commands[i].btree then BTMap[M.commands[i].btree] ={eventName = "editor.selector."..M.commands[i].name, name = M.commands[i].name} end end -- BTree calls this when activating actionNode M.BThandler = function(name, status) -- print("#BTHandler: dispathEvent") -- print("", name, bt.getFriendlyStatus( nil,status )) local target = BTMap[name] -- print("", target) if target then -- print("", target.eventName) --local obj = M.UI.editor.sceneGroup[target.name] local params = { name = target.eventName, UI = M.UI, -- beaware UI is belonged to a page -- show = not obj.isVisible, } if tree.backboard then for k, v in pairs(tree.backboard) do params[k] = v end end M.UI.scene.app:dispatchEvent(params) end return bt.SUCCESS end