forked from wudeng/lbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence.lua
38 lines (33 loc) · 827 Bytes
/
sequence.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
local Const = require "const"
local BTCommon = require "bt_common"
local mt = {}
mt.__index = mt
function mt:run(tick, data)
for _, node in ipairs(self.children) do
local status = BTCommon.execute(node, tick, data.__level + 1)
if status ~= Const.SUCCESS then
return status
end
end
return Const.SUCCESS
end
function mt:close(tick)
for _, node in ipairs(self.children) do
local child_data = tick[node]
if child_data and child_data.is_open then
child_data.is_open = false
if node.close then
node:close(tick, child_data)
end
end
end
end
local function new(...)
local obj = {
name = "sequence",
children = {...},
}
setmetatable(obj, mt)
return obj
end
return new