1
1
import { join , normalize } from "path" ;
2
- import { NativeAdapter } from "./adapter/native.adapter.class " ;
2
+ import { cwd } from "process " ;
3
3
import { VisionAdapter } from "./adapter/vision.adapter.class" ;
4
+ import { FileType } from "./file-type.enum" ;
5
+ import { generateOutputPath } from "./generate-output-path.function" ;
4
6
import { LocationParameters } from "./locationparameters.class" ;
5
7
import { MatchRequest } from "./match-request.class" ;
6
8
import { Region } from "./region.class" ;
@@ -11,14 +13,15 @@ export class Screen {
11
13
resourceDirectory : "./" ,
12
14
} ;
13
15
14
- constructor ( private vision : VisionAdapter , private native : NativeAdapter ) { }
16
+ constructor ( private vision : VisionAdapter ) {
17
+ }
15
18
16
19
public width ( ) {
17
- return this . native . screenWidth ( ) ;
20
+ return this . vision . screenWidth ( ) ;
18
21
}
19
22
20
23
public height ( ) {
21
- return this . native . screenHeight ( ) ;
24
+ return this . vision . screenHeight ( ) ;
22
25
}
23
26
24
27
public async findOnScreen (
@@ -27,12 +30,12 @@ export class Screen {
27
30
) : Promise < Region > {
28
31
const minMatch = ( params && params . confidence ) || this . config . confidence ;
29
32
const searchRegion =
30
- ( params && params . searchRegion ) || await this . native . screenSize ( ) ;
33
+ ( params && params . searchRegion ) || await this . vision . screenSize ( ) ;
31
34
32
35
const fullPathToNeedle = normalize ( join ( this . config . resourceDirectory , pathToNeedle ) ) ;
33
- console . log ( `Full path to needle: ${ fullPathToNeedle } ` ) ;
36
+ // console.log(`Full path to needle: ${fullPathToNeedle}`);
34
37
35
- const screenImage = await this . native . grabScreen ( ) ;
38
+ const screenImage = await this . vision . grabScreen ( ) ;
36
39
37
40
const matchRequest = new MatchRequest (
38
41
screenImage ,
@@ -50,9 +53,27 @@ export class Screen {
50
53
reject (
51
54
`No match for ${ pathToNeedle } . Required: ${ minMatch } , given: ${
52
55
matchResult . confidence
53
- } `,
56
+ } `,
54
57
) ;
55
58
}
56
59
} ) ;
57
60
}
61
+
62
+ public async capture (
63
+ fileName : string ,
64
+ fileFormat : FileType = FileType . PNG ,
65
+ filePath : string = cwd ( ) ,
66
+ fileNamePrefix : string = "" ,
67
+ fileNamePostfix : string = "" ) : Promise < string > {
68
+ const outputPath = generateOutputPath ( fileName , {
69
+ path : filePath ,
70
+ postfix : fileNamePostfix ,
71
+ prefix : fileNamePrefix ,
72
+ type : fileFormat ,
73
+ } ) ;
74
+
75
+ const currentScreen = await this . vision . grabScreen ( ) ;
76
+ this . vision . saveImage ( currentScreen , outputPath ) ;
77
+ return outputPath ;
78
+ }
58
79
}
0 commit comments