cajonzero 0.1.3 → 0.2.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Toby Lai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Toby Lai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # cajonzero
2
2
 
3
3
  运行在 Cloudflare 上的 BOX3 游玩端引擎:内置账号系统,每个房间是一个
4
- Durable Object,地图存放在 OSS/CDN。
4
+ Durable Object,地图默认随 worker 作为静态资源部署(也可改 CDN)。
5
5
 
6
6
  ## 安装
7
7
 
@@ -42,70 +42,53 @@ npm run deploy
42
42
  `cj0 setup` 会把 KV namespace id 写进 `wrangler.jsonc`;如果当时没有登录
43
43
  wrangler,也可以手动运行 `npx wrangler kv namespace create <name> --update-config --binding CAJONZERO_KV`。
44
44
 
45
- ## 配置地图
46
-
47
- 地图文件单独上传,不随 worker 打包。把解包后的 `.boxplay` 目录上传到
48
- OSS/S3/CDN(需允许 CORS),然后在 `cajonzero/maps.json` 中登记:
49
-
50
- ```json
51
- {
52
- "version": 1,
53
- "maps": [
54
- {
55
- "slug": "race",
56
- "root": "https://<你的 CDN>/box3/race/",
57
- "worldId": "<世界 id>",
58
- "name": "显示名"
59
- }
60
- ]
61
- }
62
- ```
63
-
64
- `root` 必须以 `/` 结尾;更新地图后刷新 CDN 缓存或改用带版本的路径。
65
- 房间参数、地图拉取策略等配置位于 `cajonzero/config.json`。
66
-
67
- ### 预计算 seed(强烈建议)
68
-
69
- 默认情况下房间启动会沿着 `bundle.json` → manifest → 每个 blob 逐个拉取,一张真实地图
70
- 会产生 100+ 次子请求。Cloudflare Workers 免费版单次调用只有 50 个子请求 / 10ms CPU,
71
- 线上会直接起不来(本地 `wrangler dev` 不限制,所以看起来正常)。
45
+ ## 导入地图
72
46
 
73
- `cj0 worker build-seed` 在本地把每张图解析一次,把单文件 seed pack 写进 **worker 的静态资源目录**
74
- (`dist/ui/seed/<slug>.json.gz`),随 `wrangler deploy` 一起上传,不需要改 CDN、不写 KV/R2:
47
+ 地图在本地从 `.boxplay` 导入,写进项目的 `public/`,随 worker 一次部署:
75
48
 
76
49
  ```bash
77
- cj0 worker build-seed # 所有地图;也可只传 slug
78
- # seeded race: 155 bodies, 64 voxel chunks, 52 meshes -> dist/ui/seed/race.json.gz (38.2 KB)
79
- # seed assets: dist/ui/seed (served at /seed/<slug>.json[.gz])
50
+ npx cj0 add ./race.boxplay # 解包到 public/maps/race/
51
+ npx cj0 update race ./race-v2.boxplay # 覆盖已有 slug
52
+ npx cj0 list # catalog + 本地导入状态
53
+ npx cj0 remove race # 删除地图、私有脚本、catalog
80
54
  ```
81
55
 
82
- 之后房间启动变成 **1 次 assets 读取**,不再遍历项目图。生成的部署项目脚本已经包含这一步:
56
+ `add/update` 会一次性完成:
83
57
 
84
- ```json
85
- "dev": "cj0 worker prepare && wrangler dev",
86
- "deploy": "cj0 worker prepare && cj0 worker build-seed --force && wrangler deploy"
87
- ```
58
+ 1. 公开地图资源写到 `public/maps/<slug>/`(`bundle.json`、`worlds/...`);
59
+ 2. 在本地解析世界图,写出 `public/maps/<slug>/seed.json.gz`,房间启动只读这一个文件;
60
+ 3. **服务端脚本**写到 `cajonzero/private/<slug>.json.gz`,不会进入公开的
61
+ `public/`;客户端脚本仍会保留在地图目录里;
62
+ 4. 在 `cajonzero/maps.json` 写入 `"root": "/maps/<slug>/"`,并把服端脚本文件记录为
63
+ `"scriptsFile": "cajonzero/private/<slug>.json.gz"`(该目录会提交,CF 构建时 `cj0 deploy` 可上传)。
88
64
 
89
- `cj0 worker prepare` 会保留 `seed/` 目录;`deploy` 强制重建,避免地图内容更新但 `version`
90
- 没变时继续用旧 pack(`maps.json` 的 `version` / `etag` / `root` 变化也会触发重建)。
65
+ `seed` 在 `add/update` 时构建,不再有独立的 build/seed 步骤。`cj0 update` 默认保留
66
+ 你手工改成 CDN 绝对地址的 `root`;`--reset-root` 可恢复为 `/maps/<slug>/`。
91
67
 
92
- 如果你更想把 pack 放在地图 CDN 上(不改 worker),也可以用:
68
+ ### 使用独立 CDN
93
69
 
94
- ```bash
95
- cj0 maps pack race # 生成 race.seed.json.gz,手动上传到 <root>/seed.json.gz
96
- ```
70
+ 如果不想把地图放进 worker 的静态资源,把对应条目的 `root` 改成
71
+ `https://<你的 CDN>/box3/race/` 即可(需允许 CORS)。运行时会自动走 HTTP 读取;
72
+ `seed.json.gz` 也放在同一个 root 下即可。
73
+
74
+ > Worker 静态资源限制:免费版 20,000 文件 / 单文件 25 MiB,付费版 100,000 文件。
75
+ > 超出时改用 CDN。
97
76
 
98
- 两种来源都会自动识别,缺省时回退到逐文件解析。
77
+ 房间参数、地图拉取策略等配置位于 `cajonzero/config.json`。服务端脚本由
78
+ `cj0 deploy` 上传到 KV(`CAJONZERO_SCRIPTS`,缺省回退 `CAJONZERO_KV`)。
99
79
 
100
80
  ## 常用命令
101
81
 
102
82
  ```bash
103
- cj0 create <folder> # 生成部署项目
104
- cj0 setup [--config <file>] # 配置 ENV + KV namespace(id)
105
- cj0 maps pack <slug> # 预计算 seed 文件(上传到 CDN)
106
- cj0 worker build-seed [slug...] # 预计算 seed 并写进 worker assets
107
- cj0 serve [--port <port>] [--host <host>] # 本地启动
108
- cj0 worker prepare [--config <file>] # 把包内 UI 同步到 assets.directory
109
- npm test # 运行测试
110
- npm run ci:gates # 完整检查(类型/测试/构建)
83
+ cj0 create <folder> # 生成部署项目(并同步 UI 到 public/)
84
+ cj0 setup [--config <file>] # 配置 ENV + KV namespace(id)
85
+ cj0 add <file.boxplay> [--slug <slug>] # 导入地图
86
+ cj0 update <slug> <file.boxplay> # 替换地图
87
+ cj0 list [--json] # 查看地图 catalog
88
+ cj0 remove <slug> # 删除地图
89
+ cj0 sync [--config <file>] # 把包内 UI 同步到 public/
90
+ cj0 deploy [--config <file>] # 同步 UI + 上传脚本 + wrangler deploy
91
+ cj0 serve [--port <port>] [--host <host>] # 本地启动
92
+ npm test # 运行测试
93
+ npm run ci:gates # 完整检查(类型/测试/构建)
111
94
  ```