Add inverter node

This commit is contained in:
Shylie 2024-06-30 18:23:36 -04:00
parent 4422642458
commit 342168c6c6

View File

@ -2,7 +2,7 @@ local Tactree = {}
local Nodes = {} local Nodes = {}
local function NodeStart(node, args) local function NodeStart(node, args)
-- abort if started -- don't start again if started
if node.data then return end if node.data then return end
node.data = node.parent and node.parent.data or args node.data = node.parent and node.parent.data or args
@ -11,7 +11,7 @@ local function NodeStart(node, args)
end end
local function NodeUpdate(node) local function NodeUpdate(node)
-- abort if not started -- don't tick if not started
if not node.data then return end if not node.data then return end
local result = node:_tick() local result = node:_tick()
@ -91,7 +91,7 @@ function Tactree.Tree(name)
end end
end end
return setmetatable(node, { __index = Nodes[name] }) return setmetatable(node, { __index = Nodes[name], __tostring = function() return name end })
end end
Tactree.Leaf 'Sequence' Tactree.Leaf 'Sequence'
@ -142,6 +142,18 @@ Tactree.Leaf 'Selector'
end end
} }
Tactree.Leaf 'Inverter'
{
start = function(node)
node.children[1]:start()
end,
tick = function(node)
local result = node.children[1]:update()
if type(result) == 'boolean' then return not result end
end
}
Tactree.Leaf 'RepeatUntilFail' Tactree.Leaf 'RepeatUntilFail'
{ {
start = function(node) start = function(node)