vscode-behavior3 2.5.1 → 2.6.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 +147 -50
- package/README.zh-CN.md +317 -0
- package/dist/build-cli.js +887 -30
- package/dist/extension.js +1483 -1087
- package/dist/webview/assets/editor-DQTG2Z7M.js +8 -0
- package/dist/webview/index.html +1 -1
- package/dist/webview/locales/en.json +13 -0
- package/dist/webview/locales/zh.json +13 -0
- package/package.json +1 -1
- package/webview/shared/b3build-model.d.ts +2 -0
- package/webview/shared/b3type.ts +1 -0
- package/dist/webview/assets/editor-BPxOdZMY.js +0 -8
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# Behavior3 Editor
|
|
2
2
|
|
|
3
|
-
VS Code custom editor for Behavior3 JSON behavior trees. It combines a
|
|
3
|
+
VS Code custom editor and build toolchain for Behavior3 JSON behavior trees. It combines a graph canvas, a dedicated Inspector, project scaffolding, and build/batch/check scripting for game AI workflows.
|
|
4
|
+
|
|
5
|
+
Chinese guide: [README.zh-CN.md](README.zh-CN.md)
|
|
4
6
|
|
|
5
7
|
## Related Projects
|
|
6
8
|
|
|
@@ -11,24 +13,20 @@ VS Code custom editor for Behavior3 JSON behavior trees. It combines a visual gr
|
|
|
11
13
|
|
|
12
14
|

