@bettergi/utils 0.0.10 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -42
- package/dist/asserts.d.ts +57 -0
- package/dist/asserts.js +91 -0
- package/dist/flow.d.ts +20 -0
- package/dist/flow.js +33 -1
- package/dist/game.d.ts +35 -22
- package/dist/game.js +92 -64
- package/dist/http.js +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/mouse.d.ts +48 -22
- package/dist/mouse.js +78 -38
- package/dist/ocr.d.ts +44 -34
- package/dist/ocr.js +40 -43
- package/dist/store.d.ts +1 -0
- package/dist/store.js +38 -6
- package/dist/workflow.d.ts +52 -0
- package/dist/workflow.js +72 -0
- package/package.json +3 -3
package/dist/workflow.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** 默认最大重试次数 */
|
|
2
|
+
const defaultMaxAttempts = 5;
|
|
3
|
+
/** 默认重试间隔(毫秒) */
|
|
4
|
+
const defaultRetryInterval = 1000;
|
|
5
|
+
/**
|
|
6
|
+
* 等待直到条件满足或超时,期间执行重试操作
|
|
7
|
+
* @param condition 返回条件是否满足的函数
|
|
8
|
+
* @param retryAction 每次重试时执行的操作(可选)
|
|
9
|
+
* @param options 配置选项
|
|
10
|
+
* @returns - true 条件满足
|
|
11
|
+
* - false 达到最大重试次数
|
|
12
|
+
*/
|
|
13
|
+
export const waitForAction = async (condition, retryAction, options) => {
|
|
14
|
+
const { maxAttempts = defaultMaxAttempts, retryInterval = defaultRetryInterval } = options || {};
|
|
15
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
16
|
+
if (condition())
|
|
17
|
+
return true;
|
|
18
|
+
await retryAction?.();
|
|
19
|
+
await sleep(retryInterval);
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* 等待某个区域出现,期间执行重试操作
|
|
25
|
+
* @param regionProvider 返回区域的函数
|
|
26
|
+
* @param retryAction 每次重试时执行的操作(可选)
|
|
27
|
+
* @param options 配置选项
|
|
28
|
+
* @returns - true 区域出现
|
|
29
|
+
* - false 达到最大重试次数
|
|
30
|
+
*/
|
|
31
|
+
export const waitForRegionAppear = async (regionProvider, retryAction, options) => {
|
|
32
|
+
return waitForAction(() => {
|
|
33
|
+
const region = regionProvider();
|
|
34
|
+
return region != null && region.isExist();
|
|
35
|
+
}, retryAction, options);
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* 等待某个区域消失,期间执行重试操作
|
|
39
|
+
* @param regionProvider 返回区域的函数
|
|
40
|
+
* @param retryAction 每次重试时执行的操作(可选)
|
|
41
|
+
* @param options 配置选项
|
|
42
|
+
* @returns - true 区域消失
|
|
43
|
+
* - false 达到最大重试次数
|
|
44
|
+
*/
|
|
45
|
+
export const waitForRegionDisappear = async (regionProvider, retryAction, options) => {
|
|
46
|
+
return waitForAction(() => {
|
|
47
|
+
const region = regionProvider();
|
|
48
|
+
return !region || !region.isExist();
|
|
49
|
+
}, retryAction, options);
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 等待整个画面上某个元素出现,期间执行重试操作
|
|
53
|
+
* @param recognitionObject 识别对象
|
|
54
|
+
* @param retryAction 每次重试时执行的操作(可选)
|
|
55
|
+
* @param options 配置选项
|
|
56
|
+
* @returns - true 整个画面上某个元素出现
|
|
57
|
+
* - false 达到最大重试次数
|
|
58
|
+
*/
|
|
59
|
+
export const waitForElementAppear = async (recognitionObject, retryAction, options) => {
|
|
60
|
+
return waitForRegionAppear(() => captureGameRegion().find(recognitionObject), retryAction, options);
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* 等待整个画面上某个元素消失,期间执行重试操作
|
|
64
|
+
* @param recognitionObject 识别对象
|
|
65
|
+
* @param retryAction 每次重试时执行的操作(可选)
|
|
66
|
+
* @param options 配置选项
|
|
67
|
+
* @returns - true 整个画面上某个元素消失
|
|
68
|
+
* - false 达到最大重试次数
|
|
69
|
+
*/
|
|
70
|
+
export const waitForElementDisappear = async (recognitionObject, retryAction, options) => {
|
|
71
|
+
return waitForRegionDisappear(() => captureGameRegion().find(recognitionObject), retryAction, options);
|
|
72
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettergi/utils",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "开发 BetterGI 脚本常用工具集",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bread Grocery<https://github.com/breadgrocery>",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"build": "tsc"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@bettergi/types": "^0.
|
|
37
|
-
"typescript": "5.
|
|
36
|
+
"@bettergi/types": "^0.1.1",
|
|
37
|
+
"typescript": "^5.9.3"
|
|
38
38
|
}
|
|
39
39
|
}
|