@bettergi/utils 0.1.16 → 0.1.18
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 +2 -2
- package/dist/game.d.ts +2 -0
- package/dist/game.js +3 -2
- package/dist/ocr.js +12 -10
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -103,7 +103,7 @@ await assertRegionDisappearing(findButton, "点击购买按钮超时", () => fin
|
|
|
103
103
|
|
|
104
104
|
```ts
|
|
105
105
|
// 鼠标从 (745, 610) 平滑自然地移动 (1920, 1080)
|
|
106
|
-
await naturalMouseMove(
|
|
106
|
+
await naturalMouseMove(745, 610, 1920, 1080);
|
|
107
107
|
|
|
108
108
|
// 鼠标从 (745, 610) 拖拽到 (1280, 610)
|
|
109
109
|
await mouseDrag(745, 610, 1280, 610);
|
|
@@ -129,7 +129,7 @@ await mouseScrollDownLines(1, 115);
|
|
|
129
129
|
// 创建/读取存储对象,保存到存储文件 store/my-data.json 中
|
|
130
130
|
const store = useStore<{ lastUsedTime?: number; count: number }>("my-data");
|
|
131
131
|
// 默认值版本
|
|
132
|
-
// const
|
|
132
|
+
// const store = useStoreWithDefaults("my-data", { lastUsedTime: 0, count: 0 });
|
|
133
133
|
|
|
134
134
|
if (store?.lastUsedTime) {
|
|
135
135
|
log.info(`欢迎回来!上次使用时间: ${store.lastUsedTime},计数器已累计至: ${store.count}`);
|
package/dist/game.d.ts
CHANGED
package/dist/game.js
CHANGED
|
@@ -92,12 +92,13 @@ export const setTimeTo = async (hour, minute, options) => {
|
|
|
92
92
|
// 1.打开时间页面
|
|
93
93
|
await openMenu("时间", true);
|
|
94
94
|
// 2.计算调整时钟的路径点
|
|
95
|
-
const { centerX = 1440, centerY = 502, offsetHours = 6, radius = 150, smooth = 4 } = options || {};
|
|
95
|
+
const { centerX = 1440, centerY = 502, offsetHours = 6, radius = 150, smooth = 4, tolerance = 2 } = options || {};
|
|
96
96
|
const radian = ((((hour + offsetHours) * 60 + minute) % 1440) / 1440) * Math.PI * 2;
|
|
97
97
|
const trackRadius = radius + 150; // 增加拨动半径,提高准确度
|
|
98
|
+
const toleranceRadian = (tolerance / (60 * 24)) * Math.PI * 2; // 容差弧度
|
|
98
99
|
const waypoints = [{ x: centerX, y: centerY }].concat(Array.from({ length: Math.max(smooth, 3) })
|
|
99
100
|
// 计算弧度
|
|
100
|
-
.map((_, i) => radian + (1 + i / (Math.max(smooth, 3) - 1)) * Math.PI)
|
|
101
|
+
.map((_, i) => radian + (1 + i / (Math.max(smooth, 3) - 1)) * Math.PI + toleranceRadian)
|
|
101
102
|
// 计算相对圆点坐标
|
|
102
103
|
.map(rad => ({ x: trackRadius * Math.cos(rad), y: trackRadius * Math.sin(rad) }))
|
|
103
104
|
// 计算绝对坐标
|
package/dist/ocr.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import { mouseScrollDownLines } from "./mouse";
|
|
2
2
|
import { waitForAction } from "./workflow";
|
|
3
|
-
const findFirst = (ir, ro, predicate) => {
|
|
4
|
-
const candidates = ir.findMulti(ro);
|
|
5
|
-
for (let i = 0; i < candidates.count; i++) {
|
|
6
|
-
if (predicate(candidates[i]))
|
|
7
|
-
return candidates[i];
|
|
8
|
-
}
|
|
9
|
-
return undefined;
|
|
10
|
-
};
|
|
11
3
|
const directionToBounds = (direction) => {
|
|
12
4
|
const x = direction.includes("east") ? genshin.width / 2 : 0;
|
|
13
5
|
const y = direction.includes("south") ? genshin.height / 2 : 0;
|
|
@@ -35,7 +27,8 @@ export const findImage = (image, config = {}) => {
|
|
|
35
27
|
if (Object.keys(config).length > 0) {
|
|
36
28
|
Object.assign(ro, config) && ro.initTemplate();
|
|
37
29
|
}
|
|
38
|
-
|
|
30
|
+
const region = ir.find(ro);
|
|
31
|
+
return region.isExist() ? region : undefined;
|
|
39
32
|
}
|
|
40
33
|
catch (err) {
|
|
41
34
|
log.warn(`${err.message || err}`);
|
|
@@ -62,7 +55,8 @@ export const findImageWithinBounds = (image, x, y, w, h, config = {}) => {
|
|
|
62
55
|
if (Object.keys(config).length > 0) {
|
|
63
56
|
Object.assign(ro, config) && ro.initTemplate();
|
|
64
57
|
}
|
|
65
|
-
|
|
58
|
+
const region = ir.find(ro);
|
|
59
|
+
return region.isExist() ? region : undefined;
|
|
66
60
|
}
|
|
67
61
|
catch (err) {
|
|
68
62
|
log.warn(`${err.message || err}`);
|
|
@@ -95,6 +89,14 @@ export const findImageInDirection = (image, direction, config = {}) => {
|
|
|
95
89
|
const { x, y, w, h } = directionToBounds(direction);
|
|
96
90
|
return findImageWithinBounds(image, x, y, w, h, config);
|
|
97
91
|
};
|
|
92
|
+
const findFirst = (ir, ro, predicate) => {
|
|
93
|
+
const candidates = ir.findMulti(ro);
|
|
94
|
+
for (let i = 0; i < candidates.count; i++) {
|
|
95
|
+
if (predicate(candidates[i]))
|
|
96
|
+
return candidates[i];
|
|
97
|
+
}
|
|
98
|
+
return undefined;
|
|
99
|
+
};
|
|
98
100
|
/**
|
|
99
101
|
* 在整个画面内搜索文本
|
|
100
102
|
* @param text 待搜索文本
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettergi/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "开发 BetterGI 脚本常用工具集",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bread Grocery<https://github.com/breadgrocery>",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"build": "rimraf dist && tsc"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@bettergi/types": "
|
|
36
|
+
"@bettergi/types": "workspace:latest",
|
|
37
37
|
"rimraf": "^6.1.0",
|
|
38
38
|
"typescript": "^5.9.3"
|
|
39
39
|
}
|