# touchsprite-lib
**Repository Path**: trium/touchsprite-lib
## Basic Information
- **Project Name**: touchsprite-lib
- **Description**: `触动精灵` 自封装 Lua库
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 3
- **Created**: 2023-07-01
- **Last Updated**: 2024-09-02
## Categories & Tags
**Categories**: Uncategorized
**Tags**: Lua
## README
# touchsprite-lib
全部公开,我自己线上 `触动精灵` 自封装的 库
# 一、IDE
- 触动精灵脚本编辑器(IDE)Mac 版
- 触动精灵脚本编辑器(IDE)Windows 版
https://www.touchsprite.com/download
# 二、注意
- 所有库都是应用于 `Android`,如果使用 `iOS`需要修改部分代码。
- 不可直接运行
- 自行查看代码,选择合适的移入自己的项目
- 内部有 很多 通用的变量,一定要自行测试下
# 三、打包脚本
- 源码不打算公开
- 其中一个 公开了 node [rxluag-cli](https://www.npmjs.com/package/rxluag-cli),如果不熟悉 后期会开发其他语言[lua-obfuscator](https://gitee.com/pulpous/lua-obfuscator) 会等很久。
# 四、友情链接
- [触动精灵 app - 日志监听服务 touchsprite-monitor-node](https://gitee.com/trium/touchsprite-monitor-node)
# 五、UI配置 3种写法都有
1. 采用 UINew 创建 UI
1. 采用 table -> ShowUI
1. webview -> ui
# 六、触动封装
- [lua源码 打包成so库](https://www.cnblogs.com/cdyboke/p/7750117.html) gcc
> gcc
- win 32位 `minGW`
- win 32/64位 `minGW-64`
- `MinGW-builds` 独立的项目,它以最有用的配置提供二进制文件。要获得专门的MinGW-w64版本,手动编译仍然是可能的。
开源文件简述:
>
- [RxLog](./func/tool/RxLog.lua): nLog 远程日志: 输出日志到触动精灵 IDE 编辑器(TS Studio)
- [RxToast](./func/tool/RxToast.lua): 在屏幕底部以悬浮层形式显示字符串信息
- [RxDialogRet](./func/tool/RxDialogRet.lua): 带有按钮的对话框
- [RxDeviceType](./func/tool/RxDeviceType.lua): 获取设备类型
- [RxDeviceScale](./func/tool/RxDeviceScale.lua): 获取分辨率
- [RxDeviceUnlock](./func/tool/RxDeviceUnlock.lua): 设备锁定状态
- [RxRunApp](./func/tool/RxRunApp.lua): 启动某 app、解锁屏幕(非密码)
>
- [RxHttp](./func/tool/RxHttp.lua): http 网络请求 `get`/`post`
- [RxTsDownload](./func/tool/RxTsDownload.lua): `ts.tsDownload` 下载服务器文件到本地
>
- [RxFindText](./func/tool/RxFindText.lua): 识别字库 `resources/font/**`
- [RxFindColor](./func/tool/RxFindColor.lua): 识别颜色 `resources/color/**`
- [RxFindPng](./func/tool/RxFindPng.lua): 误差找图、二值化找图
- [RxMuitlColor](./func/tool/RxMuitlColor.lua): 多点颜色比对
>
- [RxDhFile](./func/tool/RxDhFile.lua): 文件`读/写`操作, (可以设置 过期文件删除)
- [RxLocationScale](./func/tool/RxLocationScale.lua): 坐标缩放
- [RxRandom](./func/tool/RxRandom.lua): 随机`数字`、`汉字`
- [RxString](./func/tool/RxString.lua): 字符串封装
- [RxTable](./func/tool/RxTable.lua): table 封装
- [RxTime](./func/tool/RxTime.lua): `日期`+`时间`封装
- [RxTouch](./func/tool/RxTouch.lua): 点击事件、滑动事件
- [RxUtils](./func/tool/RxUtils.lua): 通用方法
# 六、示例
```lua
-- 测试功能 - 时间
function RxJugeUI_test_time()
RxLog('test time func')
local y,m, d = RxTime:ymd()
RxTime:week()
RxTime:shortTime()
end
```
```lua
function RxJugeUI_test_font()
-- 首页-限时活动-畅爽盛夏
local ctn = RxFindTextTable(Font_av_xshd_cssj)
-- ctn 0/1
RxLog('首页-限时活动-畅爽盛夏 ctn='..tostring(ctn))
end
```
```lua
function RxJugeUI_test_color()
-- av-color 奕定乾坤
local ctn = RxFindMultiColorTable(Color_av_yiDingQianKun)
-- ctn 0/1
RxLog('av-color 奕定乾坤 ctn='..tostring(ctn))
end
```
```lua
function RxJugeUI_test_muitlColor()
-- 知道 位置 和 颜色
-- 一般用于固定页面的按钮、图案等
-- -- 这个和
-- -- -- font(RxFindTextTable)
-- -- -- color(RxFindMultiColorTable)
-- -- -- 差不多,就是多个方案
local comfirmCos = {
{428,370,0xffb157},
{632,366,0xffe77e}
}
local close = RxMuitlColor_EqaulCos(comfirmCos)
-- close true/false
RxLog('comfirmCos close='..tostring(close))
-------------------------------------------------------------------
-- 为了适配页面的滑动,是否滑到低了
-- 1. cancelCos 是位置
-- 2. RxMuitlColor_getCos 根据位置获取颜色
-- 3. 滑动操作 RxTouchMove
-- 4. RxMuitlColor_EqaulCos 判断滑动后,是否 和之前 多个位置颜色一致,就说明到底了
local cancelCos = {
{740,163},{740,177},{740,189},{740,197}
}
local cos = RxMuitlColor_getCos(cancelCos)
RxTouchMove(56,507,56,240)
mSleep(300)
UtilAutoPointColor()
local cancel = RxMuitlColor_EqaulCos(cos)
-- cancel true/false
RxLog('cancelCos cancel='..tostring(cancel))
end
```
```lua
--本地图片 是否在 页面固定区域内,并返回坐标
function RxJugeUI_test_png()
local singleArea = {0, 0, 100, 100}
local iconIndex, localTable = RxFindPng:findPngInRegionFuzzyTable(singleArea, RxAssets.bzjiangli)
-- iconIndex 1/2 (index) ->
-- --> RxAssets.bzjiangli.icon {
-- {index = 1},
-- {index= 2,}
-- }
-- localTable table: {0, 0, 1, 1}
end
```
```lua
-- RxWhileDo
RxWhileDo(function()
local _ts = getColor(917, 10)
if _ts == 0xffffff then return 1 end
-- return 0
end, 20)
local t = RxWhileDo(function()
if getColor(917, 10) == 0xff0000 then return 1 end
end)
nLog('RxWhileDo t='..tostring(t))
```
```lua
--- 多线程
local thread = require('thread')
function RxAllThread(fn)
local ctn = 0
if not fn or type(fn) ~= 'function' then
return ctn
end
-- 创建多线程、切换多线程的任务
function nomalCreateThread(subThreadFn)
if not subThreadFn or type(subThreadFn) ~= 'function' then
RxToast('subThreadFn ~= function')
return nil
end
local t = 0
-- developEnv : Node.js打包环境变量
-- -- 这个启用了,如有崩溃,多线程就卡死了,正式环境是不启用的
if developEnv < 1 or developEnv > 10 then
t = thread.create(subThreadFn
,{
callBack = function()
--协程结束会调用,不论是错误、异常、正常结束
RxLog("UISelThread 协程结束了", 0)
end,
errorBack = function(err)
--协程错误结束,一般是引用空调用,err 是字符串
RxLog("UISelThread 协程错误了:"..err,0)
end,
catchBack = function(exp)
--协程异常结束,异常是脚本调用了 throw 激发的,exp 是 table,exp.message 是异常原因
local ts = require('ts')
local cjson = ts.json
RxLog("UISelThread 协程异常了\n"..json.encode(exp),0)
end
})
else
t = thread.create(subThreadFn)
end
thread.clearTimeout(t)
return t
end
function addThread()
mSleep(1)
UISelThread = nomalCreateThread(fn)
end
function removeThread()
if UISelThread == nil then
RxLog('线程入口 RxAllThread removeThread UISelThread == nil')
else
RxLog('将要停止线程 UISelThread='..tostring(UISelThread))
thread.setTimeout(0,UISelThread)
thread.stop(UISelThread)
UISelThread = nil
end
end
local taskIndex = -1
while true do
RxLog('-=-=-= thread -=-=-= 00000000000000')
local hour, minute = RxTime:shortTime()
local week = RxTime:week()
if hour == 4 then
if taskIndex ~= '凌晨任务' then
taskIndex = '凌晨任务'
removeThread()
-- 创建新的线程
UISelThread = nomalCreateThread(RxThread_PlayGenalTask)
end
elseif (hour == 11 and minute >= 50 and minute < 52) then
if taskIndex ~= 'boss活动' then
taskIndex = 'boss活动'
removeThread()
-- 创建新的线程
UISelThread = nomalCreateThread(RxThread_PlayLegionBoss)
end
else
if taskIndex ~= -10 then
RxLog('-=-= -10-10 2-2-2-')
taskIndex = -10
removeThread()
-- 入口传入的 fn
addThread()
end
end
end
RxLog('-=-=-= thread -=-=-= 12')
thread.waitAllThreadExit() --等待所有协程结束,只能用于主线程
return ctn
```