Skip to content

Commit

Permalink
新增自动下载功能
Browse files Browse the repository at this point in the history
  • Loading branch information
MK331 committed Feb 26, 2021
1 parent d5b8c45 commit 304e337
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions autochoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ var sdcard = files.getSdcardPath();
requestScreenCapture();

function initOpts(){
toast("正在初始化因子列表");
var dir = sdcard+"/脚本/[email protected]/pics/"
var jpgFiles = files.listDir(dir, function(name){
return name.endsWith(".jpg") && files.isFile(files.join(dir, name));
});
// for(i = 0; i < jpgFiles.length; ++i){
// jpgFiles[i] = '"' + jpgFiles[i] + '"';
// }
// log(jpgFiles);
for(i = 0; i < jpgFiles.length; ++i){
jpgFiles[i] = jpgFiles[i].substr(0, jpgFiles[i].length - 4);
}
Expand All @@ -17,6 +20,7 @@ function initOpts(){
return param1.localeCompare(param2,"zh");
}
);

return jpgFiles;
}

Expand All @@ -26,8 +30,13 @@ function round(){
var img = captureScreen();
//images.resize(img, [2280,1080]);
var isLoop = 10;

allFunc = ["初次使用初始化", "选择因子"]
var getPic = dialogs.singleChoice("请选择功能", allFunc);
if(getPic == -1)exit();
else if(getPic == 0)picInit();

opts = initOpts();
toast("初始化完成");

var ans = dialogs.multiChoice("请选择因子", opts);
if(ans.length == 0 )exit();
Expand Down Expand Up @@ -69,12 +78,7 @@ function round(){
}

function debug(){
var img = captureScreen();
var dir = sdcard+"/脚本/[email protected]/pics/"
var tmp = images.read(dir + "refresh.png");
var button = findImage(img, tmp);
log(button.x);
toast("123");
picInit();
}

function judge(ans, img, h, w){
Expand All @@ -87,5 +91,25 @@ function judge(ans, img, h, w){
return true;
}

function picInit(){
toast("开始下载");
var picName = ["refresh.png", "怪物密集.jpg", "无限能量.jpg", "敌人弹速增快.jpg", "随机武器.jpg", "多重雕像.jpg", "更强护盾.jpg", "暴击概率加倍.jpg", "更少天赋.jpg", "双数首领.jpg", "更多精英怪物.jpg", "冷却减缓.jpg", "自带配件.jpg", "更多天赋选择.jpg", "随机角色.jpg", "固定一血.jpg", "集体复活.jpg", "体型增大.jpg", "攻击加倍.jpg", "更多房间.jpg", "冷却减半.jpg", "近战限定.jpg", "攻速加倍.jpg"];
var dir = sdcard+"/脚本/[email protected]/pics/";
files.createWithDirs(dir);
for(i = 0; i < picName.length; i++){
if(files.isFile(dir + picName[i]))continue;
let res = http.get("https://cdn.jsdelivr.net/gh/MK331/autochoice/images/" + picName[i]);
log(res);
picType = picName[i].substr(picName[i].length - 3, 3);
if(res.statusCode == 200){
let img = images.fromBytes(res.body.bytes());
log(picName[i]);
var s = images.save(img, dir + picName[i], picType, 100);
}
}
toast("下载成功");
exit();
}

//debug();
threads.start(round());

0 comments on commit 304e337

Please sign in to comment.