/*
软件作者:https://xuhss.com/oxox/pro
*/
/**
*作者QQ: 1811588980
*完成时间: 2019年6月7日 上午1:58:21
*API: 27
*备注: 运行自动精灵生成的脚本文件zjs
*需要你自己改文件路径。
简单的写了一个框架,已经实现,点击,滑动,找图的简单功能。
还只是个框架,大部分功能还没完全实现。
有兴趣的可以看看完善完善。
基本思路就在那摆着呢。
**/
console.show();
//zjs_
/*
var j_ = {
delay: ()=>{},
press: () => {},
swipe: ()=>{},
findImg: () => {},
base64Img: () => {},
};
*/
auto();
if (!requestScreenCapture()) {
toast("请求截图失败");
exit();
};
let j_ = {
//需要用到的功能函数。
delay: sleep,
press: function(p, d){
log(p, d);
press(p.x, p.y, d);
},
swipe: function(p1, p2, d){
log(p1, p2, d);
swipe(p1.x, p1.y, p2.x, p2.y, d);
},
findImg: findImg,
base64Img: function(base64){
return images.fromBase64(base64);
},
};
//读取自动精灵zjs源文件。
let step_ary = readFile("./tyu.zjs");
let constData = step_ary.shift();
/*
{
"repeatCount": -1,
"pauseOnFail": true,
"count": 5,
"description": "sndkdkjd",
"minVerCode": 1,
"screenWidth": 1080,
"screenHeight": 2280,
"screenDpi": 3
}
*/
constData.repeatCount = constData.repeatCount >= 0 ? constData.repeatCount : 1;
for (let i = 0; i < constData.repeatCount; i++) {
for (let i = 0; i < step_ary.length; i++) {
let obj = step_ary[i];
//每一步的重复问题没搞懂。是延迟完重复执行的动作。还是重复延迟和动作
switch (obj.type) {
case "点击":
zjs_点击(obj);
break;
case "滑动":
zjs_滑动(obj);
break;
case "点击图片":
zjs_点击(obj);
break;
case "点击":
break;
};
};
};
//函数部分~~~~~~~~~~~~——————————————————————
//~~~~~~~~~~~~~~~~~~——————————————————————
//~~~~~~~~~~~~~~~~~~——————————————————————
//~~~~~~~~~~~~~~~~~~——————————————————————
//~~~~~~~~~~~~~~~~~~——————————————————————
//~~~~~~~~~~~~~~~~~~——————————————————————
//~~~~~~~~~~~~~~~~~~——————————————————————
function readFile(path) {
let textFile = open(path, "r");
let step_ary = textFile.readlines();
textFile.close();
return step_ary.map(function(str) {
return JSON.parse(str);
});
};
function zjs_repeatCount(rep, fun) {
rep = rep >= 0 ? rep : 1;
for (let i = 0; i < rep; i++) {
fun();
};
};
function zjs_点击(obj) {
/*
"type": "点击",
"duration": 123,
"delay": 132,
"delayUnit": 1,
"posData": {
"type": "location",
"x": "59%",
"y": "63%"
}
*/
let duration = obj.duration || 100;
zjs_delay(obj);
if (!obj.condition || zjs_condition(obj.condition)) {
let point = zjs_posData(obj.posData);
j_.press(point, duration);
};
};
function zjs_滑动(obj) {
let duration = obj.duration || 100;
zjs_delay(obj);
if (!obj.condition || zjs_condition(obj.condition)) {
let startPoint = zjs_posData(obj.startPos);
let endPoint = zjs_posData(obj.endPos);
j_.swipe(startPoint, endPoint, duration);
};
};
function zjs_delay(obj) {
//延迟。
if (obj.delay) {
let delay = obj.delay;
switch (obj.delayUnit) {
case 1:
delay = delay * 1000;
break;
case 2:
delay = delay * 60 * 1000;
break;
};
j_.delay(delay);
};
};
function zjs_condition(obj) {
//条件判断。
switch (obj.type) {
case "image":
return zjs_condition_image(obj);
break;
case "textFount":
return zjs_condition_textFount(obj);
break;
case "conditionSet":
return zjs_condition_conditionSet(obj);
break;
};
};
function zjs_condition_image(obj) {
//找图条件。
let imageData = obj.imageData;
let img = j_.base64Img(imageData.data);
let k = false;
if (obj.limitArea) {
let region = obj.limitArea.split(" ");
region = region.map(function(str) {
return zjs_pos_p(str);
});
region[0] = region[0] * constData.screenWidth;
region[1] = region[1] * constData.screenHeight;
region[2] = region[2] * constData.screenWidth;
region[3] = region[3] * constData.screenHeight;
region[2] = region[2] - region[0];
region[3] = region[3] - region[1];
k = new j_.findImg(img).region(region).exists();
} else {
k = new j_.findImg(img).exists();
};
img.recycle();
if (obj.runWhenFalse) {
k = !k;
};
return k;
};
function zjs_condition_textFount(obj) {
//找文字条件。不会写。
/*
{
"type": "textFount",
"text": "文字出现。"
}
*/
//不会搞。
var k = false;
if (obj.runWhenFalse) {
k = !k;
};
return true;
};
function zjs_condition_conditionSet(obj) {
//多个条件。
/*
"type": "conditionSet",
"conditions": [{
*/
var k = false;
if (obj.matchMode == "and") {
for (let ob of obj.condition) {
let g = zjs_condition(ob);
if (!g) {
k = false;
break;
} else {
k = k || g;
};
};
} else if (obj.matchMode == "or") {
for (let ob of obj.condition) {
let g = zjs_condition(ob);
if (g) {
k = true;
break;
};
};
};
if (obj.runWhenFalse) {
k = !k;
};
return k;
};
function zjs_posData(obj) {
//坐标数据。
switch (obj.type) {
case "location":
return zjs_pos_location(obj);
break;
case "image":
return zjs_pos_image(obj);
break;
case "textFount":
return zjs_pos_textFount(obj);
break;
};
};
function zjs_pos_p(str) {
//坐标表达方式转换。
if (typeof(str) == "string") {
let num = parseFloat(str);
if (str.indexOf("%") >= 0) {
return num / 100;
} else if (str.indexOf("dp") >= 0) {
return num * constData.screenDpi;
};
};
return 0;
};
function zjs_pos_location(obj) {
//坐标位置。
/*
"type": "location",
"xOffset": "12dp",
"yOffset": "13dp",
"x": "34%",
"y": "33%"
*/
let x = zjs_pos_p(obj.x) * constData.screenWidth;
let y = zjs_pos_p(obj.y) * constData.screenHeight;
if (obj.xOffset) {
x += zjs_pos_p(ob