Skip to content

Commit fa38301

Browse files
committed
revert device state after script executed
1 parent 788c67c commit fa38301

File tree

2 files changed

+98
-34
lines changed

2 files changed

+98
-34
lines changed

euro12.js

+59-28
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
//选择可用的车,第一列第一张编号为1,第一列第二张为2,第二列第一张为3,依次递增.可根据自己需求修改
22
//填写车的编号,1920*1080上最多6张车循环,按填写先后顺序用车
33
const cars = [1, 2, 3, 4, 5, 6];
4-
const height = device.height;
5-
const width = device.width;
4+
5+
6+
/********** 设备 start **********/
7+
const { width, height } = device;
8+
9+
const POWER_SAVE_BRIGHTNESS = 0;
10+
const POWER_SAVE_MUSIC_VOLUME = 0;
11+
const AUTO_BRIGHTNESS_MODE = 1;
12+
13+
const isAutoBrightnessMode = device.getBrightnessMode();
14+
const previousBrightness = device.getBrightness();
15+
const previousMusicVolume = device.getMusicVolume();
16+
17+
/**
18+
* 调节亮度及音量,进入低功耗模式
19+
*/
20+
const _savePower = () => {
21+
device.setBrightness(POWER_SAVE_BRIGHTNESS);
22+
device.setMusicVolume(POWER_SAVE_MUSIC_VOLUME);
23+
}
24+
25+
/**
26+
* 还原运行时脚本之前的屏幕亮度及设备音量
27+
*/
28+
const _revertPower = () => {
29+
isAutoBrightnessMode ? device.setBrightnessMode(AUTO_BRIGHTNESS_MODE) : device.setBrightness(previousBrightness);
30+
device.setMusicVolume(previousMusicVolume);
31+
}
32+
33+
/**
34+
* 是否调节亮度及音量,以此减少功耗
35+
* @param {boolean} enable
36+
*/
37+
const enablePowerSave = enable => enable ? _savePower() : _revertPower();
38+
/********** 设备 end **********/
39+
40+
41+
642
var rootAutomator;
743
var robot = new Robot();
844

@@ -138,7 +174,7 @@ if (height === 1920 && width == 1080) {
138174
profile = profileB;
139175
} else if (height === 2220 && width === 1080) {
140176
profile = profileC;
141-
}
177+
}
142178
// else if (height === 1280 && width === 720) {
143179
// profile = profileD;
144180
// }
@@ -176,7 +212,7 @@ function eventListener() {
176212
if (rootAutomator != null) {
177213
rootAutomator.exit();
178214
}
179-
device.setBrightness(40);
215+
enablePowerSave(false);
180216
threads.shutDownAll();
181217
exit();
182218
});
@@ -204,12 +240,7 @@ function deviceInfo() {
204240
toast('请求截图失败,程序结束');
205241
exit();
206242
}
207-
console.log("height:" + height);
208-
console.log("width:" + width);
209-
// 调整屏幕亮度
210-
device.setBrightness(0);
211-
// 调整媒体声音
212-
device.setMusicVolume(0);
243+
enablePowerSave(true);
213244
}
214245

