sapdon 3.2.2 → 3.4.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.
Files changed (76) hide show
  1. package/README.md +255 -121
  2. package/doc/dev/architecture.md +418 -0
  3. package/doc/dev/cli.md +467 -0
  4. package/doc/dev/core.md +751 -0
  5. package/doc/dev/lr-paradigm.md +85 -0
  6. package/doc/dev/oc.md +582 -0
  7. package/doc/dev/workflow.md +257 -0
  8. package/doc/hello_sapdon/hello_sapdon.md +3 -3
  9. package/doc/user/api/biome.md +558 -0
  10. package/doc/user/api/block.md +1530 -0
  11. package/doc/user/api/entity.md +685 -0
  12. package/doc/user/api/extra.md +231 -0
  13. package/doc/user/api/item.md +1125 -0
  14. package/doc/user/api/neo-guidebook.md +409 -0
  15. package/doc/user/api/recipe.md +427 -0
  16. package/doc/user/api/sapdon-ui.md +185 -0
  17. package/doc/user/api/texture.md +181 -0
  18. package/doc/user/config/build-config.md +83 -0
  19. package/doc/user/config/mod-info.md +33 -0
  20. package/doc/user/faq.md +160 -0
  21. package/doc/user/quick-start.md +122 -0
  22. package/doc/user/tutorials/block.md +474 -0
  23. package/doc/user/tutorials/entity.md +356 -0
  24. package/doc/user/tutorials/item.md +449 -0
  25. package/doc/user/tutorials/neo-guidebook-experience.md +381 -0
  26. package/doc/user/tutorials/neo-guidebook.md +640 -0
  27. package/doc/user/tutorials/recipe.md +278 -0
  28. package/doc/user/tutorials/sapdon-ui.md +207 -0
  29. package/package.json +8 -3
  30. package/prod/cli/index.js +1 -1
  31. package/prod/cli/start.js +1 -1458
  32. package/prod/core/index.d.ts +4564 -2166
  33. package/prod/core/index.js +1 -59015
  34. package/prod/core/package.json +7 -0
  35. package/prod/oc/index.d.ts +350 -108
  36. package/prod/oc/index.js +1 -1
  37. package/prod/oc/package.json +7 -0
  38. package/prod/utils/index.d.ts +20 -9
  39. package/prod/utils/index.js +1 -1
  40. package/prod/utils/package.json +7 -0
  41. package/doc/BlockAPI.md +0 -145
  42. package/doc/api.md +0 -128
  43. package/doc/oc/index.md +0 -0
  44. package/doc/sapdon-ts.md +0 -64
  45. package/src/templates/js_sapdon/build.config +0 -23
  46. package/src/templates/js_sapdon/main.mjs +0 -4
  47. package/src/templates/js_sapdon/mod.info +0 -7
  48. package/src/templates/js_sapdon/pack_icon.png +0 -0
  49. package/src/templates/js_sapdon/package.json +0 -20
  50. package/src/templates/js_sapdon/res/animations/animation_item.animation.json +0 -34
  51. package/src/templates/js_sapdon/res/animations/large_item.animation.json +0 -27
  52. package/src/templates/js_sapdon/res/models/blocks/crop.geo.json +0 -48
  53. package/src/templates/js_sapdon/res/models/entity/animation/animation_item.geo.json +0 -26
  54. package/src/templates/js_sapdon/res/models/entity/animation/large_item.geo.json +0 -28
  55. package/src/templates/js_sapdon/res/textures/blocks/none.png +0 -0
  56. package/src/templates/js_sapdon/res/textures/blocks/test_log_oak.png +0 -0
  57. package/src/templates/js_sapdon/res/textures/blocks/test_log_top.png +0 -0
  58. package/src/templates/js_sapdon/res/textures/items/masterball.png +0 -0
  59. package/src/templates/js_sapdon/scripts/custom_components/cropComponent.js +0 -50
  60. package/src/templates/js_sapdon/scripts/custom_components/items/gui_book.js +0 -37
  61. package/src/templates/js_sapdon/scripts/custom_components/registry.js +0 -25
  62. package/src/templates/js_sapdon/scripts/index.js +0 -0
  63. package/src/templates/ts_sapdon/build.config +0 -23
  64. package/src/templates/ts_sapdon/main.ts +0 -11
  65. package/src/templates/ts_sapdon/mod.info +0 -7
  66. package/src/templates/ts_sapdon/pack_icon.png +0 -0
  67. package/src/templates/ts_sapdon/package.json +0 -20
  68. package/src/templates/ts_sapdon/res/models/blocks/crop.geo.json +0 -48
  69. package/src/templates/ts_sapdon/res/textures/blocks/test_log_oak.png +0 -0
  70. package/src/templates/ts_sapdon/res/textures/blocks/test_log_top.png +0 -0
  71. package/src/templates/ts_sapdon/res/textures/items/masterball.png +0 -0
  72. package/src/templates/ts_sapdon/scripts/components/cropComponent.ts +0 -44
  73. package/src/templates/ts_sapdon/scripts/components/items/guiBook.ts +0 -36
  74. package/src/templates/ts_sapdon/scripts/components/registry.ts +0 -24
  75. package/src/templates/ts_sapdon/scripts/index.ts +0 -7
  76. package/src/templates/ts_sapdon/tsconfig.json +0 -117
