xxtouch吧 关注:263贴子:773
  • 7回复贴,共1

XXTouch 桃大_Do框架实现

只看楼主收藏回复

更改点色判断使用 screen.is_colors
csim 更改为 相似度
加入数据判断(避免传入不正确的值)
function _Do(_tab)
-- 判断是否传入的是正确内容
local check_table
check_table = function(t)
if type(t) ~= 'table' then error('传入非table内容',3) end
if #t == 0 then error('传入table无数据',3) end
if not (type(t.csim) == 'number' or type(t.csim) == 'nil') then error('相似度数值不正确',3) end
if not (
(
type(t.Repeat) == 'table' and
type(t.Repeat.n) == 'number' and
type(t.Repeat.Run) == 'function'
) or
type(t.Repeat) == 'nil'
) then
error('重复检测参数不正确',3)
end
if not (
(
type(t.timeout) == 'table' and
type(t.timeout.n) == 'number' and
type(t.timeout.Run) == 'function'
) or
type(t.timeout) == 'nil'
) then
error('超时参数不正确',3)
end
for n, v in ipairs(t) do
if not (
type(v.Color) == 'table' and
type(v.Run) == 'function' and
(type(v.csim) == 'number' or type(v.csim) == 'nil') and
(type(v.layer) == 'table' or type(v.layer) == 'nil')
) then
error(
string.format(
"传入table第%d项不正确",
n
),
3
)
else
for _n, _v in ipairs(v.Color) do
if not (
type(_v[1]) == 'number' and
type(_v[2]) == 'number' and
type(_v[3]) == 'number'
) then
error(
string.format(
"传入table第%d项内点色第%d项不正确",
n,
_n
),
3
)
end
end
if type(v.layer) == 'table' then
check_table(v.layer)
end
end
end
end
check_table(_tab)
if _G.DoName then table.insert(DoName,_tab.Name) else _G.DoName = {_tab.Name} end
local _now = os.time()
local _break = false
local _Repeat = false
for _key,_value in ipairs(_tab) do _value.RepeatTime = os.time() end
if _tab.Begin then _tab.Begin() end
while true do
local _States = {}
--寻找满足状态的项
screen.keep()
for _key,_value in ipairs(_tab) do
if screen.is_colors(_value.Color, _value.csim or _tab.csim) then
table.insert(_States,_key)
if _tab.Repeat then
if os.time() - _value.RepeatTime >= _tab.Repeat.n then
_value.RepeatTime = os.time()
if not _value.NoRepeat then _Repeat = true;nLog(_value.Name..' 重复') end
end
end
else
_value.RepeatTime = os.time()
end
end
screen.unkeep()
--超时判断
if #_States == 0 then
if _tab.timeout then
if os.time() - _now >= _tab.timeout.n then
nLog('超时')
local _Back = _tab.timeout.Run()
if _Back then return end
if _tab.timeout.layer then _Do(_tab.timeout.layer) end
_now = os.time()
end
end
else
--执行满足状态的项
for _key,_value in ipairs(_States) do
local _Handle = _tab[_value]
nLog(_Handle.Name)
if _Handle.Run then if _Handle.Run() then _break = true end end
if _Handle.layer then _Do(_Handle.layer) end
_now = os.time()
end
if _break then break end
if _Repeat then if _tab.Repeat.Run() then return end
_Repeat=false
end
end
sys.msleep(_tab.sleep or 500)
end
if _tab.End then _tab.End() end
if type(_G.DoName) == 'table' then
if #(_G.DoName) > 0 then
table.remove(_G.DoName,#DoName)
end
end
end


1楼2016-08-29 19:50回复
    传入数据示例:
    Test = { Name = '测试框架',
    { Name = '测试1',
    Color = {
    {619,110,0x334455},
    },
    Run = (function()
    touch.tap(100,100)
    end),
    },
    { Name = '测试2',
    Color = {
    {619,110,0xffffff},
    },
    Run = (function()
    return true --跳出
    end),
    layer = { Name = '测试2层',
    { Name = '测试3',
    Color = {
    {619,110,0x334455},
    },
    Run = (function()
    touch.tap(100,100)
    end),
    },
    Repeat = {
    n = 3,
    Run = (function()
    --重复
    return true
    end),
    },
    timeout = {
    n = 60,
    Run = (function()
    --超时
    end),
    },
    Begin = (function() end),
    End = (function() end),
    sleep = 800,
    csim = 20
    },
    csim = 20,
    },
    Repeat = {
    n = 3,
    Run = (function()
    --重复
    return true
    end),
    },
    timeout = {
    n = 60,
    Run = (function()
    --超时
    end),
    },
    Begin = (function() end),
    End = (function() end),
    sleep = 800,
    csim = 20
    }
    --[[
    层级关系 循环线性流程
    层内 必须存在一项子项目
    Name 为框架名
    *Repeat 为重复检测到后处理方式
    n 为重复检测到时常满足 3秒内 每次都能找到
    Run 为重复检测到后的处理方式
    *timeout 超时任何东西未检测到后处理方式
    n 在这段时间内任何东西没有找到则按照超时处理
    Run 处理方式
    *Begin 开启层前处理
    *End 跳出层时处理
    *sleep 每次处理完一次循环逻辑 等待时常
    *csim 全局相似度
    子项目处理
    { Name = '测试1', --名字
    Color = { --判断屏幕指定位置的色彩是否满足
    {619,110,0x334455},
    },
    Run = (function()
    touch.tap(100,100)
    end),
    layer = { --下一层
    { Name = '测试1',
    Color = {
    {619,110,0x334455},
    },
    Run = (function()
    touch.tap(100,100)
    end),
    csim = 20,
    },
    },
    csim = 20, --局部相似度 (优先局部 后 全局)
    },
    *csim可为空
    ]]


    2楼2016-08-29 19:51
    回复
      精华占楼更新人工置顶


      3楼2016-08-31 00:33
      回复
        精华占楼更新人工置顶


        5楼2016-09-01 13:42
        回复
          教程贴没人顶没天理


          来自iPhone客户端6楼2016-09-04 00:19
          回复
            触动妄图占XXTouch吧打广告真是拙计啊


            7楼2016-09-05 15:25
            回复
              听说要凑15个字才能拿经验,是真的吗?


              IP属地:湖南来自iPhone客户端10楼2016-09-06 18:56
              回复
                听说要凑15个字才能拿经验,是真的吗?


                IP属地:湖南来自iPhone客户端11楼2016-09-06 18:56
                回复