215246
function main() {
@@ -263,7 +294,7 @@ function afterRun() {
263294
}
264295

265296
//可能升级或有广告.
266-
while(true){
297+
while (true) {
267298
//若退出选关,可将此值调大
268299
sleep(1500);
269300
// 截图
@@ -273,7 +304,7 @@ function afterRun() {
273304
checkForResolution(profile.recommendedPoints.x, profile.recommendedPoints.y, img).positionX,
274305
checkForResolution(profile.recommendedPoints.x, profile.recommendedPoints.y, img).positionY);
275306
var hasFinish = colors.equals(color, "#ffc3fc0f") || colors.equals(color, "#ffff0054");
276-
if(hasFinish){
307+
if (hasFinish) {
277308
break;
278309
} else {
279310
robot.back();
@@ -282,28 +313,28 @@ function afterRun() {
282313

283314
// 截图
284315
var img = captureScreen();
285-
var leftup = images.pixel(img, checkForResolution(height/8, width/4, img).positionX, checkForResolution(height/4, width/4, img).positionY);
286-
var rightup = images.pixel(img, checkForResolution(height*7/8, width/4, img).positionX, checkForResolution(height*7/8, width/4, img).positionY);
287-
var leftdown = images.pixel(img, checkForResolution(height/8, width*3/4, img).positionX, checkForResolution(height/8, width*3/4, img).positionY);
288-
var rightdown = images.pixel(img, checkForResolution(height*7/8, width*3/4, img).positionX, checkForResolution(height*7/8, width*3/4, img).positionY);
289-
290-
var AD1 = color_equal(leftup, "#ff080906");
291-
var AD2 = color_equal(rightup, "#ff080906");
292-
var AD3 = color_equal(leftdown, "#ff080906");
293-
var AD4 = color_equal(rightdown, "#ff080906");
294-
295-
if (AD1 && AD2 && AD3 && AD4){
316+
var leftup = images.pixel(img, checkForResolution(height / 8, width / 4, img).positionX, checkForResolution(height / 4, width / 4, img).positionY);
317+
var rightup = images.pixel(img, checkForResolution(height * 7 / 8, width / 4, img).positionX, checkForResolution(height * 7 / 8, width / 4, img).positionY);
318+
var leftdown = images.pixel(img, checkForResolution(height / 8, width * 3 / 4, img).positionX, checkForResolution(height / 8, width * 3 / 4, img).positionY);
319+
var rightdown = images.pixel(img, checkForResolution(height * 7 / 8, width * 3 / 4, img).positionX, checkForResolution(height * 7 / 8, width * 3 / 4, img).positionY);
320+
321+
var AD1 = color_equal(leftup, "#ff080906");
322+
var AD2 = color_equal(rightup, "#ff080906");
323+
var AD3 = color_equal(leftdown, "#ff080906");
324+
var AD4 = color_equal(rightdown, "#ff080906");
325+
326+
if (AD1 && AD2 && AD3 && AD4) {
296327
robot.back();
297328
sleep(3000);
298329
}
299330
}
300331
}
301332

302-
function color_equal(color1,color2){
303-
if (colors.equals(color1,color2))
304-
return 1;
305-
else
306-
return 0;
333+
function color_equal(color1, color2) {
334+
if (colors.equals(color1, color2))
335+
return 1;
336+
else
337+
return 0;
307338
}
308339

309340
function run() {

帕加尼BC.js

+39-6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,43 @@
44
// 请根据自己实际情况修改第6行后开始运行脚本
55

66
const cars = [1, 2, 3, 4, 5, 6];
7-
const width = device.width;
8-
const height = device.height;
7+
8+
9+
/********** 设备 start **********/
10+
const { width, height } = device;
11+
12+
const POWER_SAVE_BRIGHTNESS = 0;
13+
const POWER_SAVE_MUSIC_VOLUME = 0;
14+
const AUTO_BRIGHTNESS_MODE = 1;
15+
16+
const isAutoBrightnessMode = device.getBrightnessMode();
17+
const previousBrightness = device.getBrightness();
18+
const previousMusicVolume = device.getMusicVolume();
19+
20+
/**
21+
* 调节亮度及音量,进入低功耗模式
22+
*/
23+
const _savePower = () => {
24+
device.setBrightness(POWER_SAVE_BRIGHTNESS);
25+
device.setMusicVolume(POWER_SAVE_MUSIC_VOLUME);
26+
}
27+
28+
/**
29+
* 还原运行时脚本之前的屏幕亮度及设备音量
30+
*/
31+
const _revertPower = () => {
32+
isAutoBrightnessMode ? device.setBrightnessMode(AUTO_BRIGHTNESS_MODE) : device.setBrightness(previousBrightness);
33+
device.setMusicVolume(previousMusicVolume);
34+
}
35+
36+
/**
37+
* 是否调节亮度及音量,以此减少功耗
38+
* @param {boolean} enable
39+
*/
40+
const enablePowerSave = enable => enable ? _savePower() : _revertPower();
41+
/********** 设备 end **********/
42+
43+
944

1045
var profile1920 = {
1146
//比赛
@@ -112,9 +147,7 @@ function before() {
112147
toast('请求截图失败,程序结束');
113148
exit();
114149
}
115-
// 调整屏幕亮度及媒体音量
116-
device.setBrightness(0);
117-
device.setMusicVolume(0);
150+
enablePowerSave(true);
118151
}
119152

120153
function eventListener() {
@@ -124,7 +157,7 @@ function eventListener() {
124157
// 监听音量上键按下
125158
events.onKeyDown("volume_down", function (event) {
126159
toastLog("程序手动退出");
127-
device.setBrightness(40);
160+
enablePowerSave(false);
128161
threads.shutDownAll();
129162
exit();
130163
});

0 commit comments

Comments
 (0)