|
1 | 1 | import { Region } from "./region.class";
|
2 |
| -import { isImageMatchRequest, MatchRequest } from "./match-request.class"; |
| 2 | +import { |
| 3 | + isColorMatchRequest, |
| 4 | + isImageMatchRequest, |
| 5 | + isTextMatchRequest, |
| 6 | + MatchRequest, |
| 7 | +} from "./match-request.class"; |
3 | 8 | import { ProviderRegistry } from "./provider/provider-registry.class";
|
4 |
| -import { Image } from "./image.class"; |
5 |
| -import { TextQuery } from "./query.class"; |
| 9 | +import { Point } from "./point.class"; |
| 10 | +import { PointResultFindInput, RegionResultFindInput } from "./screen.class"; |
6 | 11 |
|
7 |
| -export class MatchResult { |
| 12 | +export class MatchResult<LOCATION_TYPE> { |
8 | 13 | constructor(
|
9 | 14 | public readonly confidence: number,
|
10 |
| - public readonly location: Region, |
| 15 | + public readonly location: LOCATION_TYPE, |
11 | 16 | public readonly error?: Error
|
12 | 17 | ) {}
|
13 | 18 | }
|
14 | 19 |
|
15 | 20 | export async function getMatchResults<PROVIDER_DATA_TYPE>(
|
16 | 21 | providerRegistry: ProviderRegistry,
|
17 |
| - matchRequest: MatchRequest<TextQuery, PROVIDER_DATA_TYPE> |
18 |
| -): Promise<MatchResult[]>; |
| 22 | + matchRequest: MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE> |
| 23 | +): Promise<MatchResult<Region>[]>; |
19 | 24 | export async function getMatchResults<PROVIDER_DATA_TYPE>(
|
20 | 25 | providerRegistry: ProviderRegistry,
|
21 |
| - matchRequest: MatchRequest<Image, PROVIDER_DATA_TYPE> |
22 |
| -): Promise<MatchResult[]>; |
| 26 | + matchRequest: MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE> |
| 27 | +): Promise<MatchResult<Point>[]>; |
23 | 28 | export async function getMatchResults<PROVIDER_DATA_TYPE>(
|
24 | 29 | providerRegistry: ProviderRegistry,
|
25 | 30 | matchRequest:
|
26 |
| - | MatchRequest<Image, PROVIDER_DATA_TYPE> |
27 |
| - | MatchRequest<TextQuery, PROVIDER_DATA_TYPE> |
28 |
| -): Promise<MatchResult[]>; |
29 |
| -export async function getMatchResults<PROVIDER_DATA_TYPE>( |
30 |
| - providerRegistry: ProviderRegistry, |
31 |
| - matchRequest: |
32 |
| - | MatchRequest<Image, PROVIDER_DATA_TYPE> |
33 |
| - | MatchRequest<TextQuery, PROVIDER_DATA_TYPE> |
34 |
| -): Promise<MatchResult[]> { |
35 |
| - return isImageMatchRequest(matchRequest) |
36 |
| - ? providerRegistry.getImageFinder().findMatches(matchRequest) |
37 |
| - : providerRegistry.getTextFinder().findMatches(matchRequest); |
| 31 | + | MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE> |
| 32 | + | MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE> |
| 33 | +): Promise<MatchResult<Point | Region>[]> { |
| 34 | + if (isImageMatchRequest(matchRequest)) { |
| 35 | + return providerRegistry.getImageFinder().findMatches(matchRequest); |
| 36 | + } else if (isTextMatchRequest(matchRequest)) { |
| 37 | + return providerRegistry.getTextFinder().findMatches(matchRequest); |
| 38 | + } else if (isColorMatchRequest(matchRequest)) { |
| 39 | + return providerRegistry.getColorFinder().findMatches(matchRequest); |
| 40 | + } |
| 41 | + throw new Error( |
| 42 | + `Unknown match request type: ${JSON.stringify(matchRequest.needle)}` |
| 43 | + ); |
38 | 44 | }
|
39 | 45 |
|
40 | 46 | export async function getMatchResult<PROVIDER_DATA_TYPE>(
|
41 | 47 | providerRegistry: ProviderRegistry,
|
42 |
| - matchRequest: MatchRequest<TextQuery, PROVIDER_DATA_TYPE> |
43 |
| -): Promise<MatchResult>; |
| 48 | + matchRequest: MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE> |
| 49 | +): Promise<MatchResult<Region>>; |
44 | 50 | export async function getMatchResult<PROVIDER_DATA_TYPE>(
|
45 | 51 | providerRegistry: ProviderRegistry,
|
46 |
| - matchRequest: MatchRequest<Image, PROVIDER_DATA_TYPE> |
47 |
| -): Promise<MatchResult>; |
48 |
| -export async function getMatchResult<PROVIDER_DATA_TYPE>( |
49 |
| - providerRegistry: ProviderRegistry, |
50 |
| - matchRequest: |
51 |
| - | MatchRequest<Image, PROVIDER_DATA_TYPE> |
52 |
| - | MatchRequest<TextQuery, PROVIDER_DATA_TYPE> |
53 |
| -): Promise<MatchResult>; |
| 52 | + matchRequest: MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE> |
| 53 | +): Promise<MatchResult<Point>>; |
54 | 54 | export async function getMatchResult<PROVIDER_DATA_TYPE>(
|
55 | 55 | providerRegistry: ProviderRegistry,
|
56 | 56 | matchRequest:
|
57 |
| - | MatchRequest<Image, PROVIDER_DATA_TYPE> |
58 |
| - | MatchRequest<TextQuery, PROVIDER_DATA_TYPE> |
59 |
| -): Promise<MatchResult> { |
60 |
| - return isImageMatchRequest(matchRequest) |
61 |
| - ? providerRegistry.getImageFinder().findMatch(matchRequest) |
62 |
| - : providerRegistry.getTextFinder().findMatch(matchRequest); |
| 57 | + | MatchRequest<RegionResultFindInput, PROVIDER_DATA_TYPE> |
| 58 | + | MatchRequest<PointResultFindInput, PROVIDER_DATA_TYPE> |
| 59 | +): Promise<MatchResult<Point | Region>> { |
| 60 | + if (isImageMatchRequest(matchRequest)) { |
| 61 | + return providerRegistry.getImageFinder().findMatch(matchRequest); |
| 62 | + } else if (isTextMatchRequest(matchRequest)) { |
| 63 | + return providerRegistry.getTextFinder().findMatch(matchRequest); |
| 64 | + } else if (isColorMatchRequest(matchRequest)) { |
| 65 | + return providerRegistry.getColorFinder().findMatch(matchRequest); |
| 66 | + } |
| 67 | + throw new Error("Unknown match request type"); |
63 | 68 | }
|
0 commit comments