@sunlight_xlz/y3-lualib-types 0.1.0 → 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/README.md +98 -24
- package/UPSTREAM-LICENSE +21 -21
- package/generation.json +43534 -875
- package/package.json +27 -4
- package/types/api/gameapi1.d.ts +8058 -0
- package/types/api/gameapi2.d.ts +7912 -0
- package/types/api/gameapi3.d.ts +8020 -0
- package/types/api/gameapi4.d.ts +7896 -0
- package/types/api/gameapi5.d.ts +8093 -0
- package/types/api/gameapi6.d.ts +8101 -0
- package/types/api/gameapi7.d.ts +2016 -0
- package/types/api/globalapi.d.ts +1504 -0
- package/types/common.d.ts +9 -0
- package/types/enums.d.ts +63 -0
- package/types/events.d.ts +4570 -0
- package/types/globals.d.ts +412 -0
- package/types/handles.d.ts +1760 -0
- package/types/index.d.ts +28 -0
- package/types/objects/ability.d.ts +608 -0
- package/types/objects/destructible.d.ts +367 -0
- package/types/objects/item.d.ts +451 -0
- package/types/objects/modifier.d.ts +299 -0
- package/types/objects/projectile.d.ts +170 -0
- package/types/objects/role.d.ts +843 -0
- package/types/objects/unit.d.ts +2429 -0
- package/index.d.ts +0 -3
- package/types/y3.d.ts +0 -106610
package/README.md
CHANGED
|
@@ -1,19 +1,66 @@
|
|
|
1
|
-
#
|
|
1
|
+
# y3-lualib-types
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Y3 **原生引擎接口**的 TypeScript 声明,用于 TypeScriptToLua 项目。
|
|
4
|
+
上游 `y3-editor/y3-lualib` 子模块只是引擎元数据来源,地图不需要安装、初始化或加载这个 Lua 库。
|
|
5
|
+
|
|
6
|
+
## 生成边界
|
|
7
|
+
|
|
8
|
+
| 输入 | 输出 |
|
|
9
|
+
| ----------------------------------------------------------------- | ----------------------------------------------------------------- |
|
|
10
|
+
| `meta/gameapi*.lua`、`meta/globalapi.lua` 的空函数声明 | 全局 `GameAPI`、`GlobalAPI` |
|
|
11
|
+
| `meta/pytype.lua` 和单位、技能、玩家等原生对象元数据 | `py.Unit`、`py.Ability`、`py.Role` 等句柄及原生方法 |
|
|
12
|
+
| `meta/manually.lua`、`double.lua`、`KKNetwork.lua` 的原生补充声明 | `Fix32`、`regist_object_event`、`xdouble`、`KKNetwork` 等引擎入口 |
|
|
13
|
+
| `meta/event.lua` 中的 `key`、`event_params.name/type` | `EngineEventMap`,使用 `ET_*` 名称和 `__unit_id` 等原始字段 |
|
|
14
|
+
| `meta/enum.lua` 的原生数值 | 编译时内联的 `Enum.*` 常量枚举 |
|
|
15
|
+
|
|
16
|
+
不扫描 `game/`、`object/`、`tools/`、`util/` 等 Lua 实现目录,不生成全局 `y3`、
|
|
17
|
+
封装类 `Unit` / `Timer` / `Point` 或 `y3.math` 等工具接口。
|
|
18
|
+
`meta/editor_object.lua` 的封装数据结构和 `must_sync.lua` 的运行库配置也不进入声明。
|
|
19
|
+
事件中的 `lua_name`、`lua_type`、`lua_code` 属于封装转换,全部忽略,绝不执行。
|
|
20
|
+
|
|
21
|
+
`meta/manually.lua` 中两个引用封装命名的注解被替换为类型定义:
|
|
22
|
+
`y3.Number` 对应 `EngineNumber`,`y3.Const.EventType` 对应原生 `EngineEventName`。
|
|
23
|
+
这不会声明任何运行时 `y3` 对象。引擎对 Lua 虚拟机的扩展,例如 `os.clock_banned`,
|
|
24
|
+
仍属于原生接口;普通 Lua 标准库的完整声明可单独使用 Lua typings。
|
|
25
|
+
|
|
26
|
+
未来需要新增工具方法时,应以 TypeScript 源码实现并独立编译,不能仅生成一个依赖
|
|
27
|
+
lualib 实现的 `.d.ts`,也不能把工具方法混入原生接口。
|
|
28
|
+
|
|
29
|
+
## 开发命令
|
|
30
|
+
|
|
31
|
+
维护此项目需要 Node.js 22+、Git、Yarn Classic 1.22.22;声明包本身没有 Node 运行时要求。
|
|
5
32
|
|
|
6
33
|
```sh
|
|
7
|
-
yarn
|
|
34
|
+
yarn
|
|
35
|
+
yarn build
|
|
36
|
+
yarn verify
|
|
8
37
|
```
|
|
9
38
|
|
|
10
|
-
|
|
39
|
+
- `yarn build`:初始化/更新元数据子模块,生成原生声明并严格检查。
|
|
40
|
+
上游 SHA、生成脚本、依赖和产物都未变化时跳过;网络失败会报错。
|
|
41
|
+
- `yarn build:offline`:使用本地锁定的上游提交,不查询 GitHub。
|
|
42
|
+
- `yarn build --force`:强制重新生成。
|
|
43
|
+
- `yarn verify`:解析与范围回归、接口逐项对账、严格 TypeScript 检查、TSTL 编译及格式检查。
|
|
44
|
+
- `yarn pack:types --bump=minor`:验证并打包预演,不发布。
|
|
45
|
+
- `yarn publish:types --bump=minor`:发布原生引擎版本。后续同范围版本可使用 `yarn publish:types`。
|
|
46
|
+
|
|
47
|
+
使用 `publish:types`,不要用 Yarn 内置的 `yarn publish` 绕过验证。
|
|
48
|
+
发布脚本检查组织权限、文件白名单、内容变化和 tarball 完整性。
|
|
49
|
+
从原来的 lualib 封装声明切换到原生接口属于破坏性变更,脚本禁止以 patch 发布这次迁移。
|
|
50
|
+
|
|
51
|
+
## 地图使用方式
|
|
52
|
+
|
|
53
|
+
当前分支是原生引擎版,与原来发布的 `0.1.0` 封装版不兼容。
|
|
54
|
+
新版发布后安装对应版本;发布前可通过 `pack:types` 生成的本地 tarball 验证。
|
|
55
|
+
|
|
56
|
+
```sh
|
|
57
|
+
yarn add -D @sunlight_xlz/y3-lualib-types
|
|
58
|
+
```
|
|
11
59
|
|
|
12
60
|
```json
|
|
13
61
|
{
|
|
14
62
|
"compilerOptions": {
|
|
15
63
|
"strict": true,
|
|
16
|
-
"allowUmdGlobalAccess": true,
|
|
17
64
|
"types": ["@sunlight_xlz/y3-lualib-types"]
|
|
18
65
|
},
|
|
19
66
|
"tstl": { "luaTarget": "5.4" }
|
|
@@ -21,27 +68,54 @@ yarn add -D @sunlight_xlz/y3-lualib-types
|
|
|
21
68
|
```
|
|
22
69
|
|
|
23
70
|
```ts
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
71
|
+
const unit: py.Unit = GameAPI.get_unit_by_id(1);
|
|
72
|
+
unit.api_set_name('原生单位');
|
|
73
|
+
|
|
74
|
+
regist_object_event(unit, 'ET_UNIT_DIE', (data) => {
|
|
75
|
+
const id: py.UnitID = data.__unit_id;
|
|
76
|
+
const damage: py.Fixed = data.__damage;
|
|
77
|
+
const source: py.Unit = data.__source_unit;
|
|
30
78
|
});
|
|
31
79
|
```
|
|
32
80
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
81
|
+
这里的 ID 和对象必须在实际地图中有效。生成的 Lua 直接调用引擎:
|
|
82
|
+
`GameAPI.get_unit_by_id(1)`、`unit:api_set_name(...)`,没有 `require 'y3'`。
|
|
83
|
+
|
|
84
|
+
可使用 `import type { py, EngineEventMap } from '@sunlight_xlz/y3-lualib-types'`,
|
|
85
|
+
不能通过运行时 `import` 加载声明包。`Enum.UnitCommandTypeEnum.ATTACK_TARGET`
|
|
86
|
+
会内联为数字 `3`,无需在地图中定义 `Enum` 表;项目不要启用 `preserveConstEnums`。
|
|
87
|
+
|
|
88
|
+
原生事件回调只提供原始字段。未列入元数据的自定义事件允许使用字符串名称,
|
|
89
|
+
其回调数据为 `unknown`,由项目自行定义类型。`py.Fixed`、`XDouble` 等保留原生对象类型,
|
|
90
|
+
不会被包装层自动转换成 JavaScript 的 `number`。原生对象的方法和可空返回值按元数据保留。
|
|
91
|
+
|
|
92
|
+
## 项目结构
|
|
93
|
+
|
|
94
|
+
```text
|
|
95
|
+
vendor/y3-lualib/ 引擎元数据来源;不随 npm 包发布
|
|
96
|
+
scripts/metadata.mjs 明确选择输入,解析原生空函数及原始事件/枚举
|
|
97
|
+
scripts/lua-types.mjs LuaLS 类型语法
|
|
98
|
+
scripts/generate.mjs 输出引擎声明和来源清单
|
|
99
|
+
scripts/build.mjs 上游更新、增量缓存、验证后同步
|
|
100
|
+
scripts/verify.mjs 统一测试入口,发布时也执行
|
|
101
|
+
scripts/publish.mjs 打包、版本和发布
|
|
102
|
+
test/ 原生消费者与范围/解析回归
|
|
103
|
+
types/index.d.ts 声明包入口
|
|
104
|
+
types/api/ GameAPI 和 GlobalAPI 分片
|
|
105
|
+
types/objects/ 原生句柄上的方法
|
|
106
|
+
types/handles.d.ts 引擎类型及继承关系
|
|
107
|
+
types/globals.d.ts 原生全局函数与对象
|
|
108
|
+
types/events.d.ts 原始事件载荷
|
|
109
|
+
types/enums.d.ts 编译时常量枚举
|
|
110
|
+
generation.json 输入范围、接口逐项清单和元数据诊断
|
|
111
|
+
```
|
|
36
112
|
|
|
37
|
-
|
|
38
|
-
|
|
113
|
+
所有 `types/` 文件都由脚本生成,应修改生成逻辑或元数据适配后重新构建。
|
|
114
|
+
新增未分类元数据、未知类型、无法归属的函数,以及声明文件中出现实际 Lua 函数实现时,
|
|
115
|
+
构建会停止。`generation.json` 对每个原生空函数保留来源位置,测试将其与输入逐项对账。
|
|
39
116
|
|
|
40
|
-
`
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
泛型表使用 `LuaTable`,多返回值使用 `LuaMultiReturn`。
|
|
44
|
-
这些声明经过 TypeScript 严格检查和代表性 TypeScriptToLua 编译验证,
|
|
45
|
-
不代表所有 API 已在 Y3 游戏环境中逐一运行验收。
|
|
117
|
+
上游少量手写元数据缺少规范参数或返回注解,相关签名保留 `any` / `unknown` 并列入诊断,
|
|
118
|
+
不靠猜测补类型。元数据与当前地图使用的引擎版本需要匹配;TypeScript 和 TSTL 检查
|
|
119
|
+
不能代替 Y3 编辑器内的运行验证。
|
|
46
120
|
|
|
47
|
-
MIT
|
|
121
|
+
MIT 许可证,上游许可保留在 `UPSTREAM-LICENSE`。
|
package/UPSTREAM-LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 y3-editor
|
|
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) 2023 y3-editor
|
|
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.
|