@wovoon/polaris 0.6.3 → 0.6.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.
- package/docs/index.md +1 -1
- package/docs/quickstart.md +21 -12
- package/docs/sdk.md +1 -1
- package/package.json +1 -1
package/docs/index.md
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
- 作品运行在 `http://localhost:5179/api/public/static/{id}/`(与生产同路径,SDK 自动识别作品)。
|
|
35
35
|
- 云能力端点与生产逐字一致:`/api/cloud/session`、`/api/cloud/{app}/collections/{name}/docs`。
|
|
36
36
|
- `--player 名字` 模拟登录玩家(可写云数据);不带参数为游客(读公开集合、不可写)。
|
|
37
|
-
-
|
|
37
|
+
- 校验与配额与生产一致(能力门禁、套餐集合额度 / 万文档 / 64KB / limit≤100),报错文案一字不差。
|
|
38
38
|
|
|
39
39
|
用 curl 即可验证(无需浏览器):
|
|
40
40
|
|
package/docs/quickstart.md
CHANGED
|
@@ -55,20 +55,29 @@ npx -y @wovoon/cli validate # 生产规则预检,PASS =
|
|
|
55
55
|
| `WORLD` | 人人可见(排行榜/公告) | `OWNER` | 登录玩家写自己的文档 |
|
|
56
56
|
| `PLAYER` | 仅文档主人可见(个人存档) | `SERVER` | **仅云函数可写**(防作弊数据的正解) |
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
配额:每作品集合数按套餐配置(免费/创作/专业默认 8/32/128)、1 万文档/集合、单文档 64KB。
|
|
59
59
|
|
|
60
60
|
### functions/*.js(云函数)
|
|
61
61
|
|
|
62
62
|
```js
|
|
63
|
-
// functions/settle.js ——
|
|
63
|
+
// functions/settle.js —— 教学结算;竞技结果应取自权威房间,不能信任客户端上报战绩
|
|
64
64
|
exports.main = async (event, context) => {
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
65
|
+
if (!context.player.loggedIn) throw new Error('请先登录');
|
|
66
|
+
const { kills, wave } = event;
|
|
67
|
+
if (![kills, wave].every(n => Number.isSafeInteger(n) && n >= 0 && n <= 10000)) {
|
|
68
|
+
throw new Error('战绩格式无效');
|
|
69
|
+
}
|
|
70
|
+
const score = kills * 10 + wave * 50;
|
|
71
|
+
const col = context.cloud.collection('rankings');
|
|
72
|
+
const playerId = context.player.playerId;
|
|
73
|
+
// SERVER 文档归属平台;玩家身份放在业务字段中,set 只能更新已存在的文档 id。
|
|
74
|
+
const mine = (await col.query({ where: { playerId }, limit: 1 }))[0];
|
|
75
|
+
const data = { playerId, score, at: Date.now() };
|
|
76
|
+
if (mine) await col.set(mine.id, data);
|
|
77
|
+
else await col.add(data);
|
|
78
|
+
const top = await col.query({ orderBy: 'score', order: 'desc', limit: 10 });
|
|
79
|
+
const rank = top.findIndex(d => JSON.parse(d.data).playerId === playerId);
|
|
80
|
+
return { score, rank: rank < 0 ? null : rank + 1 };
|
|
72
81
|
};
|
|
73
82
|
|
|
74
83
|
// 可选元数据(直接在函数文件里声明):
|
|
@@ -77,7 +86,7 @@ exports.main = async (event, context) => {
|
|
|
77
86
|
// exports.timeoutMs = 30000; // 长任务档 1000~60000ms(默认 3000)
|
|
78
87
|
```
|
|
79
88
|
|
|
80
|
-
沙箱:禁出网、64MB 内存、入出参 ≤32KB
|
|
89
|
+
沙箱:禁出网、64MB 内存、入出参 ≤32KB;月调用次数由云服务套餐配置;另有玩家 30 次/分、作品 20 万次/日的安全上限。
|
|
81
90
|
|
|
82
91
|
---
|
|
83
92
|
|
|
@@ -110,8 +119,8 @@ await cloud.call('settle', { kills, wave }); // 调云函数
|
|
|
110
119
|
|
|
111
120
|
const room = cloud.room('arena-1'); // 实时房间(256 人/房)
|
|
112
121
|
room.send({ x, y, hp }); // ≤4KB,300 帧/30s
|
|
113
|
-
room.onMessage((
|
|
114
|
-
room.onPresence((
|
|
122
|
+
room.onMessage(({ from, data }) => {});
|
|
123
|
+
room.onPresence(({ type, playerId, players }) => {});
|
|
115
124
|
```
|
|
116
125
|
|
|
117
126
|
TypeScript 构建期可用 `@wovoon/polaris`(全量类型)。
|
package/docs/sdk.md
CHANGED
|
@@ -56,7 +56,7 @@ const rows = docs.map(d => parseData(d)); // data 字符串 → 对象
|
|
|
56
56
|
| playerId | "账号 × 作品"稳定(同账号同作品恒定,跨作品不可关联);未登录为游客态 |
|
|
57
57
|
| 游客 | 可读 WORLD 集合;**不可写**(`登录后才能写入云数据`) |
|
|
58
58
|
| 权限 | 读 `WORLD`(默认,任何人)/ `PLAYER`(仅登录);写 `OWNER`(默认,本人文档)/ `SERVER`(云函数,M3) |
|
|
59
|
-
| 配额 |
|
|
59
|
+
| 配额 | 每作品集合数由套餐决定(免费/创作/专业默认 8/32/128,可由后台调整);每集合 10,000 条文档;单文档 64 KB;查询 limit ≤ 100(默认 20) |
|
|
60
60
|
| 排序 | `orderBy` 按文档**数值字段**应用层排序(`order: 'asc'|'desc'`),排行榜场景 |
|
|
61
61
|
| 文档形态 | JSON 对象(不能是数组/标量);`id`/`seq`/`createdAt`/`updatedAt` 平台维护 |
|
|
62
62
|
| 能力门禁 | 每次调用比对 `.wovoon` 声明,未声明即拒绝并附修复指引(见 [errors.md](errors.md#cloud)) |
|