-
Notifications
You must be signed in to change notification settings - Fork 26
/
jump.js
51 lines (42 loc) · 1.33 KB
/
jump.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* Created by beiwan on 2017/12/29.
*/
const util = require('util')
const fs = require('fs');
const path = require('path');
const exec = util.promisify(require('child_process').exec)
const ADB_PATH = 'adb'
const SCREENCAP_REMOTE_PATH = '/sdcard/screencap.png'
const SCREENCAP_PATH = path.resolve('.', 'public/images/jump_screencap')
const BOOM = 4.88
jumpGo = async (timeout) => {
const r = Math.random() * 20
const {stdout} = await exec(`${ADB_PATH} shell input touchscreen swipe ${150+r} ${200+r} ${140+r} ${100+r} ${timeout}`)
console.log(stdout)
}
fetchScreenCap = async () => {
const {stdout, stderr} = await exec(`${ADB_PATH} shell screencap -p ${SCREENCAP_REMOTE_PATH}`)
console.log('fetch...')
}
pullScreenCap = async () => {
const {stdout, stderr} = await exec(`${ADB_PATH} pull ${SCREENCAP_REMOTE_PATH} ${SCREENCAP_PATH}/screencap.png`, [])
console.log('pull...')
}
distance = (start, end) => {
return Math.sqrt(Math.pow((start.x - end.x), 2) + Math.pow((start.y - end.y), 2));
}
iJump = async (distance) => {
await jumpGo(parseInt(distance * BOOM))
await setTimeout(async() => {
await fetchScreenCap()
await pullScreenCap()
}, 2000)
}
refreshScreencap = async() => {
await fetchScreenCap()
await pullScreenCap()
}
module.exports = {
iJump,
refreshScreencap
}