1
1
//选择可用的车,第一列第一张编号为1,第一列第二张为2,第二列第一张为3,依次递增.可根据自己需求修改
2
2
//填写车的编号,1920*1080上最多6张车循环,按填写先后顺序用车
3
3
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
+
6
42
var rootAutomator ;
7
43
var robot = new Robot ( ) ;
8
44
@@ -138,7 +174,7 @@ if (height === 1920 && width == 1080) {
138
174
profile = profileB ;
139
175
} else if ( height === 2220 && width === 1080 ) {
140
176
profile = profileC ;
141
- }
177
+ }
142
178
// else if (height === 1280 && width === 720) {
143
179
// profile = profileD;
144
180
// }
@@ -176,7 +212,7 @@ function eventListener() {
176
212
if ( rootAutomator != null ) {
177
213
rootAutomator . exit ( ) ;
178
214
}
179
- device . setBrightness ( 40 ) ;
215
+ enablePowerSave ( false ) ;
180
216
threads . shutDownAll ( ) ;
181
217
exit ( ) ;
182
218
} ) ;
@@ -204,12 +240,7 @@ function deviceInfo() {
204
240
toast ( '请求截图失败,程序结束' ) ;
205
241
exit ( ) ;
206
242
}
207
- console . log ( "height:" + height ) ;
208
- console . log ( "width:" + width ) ;
209
- // 调整屏幕亮度
210
- device . setBrightness ( 0 ) ;
211
- // 调整媒体声音
212
- device . setMusicVolume ( 0 ) ;
243
+ enablePowerSave ( true ) ;
213
244
}
214
245
215
246
function main ( ) {
@@ -263,7 +294,7 @@ function afterRun() {
263
294
}
264
295
265
296
//可能升级或有广告.
266
- while ( true ) {
297
+ while ( true ) {
267
298
//若退出选关,可将此值调大
268
299
sleep ( 1500 ) ;
269
300
// 截图
@@ -273,7 +304,7 @@ function afterRun() {
273
304
checkForResolution ( profile . recommendedPoints . x , profile . recommendedPoints . y , img ) . positionX ,
274
305
checkForResolution ( profile . recommendedPoints . x , profile . recommendedPoints . y , img ) . positionY ) ;
275
306
var hasFinish = colors . equals ( color , "#ffc3fc0f" ) || colors . equals ( color , "#ffff0054" ) ;
276
- if ( hasFinish ) {
307
+ if ( hasFinish ) {
277
308
break ;
278
309
} else {
279
310
robot . back ( ) ;
@@ -282,28 +313,28 @@ function afterRun() {
282
313
283
314
// 截图
284
315
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 ) {
296
327
robot . back ( ) ;
297
328
sleep ( 3000 ) ;
298
329
}
299
330
}
300
331
}
301
332
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 ;
307
338
}
308
339
309
340
function run ( ) {
0 commit comments