@@ -0,0 +1,278 @@
1
+ # 配方创建教程
2
+
3
+ 本文档介绍如何使用 sapdon 框架创建各类 Minecraft 配方。
4
+
5
+ > 开始前请确保已完成[快速入门](../quick-start.md)中的环境搭建。
6
+
7
+ ## 导入
8
+
9
+ 所有配方 API 均从 `@sapdon/core` 导入:
10
+
11
+ ```typescript
12
+ import { RecipeAPI, registry } from '@sapdon/core'
13
+ ```
14
+
15
+ 完成后调用 `registry.submit()` 提交所有注册数据。
16
+
17
+ ---
18
+
19
+ ## 1. 有序配方 — 简写
20
+
21
+ `RecipeAPI.registerSimpleShaped()` 通过 pattern(图案)、key(键映射)和 output(输出)快速创建有序配方。
22
+
23
+ ```typescript
24
+ import { RecipeAPI, registry } from '@sapdon/core'
25
+
26
+ RecipeAPI.registerSimpleShaped(
27
+ 'sapdon:diamond_sword',
28
+ 'minecraft:diamond_sword',
29
+ [' X ', ' X ', ' Y '],
30
+ {
31
+ X: { item: 'minecraft:diamond' },
32
+ Y: { item: 'minecraft:stick' }
33
+ }
34
+ ).tags(['crafting_table'])
35
+
36
+ registry.submit()
37
+ ```
38
+
39
+ **参数说明**
40
+
41
+ | 参数 | 类型 | 说明 |
42
+ |------|------|------|
43
+ | `identifier` | `string` | 配方唯一标识符,格式 `命名空间:名称` |
44
+ | `output` | `string` | 输出物品 ID |
45
+ | `pattern` | `string[]` | 3 行图案,每行 3 字符 |
46
+ | `key` | `object` | 字符到物品的映射 |
47
+
48
+ 方法自动设置 `crafting_table` 标签。`.tags()` 链式调用可覆盖或追加标签。
49
+
50
+ ---
51
+
52
+ ## 2. 有序配方 — 链式
53
+
54
+ `RecipeAPI.registerShaped()` 返回 `AddonRecipeShaped` 实例,支持完整的链式调用。
55
+
56
+ ```typescript
57
+ import { RecipeAPI, registry } from '@sapdon/core'
58
+
59
+ RecipeAPI.registerShaped('sapdon:custom_helmet')
60
+ .key({
61
+ X: { item: 'minecraft:iron_ingot' }
62
+ })
63
+ .pattern(['XXX', 'X X', ' '])
64
+ .output('sapdon:custom_helmet')
65
+ .tags(['crafting_table'])
66
+
67
+ registry.submit()
68
+ ```
69
+
70
+ **可用链式方法**
71
+
72
+ | 方法 | 说明 |
73
+ |------|------|
74
+ | `.key(map)` | 设置字符到物品的键映射 |
75
+ | `.pattern(rows)` | 设置 3 行图案数组 |
76
+ | `.output(item)` | 设置输出物品,支持 `string` 或 `{ item, count }` 对象 |
77
+ | `.priority(num)` | 设置优先级(数值越小优先级越高) |
78
+ | `.assumeSymmetry()` | 启用对称假设 |
79
+ | `.tags(tags[])` | 设置配方标签数组 |
80
+
81
+ ```typescript
82
+ // 带数量和优先级的完整示例
83
+ RecipeAPI.registerShaped('sapdon:custom_block')
84
+ .key({
85
+ A: { item: 'minecraft:diamond' },
86
+ B: { item: 'minecraft:iron_ingot' }
87
+ })
88
+ .pattern(['AAA', 'ABA', 'AAA'])
89
+ .output({ item: 'sapdon:custom_block', count: 4 })
90
+ .priority(0)
91
+ .tags(['crafting_table'])
92
+ ```
93
+
94
+ ---
95
+
96
+ ## 3. 无序配方 — 简写
97
+
98
+ `RecipeAPI.registerSimpleShapeless()` 通过 ingredients 数组快速创建无序配方。
99
+
100
+ ```typescript
101
+ import { RecipeAPI, registry } from '@sapdon/core'
102
+
103
+ RecipeAPI.registerSimpleShapeless(
104
+ 'sapdon:custom_ingot',
105
+ 'sapdon:custom_ingot',
106
+ [
107
+ { item: 'minecraft:iron_ingot' },
108
+ { item: 'minecraft:gold_ingot' }
109
+ ]
110
+ ).tags(['crafting_table'])
111
+
112
+ registry.submit()
113
+ ```
114
+
115
+ **参数说明**
116
+
117
+ | 参数 | 类型 | 说明 |
118
+ |------|------|------|
119
+ | `identifier` | `string` | 配方唯一标识符 |
120
+ | `output` | `string` | 输出物品 ID |
121
+ | `ingredients` | `object[]` | 原料数组,无需顺序 |
122
+
123
+ 原料支持标签引用实现宽匹配:
124
+
125
+ ```typescript
126
+ RecipeAPI.registerSimpleShapeless(
127
+ 'sapdon:leather_helmet',
128
+ 'minecraft:leather_helmet',
129
+ [
130
+ { item: 'minecraft:leather' },
131
+ { item: 'minecraft:leather' },
132
+ { item: 'minecraft:leather' },
133
+ { item: 'minecraft:leather' },
134
+ { item: 'minecraft:leather' }
135
+ ]
136
+ ).tags(['crafting_table'])
137
+ ```
138
+
139
+ ---
140
+
141
+ ## 4. 无序配方 — 链式
142
+
143
+ `RecipeAPI.registerShapeless()` 返回 `AddonRecipeShapeless` 实例,支持链式调用。
144
+
145
+ ```typescript
146
+ import { RecipeAPI, registry } from '@sapdon/core'
147
+
148
+ RecipeAPI.registerShapeless('sapdon:mixed_ingot')
149
+ .ingredients([
150
+ { item: 'minecraft:iron_ingot' },
151
+ { item: 'minecraft:gold_ingot' },
152
+ { item: 'minecraft:diamond' }
153
+ ])
154
+ .output({ item: 'sapdon:mixed_ingot', count: 3 })
155
+ .tags(['crafting_table'])
156
+
157
+ registry.submit()
158
+ ```
159
+
160
+ **可用链式方法**
161
+
162
+ | 方法 | 说明 |
163
+ |------|------|
164
+ | `.ingredients(items[])` | 设置原料数组 |
165
+ | `.output(item)` | 设置输出物品 |
166
+ | `.priority(num)` | 设置优先级 |
167
+ | `.tags(tags[])` | 设置配方标签数组 |
168
+
169
+ 使用物品标签作为原料:
170
+
171
+ ```typescript
172
+ RecipeAPI.registerShapeless('sapdon:wooden_rod')
173
+ .ingredients([
174
+ { tag: 'minecraft:planks' },
175
+ { tag: 'minecraft:planks' }
176
+ ])
177
+ .output('sapdon:wooden_rod')
178
+ .tags(['crafting_table'])
179
+ ```
180
+
181
+ ---
182
+
183
+ ## 5. 熔炉配方 — 简写
184
+
185
+ `RecipeAPI.registerSimpleFurnace()` 快速创建熔炉配方。
186
+
187
+ ```typescript
188
+ import { RecipeAPI, registry } from '@sapdon/core'
189
+
190
+ RecipeAPI.registerSimpleFurnace(
191
+ 'sapdon:cooked_ruby',
192
+ 'sapdon:ruby',
193
+ 'sapdon:raw_ruby'
194
+ ).tags(['furnace'])
195
+
196
+ registry.submit()
197
+ ```
198
+
199
+ **参数说明**
200
+
201
+ | 参数 | 类型 | 说明 |
202
+ |------|------|------|
203
+ | `identifier` | `string` | 配方唯一标识符 |
204
+ | `output` | `string` | 烧炼输出物品 ID |
205
+ | `input` | `string` | 烧炼输入物品 ID |
206
+
207
+ 方法自动设置 `furnace` 标签。
208
+
209
+ ---
210
+
211
+ ## 6. 熔炉配方 — 链式
212
+
213
+ `RecipeAPI.registerFurnace()` 返回 `AddonRecipeFurnace` 实例,支持链式调用。
214
+
215
+ ```typescript
216
+ import { RecipeAPI, registry } from '@sapdon/core'
217
+
218
+ RecipeAPI.registerFurnace('sapdon:smelt_ruby')
219
+ .input('sapdon:raw_ruby')
220
+ .output('sapdon:ruby')
221
+ .tags(['furnace'])
222
+
223
+ registry.submit()
224
+ ```
225
+
226
+ **可用链式方法**
227
+
228
+ | 方法 | 说明 |
229
+ |------|------|
230
+ | `.input(item, data?, count?)` | 设置输入物品,可选 data 和 count |
231
+ | `.output(item)` | 设置输出物品 |
232
+ | `.tags(tags[])` | 设置配方标签数组 |
233
+
234
+ ```typescript
235
+ // 带 data 值的熔炉配方
236
+ RecipeAPI.registerFurnace('sapdon:smelt_ore')
237
+ .input('minecraft:iron_ore', 0, 1)
238
+ .output('minecraft:iron_ingot')
239
+ .tags(['furnace', 'blast_furnace'])
240
+ ```
241
+
242
+ ---
243
+
244
+ ## 7. 配方标签
245
+
246
+ 配方标签决定配方可在哪些方块中使用。通过 `.tags()` 方法设置:
247
+
248
+ ```typescript
249
+ RecipeAPI.registerShaped('sapdon:example')
250
+ .pattern(['A', 'A', 'A'])
251
+ .key({ A: { item: 'minecraft:iron_ingot' } })
252
+ .output('sapdon:example')
253
+ .tags(['crafting_table'])
254
+ ```
255
+
256
+ ### 可用标签值
257
+
258
+ | 标签 | 适用方块 | 说明 |
259
+ |------|----------|------|
260
+ | `furnace` | 熔炉 | 标准熔炉烧炼配方 |
261
+ | `smoker` | 烟熏炉 | 食物烧炼配方 |
262
+ | `campfire` | 篝火 | 篝火烹饪配方 |
263
+ | `soul_campfire` | 灵魂篝火 | 灵魂篝火烹饪配方 |
264
+ | `crafting_table` | 工作台 | 工作台合成配方 |
265
+
266
+ 可通过 `RecipeTags` 常量引用:
267
+
268
+ ```typescript
269
+ import { RecipeAPI, registry, RecipeTags } from '@sapdon/core'
270
+
271
+ RecipeAPI.registerSimpleFurnace(
272
+ 'sapdon:cooked_beef',
273
+ 'minecraft:cooked_beef',
274
+ 'minecraft:beef'
275
+ ).tags([RecipeTags.Furnace, RecipeTags.smoker])
276
+ ```
277
+
278
+ > 注:`RecipeTags.smoker` 首字母小写,其余常量均为大写首字母。
@@ -0,0 +1,207 @@
1
+ # Sapdon UI 页面壳系统教程
2
+
3
+ 本教程将带你创建一个使用 `sapdon_ui:` 前缀路由的自定义 Server Form UI:一个页面含「内容面板 + 按键面板」(按键盖在内容上层),左下/右下摆表单按钮,右上放退出键。完整可运行示例见 `examples/test_ui`。
4
+
5
+ ---
6
+
7
+ ## 目录
8
+
9
+ 1. [准备工作](#1-准备工作)
10
+ 2. [创建构建入口](#2-创建构建入口)
11
+ 3. [定义内容面板](#3-定义内容面板)
12
+ 4. [定义按键面板](#4-定义按键面板)
13
+ 5. [组装页面并注册](#5-组装页面并注册)
14
+ 6. [编写运行时脚本](#6-编写运行时脚本)
15
+ 7. [构建与部署](#7-构建与部署)
16
+ 8. [完整示例](#8-完整示例)
17
+
18
+ ---
19
+
20
+ ## 1. 准备工作
21
+
22
+ 初始化一个 TS 项目并安装依赖:
23
+
24
+ ```bash
25
+ npm init -y
26
+ npm install @minecraft/server@2.8.0 @minecraft/server-ui@2.1.0
27
+ # @sapdon/core 由 postinstall 的 `sapdon lib` 自动同步
28
+ ```
29
+
30
+ 项目结构:
31
+
32
+ ```
33
+ test_ui/
34
+ ├── main.ts # 构建入口(声明式定义 UI)
35
+ ├── scripts/
36
+ │ └── index.ts # 运行时入口(触发表单)
37
+ ├── build.config # 构建配置
38
+ ├── mod.info # 模块信息(含 min_engine_version)
39
+ ├── tsconfig.json
40
+ ├── package.json
41
+ ├── pack_icon.png
42
+ └── res/ # 资源目录
43
+ ```
44
+
45
+ `build.config` 关键项(参考 `examples/test_ui/build.config`):
46
+
47
+ ```json
48
+ {
49
+ "formatVersion": 2,
50
+ "buildOptions": {
51
+ "buildMode": "dev",
52
+ "buildEntry": "main.ts",
53
+ "scriptEntry": "scripts/index.ts",
54
+ "scriptOutput": "scripts/index.js",
55
+ "useJs": false,
56
+ "buildDir": "dev/",
57
+ "dependencies": [
58
+ { "module_name": "@minecraft/server-ui", "version": "2.1.0" },
59
+ { "module_name": "@minecraft/server", "version": "2.8.0" }
60
+ ]
61
+ }
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 2. 创建构建入口
68
+
69
+ `main.ts` 是构建时脚本:声明 UI → 注册页面 → `registry.submit()` 生成所有 UI JSON。
70
+
71
+ ```typescript
72
+ import {
73
+ Label, Layout, Panel, SapdonButton, SapdonButtonPanel, SapdonPanel,
74
+ SapdonServerUI, StackPanel, Text, registry
75
+ } from '@sapdon/core'
76
+ ```
77
+
78
+ ---
79
+
80
+ ## 3. 定义内容面板
81
+
82
+ 内容面板是页面的主体(背景 + 标题/正文),最后会被画在按键面板**下面**。
83
+
84
+ ```typescript
85
+ const apple_content_panel = new Panel("apple_content_panel")
86
+ .setLayout(new Layout().setSize(["40%", "40%"]))
87
+ .enableDebug();
88
+ apple_content_panel.addControl(
89
+ new StackPanel("main", undefined)
90
+ .addStack(["100%", "30%"],
91
+ new Label("title", undefined).enableDebug().setText(new Text().setText("苹果界面")))
92
+ .addStack(["100%", "70%"],
93
+ new Label("body", undefined).enableDebug().setText(new Text().setText("内容面板")))
94
+ );
95
+ ```
96
+
97
+ > 面板 id(`apple_content_panel`)稍后会作为注册引用 `sapdon_ui_apple.apple_content_panel`。
98
+
99
+ ---
100
+
101
+ ## 4. 定义按键面板
102
+
103
+ 按键面板画在内容面板**上层**。两个表单按钮用 `SapdonButtonPanel`(grid 2×1) 摆到左右下角;右上角放一个普通退出键(不占表单集合)。
104
+
105
+ ```typescript
106
+ import { Button } from '@sapdon/core'
107
+
108
+ const apple_buttons_panel = new Panel("apple_buttons_panel")
109
+ .setLayout(new Layout().setSize(["40%", "40%"]))
110
+ .addControl(
111
+ new SapdonButtonPanel("apple_buttons_grid")
112
+ .setDimensions([2, 1]) // 左右两份
113
+ .setCollection("form_buttons")
114
+ .setSize(["100%", "100%"])
115
+ .place([0, 0], new SapdonButton("bt0").setAnchor("bottom_left"))
116
+ .place([1, 0], new SapdonButton("bt1").setAnchor("bottom_right"))
117
+ .build()
118
+ )
119
+ .addControl(
120
+ new Button("exit", "common.button") // 右上:普通退出键
121
+ .addVariable("pressed_button_name", "button.menu_exit")
122
+ .setLayout(new Layout().setSize([48, 24]).setAnchorFrom("top_right").setAnchorTo("top_right"))
123
+ .addControl(new Label("exit_text", undefined).setText(new Text().setText("退出")))
124
+ );
125
+ ```
126
+
127
+ 要点:
128
+ - `grid_dimensions [2,1]` 把按键面板切成左右两半;格子内默认左上对齐,`setAnchor("bottom_left")` / `("bottom_right")` 把按钮落到两个下角。
129
+ - 表单按钮走 `SapdonButton`(自动引用框架模板 `server_form.form_button`,吃 `form_buttons` 集合数据)。
130
+ - 退出键用 `common.button` + `button.menu_exit`,点击关闭表单。
131
+
132
+ ---
133
+
134
+ ## 5. 组装页面并注册
135
+
136
+ `SapdonPanel` 把内容/按键两块组装进该页面自己的 UI 文件;`SapdonServerUI.registerPage` 注册到路由。
137
+
138
+ ```typescript
139
+ new SapdonPanel("sapdon_ui_apple") // 生成 ui/sapdon_ui_apple.json
140
+ .setContent(apple_content_panel)
141
+ .setButtons(apple_buttons_panel)
142
+ .build();
143
+
144
+ SapdonServerUI.registerPage({
145
+ panelId: "sapdon_ui:apple", // title 精确匹配
146
+ name: "apple",
147
+ contentPanel: "sapdon_ui_apple.apple_content_panel",
148
+ buttonsPanel: "sapdon_ui_apple.apple_buttons_panel",
149
+ });
150
+
151
+ registry.submit() // 输出 server_form.json + 各页面 ui 文件 + _ui_defs.json
152
+ ```
153
+
154
+ > 纯内容页(无按键):也需提供一个空的按键面板并注册,否则壳的 `$user_buttons_panel` 引用会报缺失。
155
+
156
+ ---
157
+
158
+ ## 6. 编写运行时脚本
159
+
160
+ `scripts/index.ts`:使用物品触发带 `sapdon_ui:` 前缀 title 的 ActionForm。
161
+
162
+ ```typescript
163
+ import { world } from "@minecraft/server";
164
+ import { ActionFormData } from "@minecraft/server-ui";
165
+
166
+ world.afterEvents.itemUse.subscribe((event) => {
167
+ if (event.itemStack.typeId != "minecraft:apple") return;
168
+ new ActionFormData()
169
+ .title("sapdon_ui:apple") // 前缀路由 → 自定义页
170
+ .body("触发苹果页")
171
+ .button("test1") // 喂给集合 form_buttons
172
+ .button("test2")
173
+ .show(event.source)
174
+ .then((r) => world.sendMessage("selection: " + r.selection));
175
+ });
176
+ ```
177
+
178
+ - title 含 `sapdon_ui:` → 显示自定义全屏 UI;否则走原版原生表单。
179
+ - 按钮点击返回 `response.selection`(对应集合下标)。
180
+
181
+ ---
182
+
183
+ ## 7. 构建与部署
184
+
185
+ ```bash
186
+ npm i # postinstall 自动执行 sapdon lib,同步 @sapdon/core
187
+ npm run build # 构建并复制到开发包目录
188
+ ```
189
+
190
+ 构建产物(`dev/test_ui_RP/ui/`):
191
+
192
+ ```
193
+ server_form.json # 路由壳(custom_full_screen / sapdon_screen_content / custom_panel_content / form_button)
194
+ sapdon_ui_apple.json # 页面:内容面板 + 按键面板
195
+ _ui_defs.json # 自动登记
196
+ ```
197
+
198
+ 进入游戏用苹果触发,验证:
199
+ 1. 内容面板在底层、按键面板覆盖在上层。
200
+ 2. 左下/右下各一个表单按钮(数据对应 test1/test2)。
201
+ 3. 右上「退出」点击关闭表单。
202
+
203
+ ---
204
+
205
+ ## 8. 完整示例
206
+
207
+ 完整可运行代码见仓库 `examples/test_ui`(含页面 A 内容+按键、页面 B 纯内容两个页面)。API 细节见《Sapdon UI 页面壳系统 API 参考》(`doc/user/api/sapdon-ui.md`)。
package/package.json CHANGED
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "name": "sapdon",
3
- "version": "3.2.2",
3
+ "version": "3.4.0",
4
4
  "scripts": {
5
5
  "build": "node scripts/build.cjs",
6
+ "test": "tsc && tsc-alias && node --test \"tests/*.test.mjs\"",
7
+ "build:demo": "cd examples/block_demo && npm run build",
6
8
  "pub": "npm run build && npm publish"
7
9
  },
8
10
  "keywords": [
@@ -20,6 +22,8 @@
20
22
  "devDependencies": {
21
23
  "@minecraft/server": "^2.0.0-beta.1.21.80-preview.20",
22
24
  "@minecraft/server-ui": "^1.3.0",
25
+ "@types/archiver": "^6.0.0",
26
+ "@types/d3-array": "^3.2.1",
23
27
  "@types/lodash": "^4.17.16",
24
28
  "@types/node": "^22.14.0",
25
29
  "tsc-alias": "^1.8.13"
@@ -32,6 +36,8 @@
32
36
  "@rollup/plugin-typescript": "^12.1.2",
33
37
  "chalk": "^5.4.1",
34
38
  "commander": "^13.0.0",
39
+ "d3-array": "^3.2.4",
40
+ "archiver": "^7.0.0",
35
41
  "download-git-repo": "^3.0.2",
36
42
  "inquirer": "^12.3.1",
37
43
  "lodash": "^4.17.21",
@@ -46,7 +52,6 @@
46
52
  },
47
53
  "files": [
48
54
  "prod/**/*",
49
- "doc/**/*",
50
- "src/templates/**/*"
55
+ "doc/**/*"
51
56
  ]
52
57
  }
package/prod/cli/index.js CHANGED
@@ -1 +1 @@
1
- import e from"http";Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));const t=Symbol("isRawJSON");const r=["boolean","number"],n=["string","undefined"];function o(e,o){const i=typeof o;if(null===i)return null;if(n.includes(i))return o;if(r.includes(i))return JSON.rawJSON(o);if("object"===i)return JSON.isRawJSON(o)?o:function(e){return!0===e?.[t]}(o)?JSON.rawJSON(o.rawJSON):o;if("bigint"===i)return JSON.rawJSON(o.toString());throw new Error("Unexpected value")}const i={encode:e=>JSON.stringify(e,o),decode:JSON.parse};function s(e,t=i){return t.encode(e)}const a={port:49037},{port:c}=a;const{port:l}=a;const d=new class{cliServerHandlers=new Map;listening=!1;isListening(){return this.listening}bootstrap(){this.listening=!0;const t=e.createServer((async(e,t)=>{const r=this.cliServerHandlers.get((e.url??"/").slice(1));if(r){try{const{promise:t,resolve:n,reject:o}=Promise.withResolvers();let s=Buffer.alloc(0);e.on("data",(e=>s=Buffer.concat([s,e]))),e.on("end",(()=>{try{n(function(e,t=i){return t.decode(e)}(s))}catch(e){o(e)}})),await r(...await t)}catch(e){return console.error(e),t.writeHead(500),void t.end()}t.writeHead(200),t.end()}else t.writeHead(404),t.end()})).listen(l,(()=>console.log(`Dev Server listening on port ${l}`)));return t.on("error",(()=>this.listening=!1)),t}handle(e,t){this.cliServerHandlers.set(e,t)}getHandler(e){return this.cliServerHandlers.get(e)}interceptHandler(e,t){const r=t(this.getHandler(e)??Function.prototype);return this.cliServerHandlers.set(e,r),r}},u={call:async(e,...t)=>await async function(e,...t){try{await fetch(`http://localhost:${c}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:s(t)})}catch(e){console.error(e),console.error("尝试在构建脚本中使用 server.startDevServer() 启动开发服务器")}}(e,...t)};export{u as client,d as devServer};
1
+ import e from"http";Symbol.metadata||(Symbol.metadata=Symbol("[[metadata]]"));const r=Symbol("isRawJSON");const t=["boolean","number"],n=["string","undefined"];function o(e,o){const s=typeof o;if(null===s)return null;if(n.includes(s))return o;if(t.includes(s))return JSON.rawJSON(o);if("object"===s)return JSON.isRawJSON(o)?o:function(e){return!0===e?.[r]}(o)?JSON.rawJSON(o.rawJSON):o;if("bigint"===s)return JSON.rawJSON(o.toString());throw new Error("Unexpected value")}const s={encode:e=>JSON.stringify(e,o),decode:JSON.parse};function i(e,r=s){return r.encode(e)}const a={port:49037},{port:c}=a;const{port:l}=a;const d=new class{cliServerHandlers=new Map;listening=!1;isListening(){return this.listening}bootstrap(){this.listening=!0;const r=e.createServer(async(e,r)=>{const t=this.cliServerHandlers.get((e.url??"/").slice(1));if(t){try{const{promise:r,resolve:n,reject:o}=Promise.withResolvers();let i=Buffer.alloc(0);e.on("data",e=>i=Buffer.concat([i,e])),e.on("end",()=>{try{n(function(e,r=s){return r.decode(e)}(i))}catch(e){o(e)}}),await t(...await r)}catch(e){return console.error(e),r.writeHead(500),void r.end()}r.writeHead(200),r.end()}else r.writeHead(404),r.end()}).listen(l,()=>console.log(`Dev Server listening on port ${l}`));return r.on("error",e=>{throw this.listening=!1,function(e){return"object"==typeof e&&null!==e&&"EADDRINUSE"===e.code}(e)&&(console.error(`[sapdon] Dev Server 端口 ${l} 已被其他 sapdon 进程占用。`),console.error("[sapdon] 请先结束残留的 sapdon 进程,再重新构建,否则本次构建的数据可能被写入错误的包目录。"),process.exit(1)),e}),r}handle(e,r){this.cliServerHandlers.set(e,r)}getHandler(e){return this.cliServerHandlers.get(e)}interceptHandler(e,r){const t=r(this.getHandler(e)??Function.prototype);return this.cliServerHandlers.set(e,t),t}},u={call:async(e,...r)=>await async function(e,...r){try{await fetch(`http://localhost:${c}/${e}`,{method:"POST",headers:{"Content-Type":"application/json"},body:i(r)})}catch(e){console.error(e),console.error("尝试在构建脚本中使用 server.startDevServer() 启动开发服务器")}}(e,...r)};export{u as client,d as devServer};