-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
174 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--node_parall.lua | ||
local log_warn = logger.warn | ||
local makechan = quanta.make_channel | ||
|
||
local NodeBase = import("robot/nodes/node_base.lua") | ||
|
||
local NodeParall = class(NodeBase) | ||
local prop = property(NodeParall) | ||
prop:reader("childs", {}) --childs | ||
prop:reader("channel", nil) --channel | ||
|
||
function NodeParall:__init(case) | ||
end | ||
|
||
function NodeParall:on_load(conf) | ||
local channel = makechan("node_parall") | ||
for _, child in piars(conf.childs or {}) do | ||
channel:push(function() | ||
|
||
end) | ||
end | ||
self.channel = channel | ||
return true | ||
end | ||
|
||
function NodeParall:on_action() | ||
if self.channel then | ||
local ok, code = self.channel:execute() | ||
if not ok then | ||
log_warn("[NodeParall][on_action] robot:{} code {}", self.actor.open_id, code) | ||
self:failed("cond error") | ||
return false | ||
end | ||
end | ||
return true | ||
end | ||
|
||
return NodeParall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--node_rand.lua | ||
local log_warn = logger.warn | ||
local makechan = quanta.make_channel | ||
|
||
local NodeBase = import("robot/nodes/node_base.lua") | ||
|
||
local NodeRand = class(NodeBase) | ||
local prop = property(NodeRand) | ||
prop:reader("channel", nil) --channel | ||
|
||
function NodeRand:__init(case) | ||
end | ||
|
||
function NodeRand:on_load(conf) | ||
self.channel = makechan("node") | ||
self.failed = conf.result.failed | ||
self.success = conf.result.success | ||
return true | ||
end | ||
|
||
function NodeRand:go_next() | ||
if self.result then | ||
self.case:run_next(self.success) | ||
else | ||
self.case:run_next(self.failed) | ||
end | ||
end | ||
|
||
function NodeRand:on_action() | ||
local role = self.actor | ||
local cond = self:call_script(self.cond) | ||
if cond == nil then | ||
log_warn("[NodeRand][on_action] robot:{} cond {} id null", role.open_id, self.cond) | ||
self:failed("cond error") | ||
return false | ||
end | ||
self.result = cond | ||
return true | ||
end | ||
|
||
return NodeRand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--node_repeat.lua | ||
local log_warn = logger.warn | ||
|
||
local NodeBase = import("robot/nodes/node_base.lua") | ||
|
||
local NodeRepeat = class(NodeBase) | ||
local prop = property(NodeRepeat) | ||
prop:reader("childs", {}) --childs | ||
|
||
function NodeRepeat:__init(case) | ||
end | ||
|
||
function NodeRepeat:on_load(conf) | ||
self.cond = conf.cond | ||
self.failed = conf.result.failed | ||
self.success = conf.result.success | ||
return true | ||
end | ||
|
||
function NodeRepeat:go_next() | ||
if self.result then | ||
self.case:run_next(self.success) | ||
else | ||
self.case:run_next(self.failed) | ||
end | ||
end | ||
|
||
function NodeRepeat:on_action() | ||
local role = self.actor | ||
local cond = self:call_script(self.cond) | ||
if cond == nil then | ||
log_warn("[NodeRepeat][on_action] robot:{} cond {} id null", role.open_id, self.cond) | ||
self:failed("cond error") | ||
return false | ||
end | ||
self.result = cond | ||
return true | ||
end | ||
|
||
return NodeRepeat |