|
|
13
15
|
|
|
14
|
-
##
|
|
16
|
+
## Highlights
|
|
15
17
|
|
|
16
18
|
- Visual graph editor for Behavior3 trees and reachable subtrees
|
|
17
|
-
- Inspector in `sidebar` or `embedded` mode
|
|
19
|
+
- Dedicated Inspector in `sidebar` or `embedded` mode, with optional raw node JSON view
|
|
18
20
|
- Explorer `Behavior3` submenu for project, tree, and script scaffolding
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
21
|
+
- Project build, debug build, checker hooks, visibility hooks, and batch processing
|
|
22
|
+
- Auto-open for likely behavior-tree JSON files when a matching `*.b3-setting` is available
|
|
23
|
+
- Custom node definitions via `*.b3-setting`
|
|
24
|
+
- Workspace-driven validation, script loading, and node color overrides via `*.b3-workspace`
|
|
22
25
|
- Theme-aware UI for dark and light VS Code themes
|
|
23
26
|
|
|
24
27
|
## Quick Start
|
|
25
28
|
|
|
26
|
-
###
|
|
27
|
-
|
|
28
|
-
- Right-click a Behavior3 `.json` file in Explorer
|
|
29
|
-
- Select **Open With** -> **Behavior3 Editor**
|
|
30
|
-
|
|
31
|
-
### Create project files
|
|
29
|
+
### 1. Create or open a project
|
|
32
30
|
|
|
33
31
|
From a folder's Explorer `Behavior3` submenu you can run:
|
|
34
32
|
|
|
@@ -39,44 +37,101 @@ From a folder's Explorer `Behavior3` submenu you can run:
|
|
|
39
37
|
- **Create Checker Script**
|
|
40
38
|
- **Run Script as Batch Process**
|
|
41
39
|
|
|
42
|
-
`
|
|
40
|
+
`Create Project` scaffolds a minimal starter project with:
|
|
41
|
+
|
|
42
|
+
- `node-config.b3-setting`
|
|
43
|
+
- `workspace.b3-workspace`
|
|
44
|
+
- `example.json`
|
|
45
|
+
|
|
46
|
+
You can also open an existing workspace that already contains `*.json` trees, a `*.b3-setting` node-definition file, and optionally a `*.b3-workspace` file.
|
|
47
|
+
|
|
48
|
+
### 2. Open and switch editors
|
|
49
|
+
|
|
50
|
+
- Right-click a tree `.json` file in Explorer and select **Open With** -> **Behavior3 Editor**
|
|
51
|
+
- Or use **Open with Behavior3** from the Explorer `Behavior3` submenu on a `.json` file
|
|
52
|
+
- Press `F4` to toggle between the text editor and the Behavior3 editor for the current tree file
|
|
53
|
+
|
|
54
|
+
If a JSON file looks like a behavior tree and a parent `*.b3-setting` exists, Behavior3 can auto-open it in preview mode. Plain JSON files continue to open in the default text editor.
|
|
55
|
+
|
|
56
|
+
### 3. Inspect and edit
|
|
57
|
+
|
|
58
|
+
- Use the **Behavior3** activity bar view for the dedicated Inspector in `sidebar` mode
|
|
59
|
+
- Or set `behavior3.inspectorMode` to `embedded` to show the Inspector inside the editor webview
|
|
60
|
+
- Use **Toggle Node JSON** to switch between form-based Inspector editing and raw node JSON
|
|
61
|
+
|
|
62
|
+
### 4. Build or batch process
|
|
63
|
+
|
|
64
|
+
- Click **Build Behavior Tree** in the editor title bar, or press `Ctrl/Cmd+B`
|
|
65
|
+
- Press `Ctrl/Cmd+Shift+B` to start **Debug Build Behavior Tree**
|
|
66
|
+
- Use **Run Script as Batch Process** on a folder to pick a script, or run it directly from a `.ts`, `.mts`, `.js`, or `.mjs` file
|
|
67
|
+
|
|
68
|
+
## Typical Project Layout
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
my-project/
|
|
72
|
+
node-config.b3-setting
|
|
73
|
+
workspace.b3-workspace
|
|
74
|
+
example.json
|
|
75
|
+
scripts/
|
|
76
|
+
build.ts
|
|
77
|
+
batch.ts
|
|
78
|
+
checkers/
|
|
79
|
+
checker_and_visible.ts
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Behavior3 discovers `*.b3-workspace` and `*.b3-setting` by walking upward from the active tree or script context.
|
|
43
83
|
|
|
44
|
-
|
|
84
|
+
## Configure Node Definitions
|
|
45
85
|
|
|
46
|
-
Create a
|
|
86
|
+
Create a `*.b3-setting` file in the workspace:
|
|
47
87
|
|
|
48
88
|
```json
|
|
49
89
|
[
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
90
|
+
{
|
|
91
|
+
"name": "MyAction",
|
|
92
|
+
"type": "Action",
|
|
93
|
+
"desc": "Does something useful",
|
|
94
|
+
"args": [{ "name": "duration", "type": "float", "desc": "Duration in seconds" }]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "CheckScore",
|
|
98
|
+
"type": "Condition",
|
|
99
|
+
"desc": "Checks whether the score matches the rule",
|
|
100
|
+
"args": [{ "name": "value", "type": "expr", "desc": "Expression" }]
|
|
101
|
+
}
|
|
62
102
|
]
|
|
63
103
|
```
|
|
64
104
|
|
|
65
|
-
|
|
105
|
+
`Create Project` seeds `node-config.b3-setting` with the built-in node definitions from the runtime.
|
|
106
|
+
|
|
107
|
+
## Configure Workspace Behavior
|
|
66
108
|
|
|
67
|
-
Use a
|
|
109
|
+
Use a `*.b3-workspace` file to control validation, script loading, and editor presentation:
|
|
68
110
|
|
|
69
111
|
```json
|
|
70
112
|
{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
113
|
+
"settings": {
|
|
114
|
+
"checkExpr": true,
|
|
115
|
+
"allowNewFunction": true,
|
|
116
|
+
"buildScript": "scripts/build.ts",
|
|
117
|
+
"checkScripts": ["scripts/checkers/**/*.ts"],
|
|
118
|
+
"nodeColors": {
|
|
119
|
+
"Action": "#0f766e",
|
|
120
|
+
"Condition": "#b45309"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
76
123
|
}
|
|
77
124
|
```
|
|
78
125
|
|
|
79
|
-
|
|
126
|
+
- `checkExpr`: enable expression validation for expression-like args
|
|
127
|
+
- `allowNewFunction`: allow inline visibility expressions that rely on `new Function`; defaults to `false`
|
|
128
|
+
- `buildScript`: load one build hook module for project builds
|
|
129
|
+
- `checkScripts`: load custom `@behavior3.check(...)` and `@behavior3.visible(...)` modules from glob matches
|
|
130
|
+
- `nodeColors`: override graph colors for `Composite`, `Decorator`, `Condition`, `Action`, `Other`, and `Error`
|
|
131
|
+
|
|
132
|
+
`buildScript` and `checkScripts` are resolved relative to the `*.b3-workspace` file. Changes to `allowNewFunction` and `nodeColors` are refreshed without reopening the editor.
|
|
133
|
+
|
|
134
|
+
See [sample/workspace.b3-workspace](sample/workspace.b3-workspace) for a complete sample.
|
|
80
135
|
|
|
81
136
|
## Inspector Modes
|
|
82
137
|
|
|
@@ -87,7 +142,7 @@ Set `behavior3.inspectorMode` to choose the active Inspector presentation:
|
|
|
87
142
|
|
|
88
143
|
Both modes share the same document semantics and commands. Only the presentation changes.
|
|
89
144
|
|
|
90
|
-
## Build, Batch, and
|
|
145
|
+
## Build, Batch, Checker, and Visibility Scripts
|
|
91
146
|
|
|
92
147
|
Behavior3 supports ESM JavaScript and TypeScript scripts:
|
|
93
148
|
|
|
@@ -97,11 +152,11 @@ Behavior3 supports ESM JavaScript and TypeScript scripts:
|
|
|
97
152
|
When importing local TypeScript helpers, use explicit extensions such as `./helper.ts`.
|
|
98
153
|
The `behavior3` decorator namespace is provided by the runtime, so script files only need type imports from `vscode-behavior3/build`.
|
|
99
154
|
|
|
100
|
-
|
|
155
|
+
Example scripts are available in:
|
|
101
156
|
|
|
102
157
|
- [sample/scripts/build.ts](sample/scripts/build.ts)
|
|
103
158
|
- [sample/scripts/batch.ts](sample/scripts/batch.ts)
|
|
104
|
-
- [sample/scripts/checkers/
|
|
159
|
+
- [sample/scripts/checkers/checker_and_visible.ts](sample/scripts/checkers/checker_and_visible.ts)
|
|
105
160
|
|
|
106
161
|
### Build Scripts
|
|
107
162
|
|
|
@@ -112,7 +167,7 @@ import type { BuildEnv, BuildScript } from "vscode-behavior3/build";
|
|
|
112
167
|
|
|
113
168
|
@behavior3.build
|
|
114
169
|
export class ProjectBuild implements BuildScript {
|
|
115
|
-
|
|
170
|
+
constructor(private readonly env: BuildEnv) {}
|
|
116
171
|
}
|
|
117
172
|
```
|
|
118
173
|
|
|
@@ -135,32 +190,43 @@ Supported hooks:
|
|
|
135
190
|
- `onWriteFile(path, tree)`
|
|
136
191
|
- `onComplete(status)`
|
|
137
192
|
|
|
138
|
-
|
|
193
|
+
By default, batch processing only writes back tree changes made by the batch script itself. Use `shouldUpgradeTree()` when you want to persist normalization or upgrade writes for a source tree.
|
|
139
194
|
|
|
140
|
-
Checker
|
|
195
|
+
### Checker and Visibility Hooks
|
|
141
196
|
|
|
142
|
-
|
|
197
|
+
- `@behavior3.check("name")` registers a custom field validator used by both Inspector validation and project builds
|
|
198
|
+
- `@behavior3.visible("name")` registers a field-visibility hook used by the Inspector and hidden-field cleanup
|
|
199
|
+
- `checkScripts` modules can register both checker hooks and visibility hooks
|
|
143
200
|
|
|
144
|
-
|
|
201
|
+
Inline visibility expressions that rely on `new Function` only run when `allowNewFunction` is enabled in `*.b3-workspace`.
|
|
145
202
|
|
|
146
|
-
|
|
147
|
-
- Press `Ctrl/Cmd+Shift+B` to start a debug build session
|
|
203
|
+
For compatibility, supported script files may still export classes through named `Hook`, `BuildHook`, `BatchHook`, or `default`, but the decorator-based APIs above are the canonical forms.
|
|
148
204
|
|
|
149
|
-
|
|
205
|
+
## Build and CLI
|
|
206
|
+
|
|
207
|
+
Behavior3 can build from the editor UI, the Inspector view, or the CLI.
|
|
208
|
+
|
|
209
|
+
- **Build Behavior Tree** chooses an output folder and remembers the last output folder per workspace
|
|
210
|
+
- **Debug Build Behavior Tree** launches the CLI under the VS Code debugger so source maps from transpiled TypeScript build scripts work
|
|
211
|
+
- CLI discovery starts from `--project` when provided, otherwise from the current working directory
|
|
212
|
+
|
|
213
|
+
Install as a dev dependency:
|
|
150
214
|
|
|
151
215
|
```bash
|
|
152
216
|
npm install -D vscode-behavior3
|
|
153
217
|
```
|
|
154
218
|
|
|
219
|
+
Use it from a package script:
|
|
220
|
+
|
|
155
221
|
```json
|
|
156
222
|
{
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
223
|
+
"scripts": {
|
|
224
|
+
"build:behavior": "behavior3-build --project ./workdir/hero.json --output ./dist/behavior3"
|
|
225
|
+
}
|
|
160
226
|
}
|
|
161
227
|
```
|
|
162
228
|
|
|
163
|
-
|
|
229
|
+
Run it directly:
|
|
164
230
|
|
|
165
231
|
```bash
|
|
166
232
|
npm exec -- behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
|
|
@@ -172,6 +238,30 @@ Or without installing first:
|
|
|
172
238
|
npx --package vscode-behavior3 behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
|
|
173
239
|
```
|
|
174
240
|
|
|
241
|
+
CLI options:
|
|
242
|
+
|
|
243
|
+
- `--output <dir>`: output directory for built JSON files
|
|
244
|
+
- `--project <path>`: tree file, project directory, or `*.b3-workspace` file to resolve from
|
|
245
|
+
- `--workspace-file <file>`: use an explicit `*.b3-workspace` file
|
|
246
|
+
- `--setting-file <file>`: use an explicit `*.b3-setting` file
|
|
247
|
+
- `--workspace-root <dir>`: limit upward discovery to a specific directory
|
|
248
|
+
- `--check-expr` / `--no-check-expr`: enable or disable expression validation
|
|
249
|
+
- `--build-script-debug`: enable sourcemapped build script debugging
|
|
250
|
+
|
|
251
|
+
## Command Surface
|
|
252
|
+
|
|
253
|
+
### Explorer `Behavior3` submenu
|
|
254
|
+
|
|
255
|
+
- On folders: **Create Project**, **Create Behavior Tree File**, **Create Build Script**, **Create Batch Script**, **Create Checker Script**, **Run Script as Batch Process**
|
|
256
|
+
- On script files: **Run Script as Batch Process**
|
|
257
|
+
- On `.json` files: **Open with Behavior3**
|
|
258
|
+
|
|
259
|
+
### Command Palette and view actions
|
|
260
|
+
|
|
261
|
+
- **Open Node Config (.b3-setting)** opens the nearest resolved node-definition file
|
|
262
|
+
- **Toggle Text / Behavior3** switches the current file between the custom editor and the text editor
|
|
263
|
+
- **Toggle Node JSON** switches the Inspector between structured fields and raw node JSON
|
|
264
|
+
|
|
175
265
|
## Extension Settings
|
|
176
266
|
|
|
177
267
|
| Setting | Type | Default | Description |
|
|
@@ -195,6 +285,7 @@ npx --package vscode-behavior3 behavior3-build --project ./workdir/hero.json --o
|
|
|
195
285
|
| `Ctrl/Cmd+F` | Search node content |
|
|
196
286
|
| `Ctrl/Cmd+G` | Jump to node by id |
|
|
197
287
|
| `Ctrl/Cmd+B` | Build |
|
|
288
|
+
| `Ctrl/Cmd+Shift+B` | Debug build |
|
|
198
289
|
| `F4` | Toggle Text / Behavior3 editor |
|
|
199
290
|
|
|
200
291
|
## Docs
|
|
@@ -206,6 +297,12 @@ npx --package vscode-behavior3 behavior3-build --project ./workdir/hero.json --o
|
|
|
206
297
|
|
|
207
298
|
## Development
|
|
208
299
|
|
|
300
|
+
- `npm run build` - production extension + webview build
|
|
301
|
+
- `npm run build:dev` - development build
|
|
302
|
+
- `npm run watch:ext` - watch extension bundle
|
|
303
|
+
- `npm run watch:webview` - watch webview bundle
|
|
304
|
+
- `npm run check` - type-check extension and webview TypeScript
|
|
305
|
+
- `npm run test:shared` - run shared test suite
|
|
209
306
|
- Output logs: **View -> Output** -> **Behavior3**
|
|
210
307
|
- Webview logs are also available in DevTools
|
|
211
308
|
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
# Behavior3 Editor 中文使用说明
|
|
2
|
+
|
|
3
|
+
Behavior3 Editor 是一个面向 Behavior3 JSON 行为树的 VS Code 自定义编辑器与构建工具链,提供图形化画布、Inspector、项目脚手架,以及 build / batch / check 脚本能力,适合游戏 AI 工作流。
|
|
4
|
+
|
|
5
|
+
英文说明见 [README.md](README.md)。
|
|
6
|
+
|
|
7
|
+
## 相关项目
|
|
8
|
+
|
|
9
|
+
- **[behavior3-ts](https://github.com/codetypess/behavior3-ts)** - TypeScript 运行时库
|
|
10
|
+
- **[behavior3lua](https://github.com/zhandouxiaojiji/behavior3lua)** - Lua 运行时库
|
|
11
|
+
|
|
12
|
+
## 预览
|
|
13
|
+
|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
## 功能概览
|
|
17
|
+
|
|
18
|
+
- 图形化编辑 Behavior3 主树与可达子树
|
|
19
|
+
- Inspector 支持 `sidebar` 与 `embedded` 两种模式,并可切换节点原始 JSON 视图
|
|
20
|
+
- Explorer 中提供 `Behavior3` 子菜单,用于创建项目、行为树与脚本脚手架
|
|
21
|
+
- 支持项目构建、调试构建、字段检查器、字段可见性钩子与批处理脚本
|
|
22
|
+
- 当 JSON 文件看起来像行为树且存在匹配的 `*.b3-setting` 时,可自动以 Behavior3 编辑器预览打开
|
|
23
|
+
- 通过 `*.b3-setting` 自定义节点定义
|
|
24
|
+
- 通过 `*.b3-workspace` 控制校验、脚本加载与节点颜色覆盖
|
|
25
|
+
- 自动适配 VS Code 深色/浅色主题
|
|
26
|
+
|
|
27
|
+
## 快速开始
|
|
28
|
+
|
|
29
|
+
### 1. 创建或打开项目
|
|
30
|
+
|
|
31
|
+
在 Explorer 中右键文件夹,打开 `Behavior3` 子菜单,可以使用以下命令:
|
|
32
|
+
|
|
33
|
+
- **Create Project**
|
|
34
|
+
- **Create Behavior Tree File**
|
|
35
|
+
- **Create Build Script**
|
|
36
|
+
- **Create Batch Script**
|
|
37
|
+
- **Create Checker Script**
|
|
38
|
+
- **Run Script as Batch Process**
|
|
39
|
+
|
|
40
|
+
`Create Project` 会生成一套最小可运行项目骨架:
|
|
41
|
+
|
|
42
|
+
- `node-config.b3-setting`
|
|
43
|
+
- `workspace.b3-workspace`
|
|
44
|
+
- `example.json`
|
|
45
|
+
|
|
46
|
+
你也可以直接打开一个已有项目目录,只要其中包含行为树 `*.json`、节点定义 `*.b3-setting`,并可选包含 `*.b3-workspace`。
|
|
47
|
+
|
|
48
|
+
### 2. 打开与切换编辑器
|
|
49
|
+
|
|
50
|
+
- 在 Explorer 中右键行为树 `.json` 文件,选择 **Open With** -> **Behavior3 Editor**
|
|
51
|
+
- 或在该 `.json` 文件的 `Behavior3` 子菜单中执行 **Open with Behavior3**
|
|
52
|
+
- 按 `F4` 可在文本编辑器与 Behavior3 编辑器之间切换当前树文件
|
|
53
|
+
|
|
54
|
+
如果某个 JSON 文件具备行为树结构,且它的父目录或上级目录中能解析到 `*.b3-setting`,扩展会自动以预览模式打开该文件;普通 JSON 文件仍会继续使用默认文本编辑器打开。
|
|
55
|
+
|
|
56
|
+
### 3. 使用 Inspector 编辑
|
|
57
|
+
|
|
58
|
+
- 使用活动栏中的 **Behavior3** 视图,在 `sidebar` 模式下查看独立 Inspector
|
|
59
|
+
- 或将 `behavior3.inspectorMode` 设置为 `embedded`,把 Inspector 嵌入编辑器 webview 中
|
|
60
|
+
- 使用 **Toggle Node JSON** 在表单式编辑与节点原始 JSON 之间切换
|
|
61
|
+
|
|
62
|
+
### 4. 构建或批处理
|
|
63
|
+
|
|
64
|
+
- 点击编辑器标题栏中的 **Build Behavior Tree**,或按 `Ctrl/Cmd+B`
|
|
65
|
+
- 按 `Ctrl/Cmd+Shift+B` 启动 **Debug Build Behavior Tree**
|
|
66
|
+
- 在文件夹上使用 **Run Script as Batch Process** 时会先选择脚本;直接在 `.ts`、`.mts`、`.js`、`.mjs` 文件上执行时会直接运行该脚本
|
|
67
|
+
|
|
68
|
+
## 典型项目结构
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
my-project/
|
|
72
|
+
node-config.b3-setting
|
|
73
|
+
workspace.b3-workspace
|
|
74
|
+
example.json
|
|
75
|
+
scripts/
|
|
76
|
+
build.ts
|
|
77
|
+
batch.ts
|
|
78
|
+
checkers/
|
|
79
|
+
checker_and_visible.ts
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Behavior3 会从当前激活的行为树或脚本上下文出发,向上查找 `*.b3-workspace` 与 `*.b3-setting`。
|
|
83
|
+
|
|
84
|
+
## 配置节点定义
|
|
85
|
+
|
|
86
|
+
在工作区中创建一个 `*.b3-setting` 文件:
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
[
|
|
90
|
+
{
|
|
91
|
+
"name": "MyAction",
|
|
92
|
+
"type": "Action",
|
|
93
|
+
"desc": "执行一个动作",
|
|
94
|
+
"args": [{ "name": "duration", "type": "float", "desc": "持续时间(秒)" }]
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"name": "CheckScore",
|
|
98
|
+
"type": "Condition",
|
|
99
|
+
"desc": "判断分数是否符合规则",
|
|
100
|
+
"args": [{ "name": "value", "type": "expr", "desc": "表达式" }]
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
如果使用 `Create Project`,生成的 `node-config.b3-setting` 会自动带上运行时内置节点定义。
|
|
106
|
+
|
|
107
|
+
## 配置工作区行为
|
|
108
|
+
|
|
109
|
+
通过 `*.b3-workspace` 控制校验、脚本加载与编辑器表现:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"settings": {
|
|
114
|
+
"checkExpr": true,
|
|
115
|
+
"allowNewFunction": true,
|
|
116
|
+
"buildScript": "scripts/build.ts",
|
|
117
|
+
"checkScripts": ["scripts/checkers/**/*.ts"],
|
|
118
|
+
"nodeColors": {
|
|
119
|
+
"Action": "#0f766e",
|
|
120
|
+
"Condition": "#b45309"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- `checkExpr`:开启表达式参数校验
|
|
127
|
+
- `allowNewFunction`:允许执行依赖 `new Function` 的内联可见性表达式;默认值为 `false`
|
|
128
|
+
- `buildScript`:指定项目 build hook 模块
|
|
129
|
+
- `checkScripts`:加载匹配到的自定义 `@behavior3.check(...)` 与 `@behavior3.visible(...)` 模块
|
|
130
|
+
- `nodeColors`:覆盖图中 `Composite`、`Decorator`、`Condition`、`Action`、`Other`、`Error` 节点颜色
|
|
131
|
+
|
|
132
|
+
`buildScript` 和 `checkScripts` 都是相对 `*.b3-workspace` 文件所在目录解析的。修改 `allowNewFunction` 与 `nodeColors` 后,无需重开编辑器即可刷新生效。
|
|
133
|
+
|
|
134
|
+
完整示例可参考 [sample/workspace.b3-workspace](sample/workspace.b3-workspace)。
|
|
135
|
+
|
|
136
|
+
## Inspector 模式
|
|
137
|
+
|
|
138
|
+
通过 `behavior3.inspectorMode` 控制 Inspector 呈现方式:
|
|
139
|
+
|
|
140
|
+
- `sidebar`:在独立的 Behavior3 侧边视图中显示 Inspector
|
|
141
|
+
- `embedded`:在主编辑器 webview 中显示 Inspector
|
|
142
|
+
|
|
143
|
+
两种模式共用同一套文档语义与命令,差别只在界面位置。
|
|
144
|
+
|
|
145
|
+
## Build / Batch / Check / Visible 脚本
|
|
146
|
+
|
|
147
|
+
Behavior3 支持 ESM JavaScript 与 TypeScript 脚本:
|
|
148
|
+
|
|
149
|
+
- JavaScript:`.js`、`.mjs`
|
|
150
|
+
- TypeScript:`.ts`、`.mts`(运行时转译,不做类型检查)
|
|
151
|
+
|
|
152
|
+
如果脚本里导入本地 TypeScript 辅助文件,请使用显式扩展名,例如 `./helper.ts`。
|
|
153
|
+
运行时会自动注入 `behavior3` 装饰器命名空间,因此脚本只需要从 `vscode-behavior3/build` 导入类型。
|
|
154
|
+
|
|
155
|
+
示例脚本可参考:
|
|
156
|
+
|
|
157
|
+
- [sample/scripts/build.ts](sample/scripts/build.ts)
|
|
158
|
+
- [sample/scripts/batch.ts](sample/scripts/batch.ts)
|
|
159
|
+
- [sample/scripts/checkers/checker_and_visible.ts](sample/scripts/checkers/checker_and_visible.ts)
|
|
160
|
+
|
|
161
|
+
### Build 脚本
|
|
162
|
+
|
|
163
|
+
Build 脚本使用 `@behavior3.build` 声明,可在构建输出阶段变换树数据,而不改写源文件。
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
import type { BuildEnv, BuildScript } from "vscode-behavior3/build";
|
|
167
|
+
|
|
168
|
+
@behavior3.build
|
|
169
|
+
export class ProjectBuild implements BuildScript {
|
|
170
|
+
constructor(private readonly env: BuildEnv) {}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
支持的 hook:
|
|
175
|
+
|
|
176
|
+
- `onProcessTree(tree, path, errors)`
|
|
177
|
+
- `onProcessNode(node, errors)`
|
|
178
|
+
- `onWriteFile(path, tree)`
|
|
179
|
+
- `onComplete(status)`
|
|
180
|
+
|
|
181
|
+
### Batch 脚本
|
|
182
|
+
|
|
183
|
+
Batch 脚本使用 `@behavior3.batch` 声明,由 **Run Script as Batch Process** 调用,用于批量原地改写项目中的源树文件。
|
|
184
|
+
|
|
185
|
+
支持的 hook:
|
|
186
|
+
|
|
187
|
+
- `shouldUpgradeTree(path, tree)`
|
|
188
|
+
- `onProcessTree(tree, path, errors)`
|
|
189
|
+
- `onProcessNode(node, errors)`
|
|
190
|
+
- `onWriteFile(path, tree)`
|
|
191
|
+
- `onComplete(status)`
|
|
192
|
+
|
|
193
|
+
默认情况下,batch 只会把脚本本身造成的树变更写回源文件;如果你想把规范化或升级结果也写回去,可以通过 `shouldUpgradeTree()` 显式声明。
|
|
194
|
+
|
|
195
|
+
### Checker 与 Visible 钩子
|
|
196
|
+
|
|
197
|
+
- `@behavior3.check("name")`:注册字段校验器,同时用于 Inspector 校验与项目构建
|
|
198
|
+
- `@behavior3.visible("name")`:注册字段可见性钩子,用于 Inspector 展示与隐藏字段清理
|
|
199
|
+
- `checkScripts` 匹配到的模块可以同时注册 checker 和 visible
|
|
200
|
+
|
|
201
|
+
依赖 `new Function` 的内联可见性表达式只有在 `*.b3-workspace` 中开启 `allowNewFunction` 后才会执行。
|
|
202
|
+
|
|
203
|
+
为兼容旧形式,受支持的脚本模块仍可以通过命名导出 `Hook`、`BuildHook`、`BatchHook` 或 `default` 暴露类,但推荐优先使用上面的装饰器形式。
|
|
204
|
+
|
|
205
|
+
## 构建与 CLI
|
|
206
|
+
|
|
207
|
+
Behavior3 支持从编辑器、Inspector 视图或 CLI 发起构建。
|
|
208
|
+
|
|
209
|
+
- **Build Behavior Tree** 会先选择输出目录,并按工作区记住上一次使用的输出目录
|
|
210
|
+
- **Debug Build Behavior Tree** 会在 VS Code 调试器下启动 CLI,方便调试经过运行时转译的 TypeScript build 脚本
|
|
211
|
+
- CLI 会优先从 `--project` 指定路径开始解析;如果没有提供,则从当前工作目录开始向上查找
|
|
212
|
+
|
|
213
|
+
安装为开发依赖:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
npm install -D vscode-behavior3
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
在 `package.json` 中作为脚本使用:
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"scripts": {
|
|
224
|
+
"build:behavior": "behavior3-build --project ./workdir/hero.json --output ./dist/behavior3"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
直接运行:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
npm exec -- behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
或者不安装直接使用:
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
npx --package vscode-behavior3 behavior3-build --project ./workdir/hero.json --output ./dist/behavior3
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
CLI 参数:
|
|
242
|
+
|
|
243
|
+
- `--output <dir>`:输出目录
|
|
244
|
+
- `--project <path>`:解析起点,可为树文件、项目目录或 `*.b3-workspace`
|
|
245
|
+
- `--workspace-file <file>`:显式指定 `*.b3-workspace`
|
|
246
|
+
- `--setting-file <file>`:显式指定 `*.b3-setting`
|
|
247
|
+
- `--workspace-root <dir>`:限制向上查找的根目录
|
|
248
|
+
- `--check-expr` / `--no-check-expr`:启用或关闭表达式校验
|
|
249
|
+
- `--build-script-debug`:启用带 sourcemap 的 build script 调试模式
|
|
250
|
+
|
|
251
|
+
## 命令入口
|
|
252
|
+
|
|
253
|
+
### Explorer 中的 `Behavior3` 子菜单
|
|
254
|
+
|
|
255
|
+
- 文件夹上:**Create Project**、**Create Behavior Tree File**、**Create Build Script**、**Create Batch Script**、**Create Checker Script**、**Run Script as Batch Process**
|
|
256
|
+
- 脚本文件上:**Run Script as Batch Process**
|
|
257
|
+
- `.json` 文件上:**Open with Behavior3**
|
|
258
|
+
|
|
259
|
+
### 命令面板与视图操作
|
|
260
|
+
|
|
261
|
+
- **Open Node Config (.b3-setting)**:打开最近解析到的节点定义文件
|
|
262
|
+
- **Toggle Text / Behavior3**:在当前文件的文本编辑器与自定义编辑器之间切换
|
|
263
|
+
- **Toggle Node JSON**:在 Inspector 中切换结构化表单与原始节点 JSON
|
|
264
|
+
|
|
265
|
+
## 扩展设置
|
|
266
|
+
|
|
267
|
+
| 设置项 | 类型 | 默认值 | 说明 |
|
|
268
|
+
| --------------------------- | --------- | ----------- | ------------------------------------ |
|
|
269
|
+
| `behavior3.checkExpr` | `boolean` | `true` | 是否启用表达式参数校验 |
|
|
270
|
+
| `behavior3.language` | `string` | `"auto"` | UI 语言,可选 `auto`、`zh`、`en` |
|
|
271
|
+
| `behavior3.subtreeEditable` | `boolean` | `true` | 是否允许在当前上下文编辑可支持的子树 |
|
|
272
|
+
| `behavior3.inspectorMode` | `string` | `"sidebar"` | Inspector 显示在侧栏还是嵌入编辑器中 |
|
|
273
|
+
|
|
274
|
+
## 快捷键
|
|
275
|
+
|
|
276
|
+
| 快捷键 | 作用 |
|
|
277
|
+
| ------------------------ | --------------------------- |
|
|
278
|
+
| `Ctrl/Cmd+Z` | 撤销 |
|
|
279
|
+
| `Ctrl+Y` / `Cmd+Shift+Z` | 重做 |
|
|
280
|
+
| `Ctrl/Cmd+C` | 复制节点 |
|
|
281
|
+
| `Ctrl/Cmd+V` | 粘贴节点 |
|
|
282
|
+
| `Ctrl/Cmd+Shift+V` | 替换节点 |
|
|
283
|
+
| `Enter` / `Insert` | 插入节点 |
|
|
284
|
+
| `Delete` / `Backspace` | 删除选中节点 |
|
|
285
|
+
| `Ctrl/Cmd+F` | 搜索节点内容 |
|
|
286
|
+
| `Ctrl/Cmd+G` | 按节点 id 跳转 |
|
|
287
|
+
| `Ctrl/Cmd+B` | 构建 |
|
|
288
|
+
| `Ctrl/Cmd+Shift+B` | 调试构建 |
|
|
289
|
+
| `F4` | 切换文本 / Behavior3 编辑器 |
|
|
290
|
+
|
|
291
|
+
## 进一步阅读
|
|
292
|
+
|
|
293
|
+
- [README.md](README.md) - 英文总览
|
|
294
|
+
- [docs/README.md](docs/README.md) - 文档入口
|
|
295
|
+
- [docs/spec-driven-development.md](docs/spec-driven-development.md) - 仓库内 SDD 工作流
|
|
296
|
+
- [docs/spec/README.md](docs/spec/README.md) - 基线 spec 地图与 work-item 索引
|
|
297
|
+
- [sample/](sample) - 示例工作区、行为树与脚本
|
|
298
|
+
|
|
299
|
+
## 开发
|
|
300
|
+
|
|
301
|
+
- `npm run build` - 生产构建扩展与 webview
|
|
302
|
+
- `npm run build:dev` - 开发构建
|
|
303
|
+
- `npm run watch:ext` - 监听扩展 bundle
|
|
304
|
+
- `npm run watch:webview` - 监听 webview bundle
|
|
305
|
+
- `npm run check` - 对扩展与 webview 做 TypeScript 检查
|
|
306
|
+
- `npm run test:shared` - 运行 shared 测试
|
|
307
|
+
- 日志输出:**View -> Output** -> **Behavior3**
|
|
308
|
+
- Webview 日志也可在 DevTools 中查看
|
|
309
|
+
|
|
310
|
+
## 运行环境要求
|
|
311
|
+
|
|
312
|
+
- VS Code `^1.105.0`
|
|
313
|
+
- Node `>=20.19`,用于 CLI 与 TypeScript 脚本运行时
|
|
314
|
+
|
|
315
|
+
## 许可证
|
|
316
|
+
|
|
317
|
+
MIT
|