@bettergi/utils 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/README.md +10 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -23,13 +23,13 @@ import {
23
23
  } from "@bettergi/utils";
24
24
 
25
25
  // 在整个画面内搜索图片,找不到返回 undefined
26
- const f1 = findImage("assets/关闭.png");
26
+ const i1 = findImage("assets/关闭.png");
27
27
 
28
28
  // 在指定方向上搜索图片,找不到返回 undefined
29
- const f2 = findImageInDirection("assets/关闭.png", "north-east");
29
+ const i2 = findImageInDirection("assets/关闭.png", "north-east");
30
30
 
31
31
  // 在指定区域内搜索图片,找不到返回 undefined
32
- const f3 = findImageWithinBounds("assets/关闭.png", 960, 0, 960, 1080);
32
+ const i3 = findImageWithinBounds("assets/关闭.png", 960, 0, 960, 1080);
33
33
 
34
34
  // 在整个画面内搜索文本(不包含、忽略大小写),找不到返回 undefined
35
35
  const t1 = findText("购买", false, true);
@@ -43,39 +43,39 @@ const t3 = findTextWithinBounds("确认", false, true, 960, 540, 960, 540);
43
43
 
44
44
  ### 行为
45
45
 
46
- > 对脚本工作流中常见行为的抽象,例如:等待 XXX 完成/出现/消失。
46
+ > 对脚本开发过程中常见工作流的抽象,例如:等待 XXX 完成/出现/消失。
47
47
 
48
48
  ```ts
49
49
  import { findImageInDirection, waitUntil } from "@bettergi/utils";
50
50
 
51
51
  // 等待直到找不到[关闭按钮] 或 5秒后超时,每隔1秒检查一次,期间按 Esc 键
52
52
  const done = await waitUntil(
53
- () => findImageInDirection("assets/关闭.png", "north-east") !== undefined,
53
+ () => findImageInDirection("assets/关闭.png", "north-east") === undefined,
54
54
  5000,
55
55
  1000,
56
56
  () => keyPress("ESCAPE")
57
57
  );
58
- if (!done) throw new Error("关闭页面");
58
+ if (!done) throw new Error("关闭页面超时");
59
59
  ```
60
60
 
61
61
  ### 存储
62
62
 
63
- > 对象数据持久化,通过代理实现自动存储。可以无感知地读取/更新数据,而无需考虑如何持久化。
63
+ > 对象数据持久化,通过 Proxy 实现自动存储。从而可以无感知地读取/更新数据,而无需考虑如何持久化。
64
64
 
65
65
  ```ts
66
66
  import { useStore } from "@bettergi/utils";
67
67
 
68
68
  // 创建/读取存储对象,保存到存储文件 store/state.json 中
69
- // 通过Proxy来实现:对存储对象的操作会同步保存到存储文件
70
69
  const state = useStore<{ lastUsedTime?: number; count: number }>("state");
71
70
  if (state?.lastUsedTime) {
72
71
  log.info(`欢迎回来!上次使用时间:${state.lastUsedTime},计数器已累计至:${state.count}`);
73
72
  }
74
73
  try {
74
+ // 模拟脚本运行期间状态的变化
75
75
  for (let i = 0; i < Math.floor(Math.random() * 100); i++) {
76
- state.count = (state.count || 0) + 1; // 同步保存到文件
76
+ state.count = (state.count || 0) + 1; // 自动同步保存到文件
77
77
  }
78
78
  } finally {
79
- state.lastUsedTime = Date.now(); // 同步保存到文件
79
+ state.lastUsedTime = Date.now(); // 自动同步保存到文件
80
80
  }
81
81
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bettergi/utils",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Utils for BetterGI JavaScript Development",
5
5
  "type": "module",
6
6
  "author": "Bread Grocery<https://github.com/breadgrocery>",