@bettergi/utils 0.1.5 → 0.1.7
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 +8 -0
- package/dist/game.js +3 -2
- package/dist/misc.d.ts +6 -0
- package/dist/misc.js +15 -0
- package/dist/store.d.ts +6 -0
- package/dist/store.js +11 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -35,6 +35,11 @@ await setTimeTo(12, 35);
|
|
|
35
35
|
|
|
36
36
|
// 调整游戏时间段
|
|
37
37
|
await setTime("evening");
|
|
38
|
+
|
|
39
|
+
// tab 翻页到指定页面
|
|
40
|
+
await navigateToTab(() => {
|
|
41
|
+
return findTextWithinBounds("小道具", 0, 0, 220, 96) !== undefined;
|
|
42
|
+
});
|
|
38
43
|
```
|
|
39
44
|
|
|
40
45
|
### 图文识别
|
|
@@ -178,4 +183,7 @@ const uuid = generateUUID(false);
|
|
|
178
183
|
// 数组洗牌
|
|
179
184
|
const arr = [1, 2, 3, 4, 5];
|
|
180
185
|
const shuffled = shuffleArray(arr);
|
|
186
|
+
|
|
187
|
+
// 深度合并多个对象:{ x: 1, y: { a: 2, b: 4, c: 5 }, d: 6 }
|
|
188
|
+
const result = deepMerge({ x: 1, y: { a: 2, b: 3 } }, { y: { b: 4, c: 5 }, d: 6 });
|
|
181
189
|
```
|
package/dist/game.js
CHANGED
|
@@ -92,13 +92,14 @@ 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 =
|
|
95
|
+
const { centerX = 1440, centerY = 502, offsetHours = 6, radius = 150, smooth = 4 } = options || {};
|
|
96
96
|
const radian = ((((hour + offsetHours) * 60 + minute) % 1440) / 1440) * Math.PI * 2;
|
|
97
|
+
const trackRadius = radius + 150; // 增加拨动半径,提高准确度
|
|
97
98
|
const waypoints = [{ x: centerX, y: centerY }].concat(Array.from({ length: Math.max(smooth, 3) })
|
|
98
99
|
// 计算弧度
|
|
99
100
|
.map((_, i) => radian + (1 + i / (Math.max(smooth, 3) - 1)) * Math.PI)
|
|
100
101
|
// 计算相对圆点坐标
|
|
101
|
-
.map(rad => ({ x:
|
|
102
|
+
.map(rad => ({ x: trackRadius * Math.cos(rad), y: trackRadius * Math.sin(rad) }))
|
|
102
103
|
// 计算绝对坐标
|
|
103
104
|
.map(p => ({ x: Math.round(p.x + centerX), y: Math.round(p.y + centerY) })));
|
|
104
105
|
// 3.调整时间
|
package/dist/misc.d.ts
CHANGED
|
@@ -9,3 +9,9 @@ export declare const generateUUID: (withDashes?: boolean) => string;
|
|
|
9
9
|
* @returns 洗牌后的新数组
|
|
10
10
|
*/
|
|
11
11
|
export declare const shuffleArray: <T>(array: T[]) => T[];
|
|
12
|
+
/**
|
|
13
|
+
* 深度合并多个对象
|
|
14
|
+
* @param objects 多个对象
|
|
15
|
+
* @returns 合并后的对象副本
|
|
16
|
+
*/
|
|
17
|
+
export declare const deepMerge: (...objects: any[]) => any;
|
package/dist/misc.js
CHANGED
|
@@ -24,3 +24,18 @@ export const shuffleArray = (array) => {
|
|
|
24
24
|
}
|
|
25
25
|
return shuffled;
|
|
26
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* 深度合并多个对象
|
|
29
|
+
* @param objects 多个对象
|
|
30
|
+
* @returns 合并后的对象副本
|
|
31
|
+
*/
|
|
32
|
+
export const deepMerge = (...objects) => {
|
|
33
|
+
const isPlainObject = (input) => input?.constructor === Object;
|
|
34
|
+
return objects.reduce((result, obj) => {
|
|
35
|
+
return Object.entries(obj).reduce((acc, [key, value]) => {
|
|
36
|
+
const recursive = isPlainObject(acc[key]) && isPlainObject(value);
|
|
37
|
+
acc[key] = recursive ? deepMerge(acc[key], value) : value;
|
|
38
|
+
return acc;
|
|
39
|
+
}, result);
|
|
40
|
+
}, {});
|
|
41
|
+
};
|
package/dist/store.d.ts
CHANGED
|
@@ -5,3 +5,9 @@
|
|
|
5
5
|
* @param name 存储对象的名称,将作为文件名(不包扩展名)
|
|
6
6
|
*/
|
|
7
7
|
export declare const useStore: <T extends Record<string, any>>(name: string) => T;
|
|
8
|
+
/**
|
|
9
|
+
* 创建一个带有默认值的持久化存储对象,用于管理应用状态数据
|
|
10
|
+
* @param name 存储对象的名称,将作为文件名(不包扩展名)
|
|
11
|
+
* @param defaults 默认值数据对象
|
|
12
|
+
*/
|
|
13
|
+
export declare const useStoreWithDefaults: <T extends Record<string, any>>(name: string, defaults: Partial<T>) => T;
|
package/dist/store.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deepMerge } from "./misc";
|
|
1
2
|
/**
|
|
2
3
|
* 创建一个持久化存储对象,用于管理应用状态数据
|
|
3
4
|
* 该函数会创建一个代理对象,对该对象的所有属性的修改都会自动同步到相应的JSON文件(脚本的 `store` 目录下)中。
|
|
@@ -50,3 +51,13 @@ export const useStore = (name) => {
|
|
|
50
51
|
};
|
|
51
52
|
return createProxy(obj);
|
|
52
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* 创建一个带有默认值的持久化存储对象,用于管理应用状态数据
|
|
56
|
+
* @param name 存储对象的名称,将作为文件名(不包扩展名)
|
|
57
|
+
* @param defaults 默认值数据对象
|
|
58
|
+
*/
|
|
59
|
+
export const useStoreWithDefaults = (name, defaults) => {
|
|
60
|
+
const store = useStore(name);
|
|
61
|
+
Object.assign(store, deepMerge(defaults, store));
|
|
62
|
+
return store;
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettergi/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "开发 BetterGI 脚本常用工具集",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bread Grocery<https://github.com/breadgrocery>",
|
|
@@ -30,10 +30,11 @@
|
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
32
|
"dev": "tsc --watch",
|
|
33
|
-
"build": "tsc"
|
|
33
|
+
"build": "rimraf dist && tsc"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@bettergi/types": "^0.1.3",
|
|
37
|
+
"rimraf": "^6.0.1",
|
|
37
38
|
"typescript": "^5.9.3"
|
|
38
39
|
}
|
|
39
40
|
}
|