Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyJiangWJ committed Jun 27, 2024
2 parents 108eb35 + 0fffcb4 commit 443b8a8
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 11 deletions.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ let default_config = {
chatgml_api_key: '',
forum_url: 'https://autoscripts.flarum.cloud/',
// 代码版本
code_version: 'v1.5.1',
code_version: 'v1.5.2',
}
// 文件更新后直接生效,不使用缓存的值
let no_cache_configs = ['release_access_token', 'code_version']
Expand Down
5 changes: 3 additions & 2 deletions core/Ant_forest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: NickHopps
* @Date: 2019-01-31 22:58:00
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2024-06-22 23:53:54
* @Last Modified time: 2024-06-27 22:21:11
* @Description:
*/
let { config: _config, storage_name: _storage_name } = require('../config.js')(runtime, global)
Expand Down Expand Up @@ -293,10 +293,11 @@ function Ant_forest () {
let ballPoints = []
if (YoloDetection.enabled) {
// 获取倒计时球 invalidBall
_base_scanner.checkAndCollectByYolo(true, null, ball => ballPoints.push(ball), null, 1)
_base_scanner.checkAndCollectByYolo(true, null, null, ball => ballPoints.push(ball), 1)
} else {
_base_scanner.checkAndCollectByHough(true, balls => ballPoints = balls, null, null, 1)
}
debugInfo(['识别不可收取能量球数量:{}', ballPoints.length])
return ballPoints.filter(ball => {
let radius = parseInt(ball.radius)
if (
Expand Down
7 changes: 5 additions & 2 deletions core/BaseScanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: TonyJiangWJ
* @Date: 2019-12-18 14:17:09
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2024-06-23 00:05:31
* @Last Modified time: 2024-06-27 22:30:09
* @Description: 能量收集和扫描基类,负责通用方法和执行能量球收集
*/
importClass(java.util.concurrent.LinkedBlockingQueue)
Expand Down Expand Up @@ -321,14 +321,17 @@ const BaseScanner = function () {
automator.click(c.x + c.width / 2, c.y + c.height / 2)
self.collect_count++
self.randomSleep()
if (c.label == 'waterBall') {
this.recheck = true
}
})
self.collect_operated = true
}
rgbImg.recycle()
}
// 有浇水能量球且收自己时,进行二次校验 最多3次 || 非收取自己,且未找到可操作能量球,二次校验 仅一次 || 使用了双击卡,且点击过球
repeat = this.recheck && this.is_own && --recheckLimit > 0
|| !haveValidBalls && --recheckLimit >= 2
|| !this.is_own && !haveValidBalls && --recheckLimit >= 2
|| _config.double_check_collect && haveValidBalls && --recheckLimit > 0
if (repeat) {
debugInfo(['需要二次校验,等待{}ms', this.is_own ? 200 : 500])
Expand Down
6 changes: 3 additions & 3 deletions lib/prototype/YoloDetectionUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function checkYoloModelValid (modelPath) {
yoloSupport = false
return null
}
debugForDev('model last line:', modelLastLine)
debugForDev('model last line:' + modelLastLine)
let regex = /^.*names.*(\{.*\})/
let checkResult = regex.exec(modelLastLine)
if (!checkResult || checkResult.length < 1) {
Expand All @@ -134,10 +134,10 @@ function checkYoloModelValid (modelPath) {
}
let jsonStr = checkResult[1]
try {
debugForDev('extra json:', jsonStr)
debugForDev('extra json:' + jsonStr)
let modelLabels = JSON.parse(jsonStr.replace(/'/g, '"'))
let labelList = Object.keys(modelLabels).map(k => modelLabels[k])
debugForDev('当前模型支持的标签:', labelList)
debugForDev('当前模型支持的标签:' + labelList)
return labelList
} catch (e) {
warnInfo(['模型标签解析失败,请检查模型是否正确'])
Expand Down
2 changes: 1 addition & 1 deletion lib/touchDevice.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (currentVersion) {
let formBody = new FormBody.Builder()
.add('currentVersion', currentVersion)
.add('deviceId', deviceId).build()
let request = new Request.Builder().url('https://tonyjiang.hatimi.top//device-info/touch').post(formBody).build()
let request = new Request.Builder().url('https://tonyjiang.hatimi.top/device-info/touch').post(formBody).build()

response = okHttpClient.newCall(request).execute()
if (response != null && response.body() != null) {
Expand Down
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* @Author: NickHopps
* @Last Modified by: TonyJiangWJ
* @Last Modified time: 2024-06-21 13:28:02
* @Last Modified time: 2024-06-27 18:49:40
* @Description: 蚂蚁森林自动收能量
*/
console.warn('如遇语法报错,请从README下载最新版的AutoJS,旧版本不维护,不适配')
Expand Down Expand Up @@ -184,6 +184,7 @@ commonFunctions.autoSetUpBangOffset()
* 主程序
***********************/
if (config.develop_mode) {
warnInfo(['如非必要,请关闭开发模式,保存YOLO数据等机制不需要持续开启开发模式'], true)
antForestRunner.exec()
} else {
try {
Expand Down
9 changes: 9 additions & 0 deletions vue_configs/js/configLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ function getLabelByConfigKey(key) {
}
}
return key
}

/**
* getLabelByConfigKey 简化写法
* @param {String} key
* @returns
*/
function $t(key) {
return getLabelByConfigKey(key)
}
2 changes: 1 addition & 1 deletion vue_configs/js/jsLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const loadJsList = [
'https://fastly.jsdelivr.net/npm/axios@0.25.0/dist/axios.min.js',
'https://fastly.jsdelivr.net/npm/js-base64@3.7.2/base64.min.js',
'./js/mdjs.min.js',
'./js/configLabels.js',
'./js/components/configuration/About.js',
'./js/components/configuration/ImageConfig.js',
'./js/components/configuration/DevelopConfig.js',
Expand All @@ -24,6 +23,7 @@ const loadJsList = [
* 需要顺序加载的
*/
const mainJsList = [
'./js/configLabels.js',
'./js/routerIndex.js',
'./js/store.js',
'./js/app.js',
Expand Down
170 changes: 170 additions & 0 deletions 独立工具/LogFloatyTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
let { config } = require('../config.js')(runtime, global)
config.buddha_like_mode = false
let singletonRequire = require('../lib/SingletonRequirer.js')(runtime, global)
let { logInfo, errorInfo, warnInfo, debugInfo, infoLog, debugForDev, clearLogFile, flushAllLogs } = singletonRequire('LogUtils')
let floatyInstance = singletonRequire('FloatyUtil')
floatyInstance.enableLog()
let commonFunctions = singletonRequire('CommonFunction')
let automator = singletonRequire('Automator')
let runningQueueDispatcher = singletonRequire('RunningQueueDispatcher')
let TouchController = require('../lib/TouchController.js')
let AiUtil = require('../lib/AIRequestUtil.js')
let logFloaty = singletonRequire('LogFloaty')
logFloaty.fontSize = 30
let warningFloaty = singletonRequire('WarningFloaty')
config.debuging = true
let SCALE_RATE = config.scaleRate
let cvt = (v) => parseInt(v * SCALE_RATE)
config.not_lingering_float_window = true
config.sea_ball_region = config.sea_ball_region || [cvt(860), cvt(1350), cvt(140), cvt(160)]
logInfo('======加入任务队列,并关闭重复运行的脚本=======')
runningQueueDispatcher.addRunningTask()
let ai_type = config.ai_type || 'kimi'
let kimi_api_key = config.kimi_api_key
// 注册自动移除运行中任务
commonFunctions.registerOnEngineRemoved(function () {
config.resetBrightness && config.resetBrightness()
debugInfo('校验并移除已加载的dex')
// 移除运行中任务
runningQueueDispatcher.removeRunningTask(true, false,
() => {
// 保存是否需要重新锁屏
config.isRunning = false
}
)
}, 'main')

if (!commonFunctions.ensureAccessibilityEnabled()) {
errorInfo('获取无障碍权限失败')
exit()
}


let executeArguments = engines.myEngine().execArgv
debugInfo(['启动参数:{}', JSON.stringify(executeArguments)])

commonFunctions.listenDelayStart()
importClass(android.graphics.drawable.GradientDrawable)
importClass(android.graphics.drawable.RippleDrawable)
importClass(android.content.res.ColorStateList)
importClass(java.util.concurrent.LinkedBlockingQueue)
importClass(java.util.concurrent.ThreadPoolExecutor)
importClass(java.util.concurrent.TimeUnit)
importClass(java.util.concurrent.ThreadFactory)
importClass(java.util.concurrent.Executors)
let threadPool = new ThreadPoolExecutor(2, 2, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(16),
new ThreadFactory({
newThread: function (runnable) {
let thread = Executors.defaultThreadFactory().newThread(runnable)
thread.setName('ai-operator-' + thread.getName())
return thread
}
})
)
let data = {
btnDrawables: {}
}
// 启动UI形式,支持手动执行更多功能
let btns = [
{
id: 'addLongText',
text: '打印长文本',
onClick: function () {
logFloaty.pushLog('这是一条长文本:通过上述属性的组合使用,你可以创建出既美观又具有良好交互体验的按钮。记住,设计按钮时要保持整体界面风格的一致性,确保按钮的样式与应用的主题和设计语言相匹配。')
}
},
{
id: 'addShortText',
text: '打印短文本',
onClick: function () {
logFloaty.pushLog('这是一条短文本')
},
},
{
id: 'exit',
color: '#EB393C',
rippleColor: '#C2292C',
text: '退出脚本',
onClick: function () {
exit()
}
}
]

let window = floaty.rawWindow(
`<horizontal>
<vertical padding="1">
${btns.map(btn => {
return `<vertical marginTop="5" marginBottom="5"><button id="${btn.id}" text="${btn.text}" textSize="${btn.textSize ? btn.textSize : 12}sp" w="*" h="30" /></vertical>`
}).join('\n')
}</vertical>
</horizontal>`)
ui.run(() => {
window.setPosition(config.device_width * 0.1, config.device_height * 0.5)
})
btns.forEach(btn => {
ui.run(() => {
setButtonStyle(btn.id, btn.color, btn.rippleColor)
})
if (btn.onClick) {
window[btn.id].on('click', () => {
if (data.clickExecuting) {
threadPool.execute(function () {
logFloaty.pushLog('点击执行中,请稍等')
})
return
}
data.clickExecuting = true
threadPool.execute(function () {
try {
btn.onClick()
} catch (e) {
errorInfo(['点击执行异常:{}', e.message], true)
} finally {
data.clickExecuting = false
}
})
})
}
})
window.exit.setOnTouchListener(new TouchController(window, () => {
exit()
}, () => {
changeButtonStyle('exit', null, '#FF753A', '#FFE13A')
}, () => {
changeButtonStyle('exit', (drawable) => {
drawable.setColor(colors.parseColor('#EB393C'))
drawable.setStroke(0, colors.parseColor('#3FBE7B'))
})
}).createListener())

setInterval(() => {
runningQueueDispatcher.renewalRunningTask()
}, 60000)

function setButtonStyle (btnId, color, rippleColor) {
let shapeDrawable = new GradientDrawable();
shapeDrawable.setShape(GradientDrawable.RECTANGLE);
// 设置圆角大小,或者直接使用setCornerRadius方法
// shapeDrawable.setCornerRadius(20); // 调整这里的数值来控制圆角的大小
let radius = util.java.array('float', 8)
for (let i = 0; i < 8; i++) {
radius[i] = 20
}
shapeDrawable.setCornerRadii(radius); // 调整这里的数值来控制圆角的大小
shapeDrawable.setColor(colors.parseColor(color || '#3FBE7B')); // 按钮的背景色
shapeDrawable.setPadding(10, 10, 10, 10); // 调整这里的数值来控制按钮的内边距
// shapeDrawable.setStroke(5, colors.parseColor('#FFEE00')); // 调整这里的数值来控制按钮的边框宽度和颜色
data.btnDrawables[btnId] = shapeDrawable
let btn = window[btnId]
btn.setShadowLayer(10, 5, 5, colors.parseColor('#888888'))
btn.setBackground(new RippleDrawable(ColorStateList.valueOf(colors.parseColor(rippleColor || '#27985C')), shapeDrawable, null))
}

function changeButtonStyle (btnId, handler, color, storkColor) {
handler = handler || function (shapeDrawable) {
color && shapeDrawable.setColor(colors.parseColor(color))
storkColor && shapeDrawable.setStroke(5, colors.parseColor(storkColor))
}
handler(data.btnDrawables[btnId])
}
Loading

0 comments on commit 443b8a8

Please sign in to comment.