@xiaozhu2007/koishi-plugin-litematic-renderer 0.5.2 → 0.5.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.
Files changed (18) hide show
  1. package/README.md +5 -4
  2. package/assets/threeviews/assets/block-assets.js +3 -0
  3. package/assets/threeviews/assets/block-flags.js +413 -0
  4. package/assets/threeviews/{/346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/deepslate-helpers.js./344/270/213/350/275/275 → assets/deepslate-resources.js} +67 -35
  5. package/assets/threeviews/assets/deepslate.min.js +7558 -0
  6. package/assets/threeviews/assets/gl-matrix.min.js +4195 -0
  7. package/assets/threeviews/{/346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/litematic-utils.js./344/270/213/350/275/275 → assets/litematic.js} +63 -64
  8. package/assets/threeviews/assets/renderer-api.js +936 -0
  9. package/assets/threeviews/index.html +1205 -1212
  10. package/lib/index.d.ts +253 -10
  11. package/lib/index.js +1 -1
  12. package/package.json +31 -27
  13. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/api.js./344/270/213/350/275/275 +0 -917
  14. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/assets.js./344/270/213/350/275/275 +0 -1
  15. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/deepslate.js./344/270/213/350/275/275 +0 -2
  16. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/gl-matrix-min.js./344/270/213/350/275/275 +0 -28
  17. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/opaque.js./344/270/213/350/275/275 +0 -413
  18. /package/assets/threeviews/{/346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/atlas.png" → assets/atlas.png} +0 -0
package/lib/index.d.ts CHANGED
@@ -1,59 +1,113 @@
1
- import { Context, h, Schema, Session } from 'koishi';
1
+ import { Context, h, Schema, Session } from "koishi";
2
+ /** Koishi 插件名称 */
2
3
  export declare const name = "litematic-renderer";
4
+ /** 插件可选注入的 Koishi 服务 */
3
5
  export declare const inject: {
4
6
  optional: string[];
5
7
  };
8
+ /** Litematic 渲染插件的完整配置 */
6
9
  export interface Config {
10
+ /** QQ 机器人的接入方式 */
7
11
  qqBotType: QqBotType;
12
+ /** 独立渲染器使用的 Java 可执行文件;为空时自动查找 Java 21 或更高版本 */
8
13
  standaloneJavaCommand: string;
14
+ /** Minecraft 客户端 JAR 或基础资源包路径 */
9
15
  minecraftJarPath: string;
16
+ /** 自定义材质包路径,后面的材质包具有更高优先级 */
10
17
  resourcePackPaths: string[];
11
- renderEngine: 'standalone' | 'java' | 'webgl' | 'cpu';
18
+ /** 用于生成投影图的渲染后端 */
19
+ renderEngine: "standalone" | "java" | "webgl" | "cpu";
20
+ /** 独立 Java 渲染器 JAR 的路径 */
12
21
  standaloneRendererJar: string;
22
+ /** 独立 Java 渲染任务的超时时间,单位为毫秒 */
13
23
  standaloneRenderTimeout: number;
24
+ /** 独立 Java 渲染器首次运行时的最大堆内存,单位为 MiB */
14
25
  standaloneJavaMaxHeapMb: number;
26
+ /** 内存不足后重试进程的最大堆内存,单位为 MiB */
15
27
  standaloneJavaRetryMaxHeapMb: number;
28
+ /** 检测到内存不足时允许重启 Java 进程的次数 */
16
29
  standaloneJavaMemoryRestartLimit: number;
30
+ /** 自动处理的最大文件大小,单位为 KiB */
17
31
  maxFileSize: number;
32
+ /** 投影声明方块数及所有区域总体积的上限 */
18
33
  maxBlocks: number;
34
+ /** 六面图和 CPU 渲染结果的最长边像素上限 */
19
35
  outputSize: number;
36
+ /** CPU 正二轴测渲染中方块菱形的半宽 */
20
37
  isometricCellSize: number;
38
+ /** PNG 背景颜色,格式为十六进制 RGB */
21
39
  background: string;
40
+ /** 是否将 PNG 背景输出为透明 */
22
41
  transparentBackground: boolean;
42
+ /** 是否默认使用 QQ 合并转发发送渲染结果 */
23
43
  sendAsForward: boolean;
44
+ /** 是否在每张渲染图前显示视图标题 */
24
45
  showViewTitles: boolean;
46
+ /** 是否在结果消息中引用并提及发送者 */
25
47
  replyAndMention: boolean;
48
+ /** 是否为支持的发送方式附加六面正交合成图 */
26
49
  sixFaceOverview: boolean;
50
+ /** 六面正交合成图的排列方向 */
27
51
  sixFaceLayout: SixFaceLayout;
52
+ /** 针对指定群聊覆盖的发送选项 */
28
53
  groupSendOptions: GroupSendOption[];
54
+ /** 文件下载及 WebGL 页面操作的超时时间,单位为毫秒 */
29
55
  renderTimeout: number;
56
+ /** 持久化渲染缓存的目录 */
30
57
  cacheDirectory: string;
58
+ /** 所有版本渲染缓存的总容量上限,单位为 GiB */
31
59
  cacheMaxSizeGb: number;
60
+ /** 聚合渲染诊断信息的 JSON 文件路径 */
32
61
  diagnosticsFilePath: string;
62
+ /** 用于上报渲染异常的 Sentry DSN */
63
+ sentryDsn: string;
64
+ /** 是否修复 OneBot 适配器对群文件上传事件的映射 */
33
65
  patchOneBotGroupUpload: boolean;
66
+ /** Fabric Java 渲染桥交换任务文件的目录 */
34
67
  javaBridgeDirectory: string;
68
+ /** 优先调用的外部 GPU 渲染器命令 */
35
69
  gpuRendererCommand: string;
70
+ /** 等待 Fabric Java 渲染桥返回结果的超时时间,单位为毫秒 */
36
71
  javaRenderTimeout: number;
72
+ /** Java 渲染器最终输出图像的边长 */
37
73
  javaResolution: number;
74
+ /** Java 渲染器的离屏超采样倍数 */
38
75
  javaSupersampling: number;
39
- webglQuality: 'standard' | 'high' | 'ultra';
76
+ /** WebGL 渲染的质量预设 */
77
+ webglQuality: "standard" | "high" | "ultra";
78
+ /** WebGL 单张渲染图的宽度 */
40
79
  webglWidth: number;
80
+ /** WebGL 单张渲染图的高度 */
41
81
  webglHeight: number;
82
+ /** 是否将 WebGL 正二轴测结果裁成正方形 */
42
83
  isometricSquare: boolean;
84
+ /** 正二轴测主体在画布中的最大占比 */
43
85
  isometricFill: number;
86
+ /** 正二轴测视图绕竖直轴旋转的角度 */
44
87
  isometricRotation: number;
88
+ /** 正二轴测视图的俯仰角 */
45
89
  isometricSlant: number;
46
90
  }
47
- export type SendMode = 'forward' | 'combined';
48
- export type ReplyAndMentionOverride = 'inherit' | 'enabled' | 'disabled';
49
- export type SixFaceLayout = 'horizontal' | 'vertical';
50
- export type QqBotType = 'official' | 'selfHosted';
91
+ /** 自建 QQ 中发送多张渲染图的方式 */
92
+ export type SendMode = "forward" | "combined";
93
+ /** 群聊是否覆盖全局的引用及提及设置 */
94
+ export type ReplyAndMentionOverride = "inherit" | "enabled" | "disabled";
95
+ /** 六面正交合成图的排列方向 */
96
+ export type SixFaceLayout = "horizontal" | "vertical";
97
+ /** QQ 机器人的接入方式 */
98
+ export type QqBotType = "official" | "selfHosted";
99
+ /** 指定群聊的消息发送覆盖项 */
51
100
  export interface GroupSendOption {
101
+ /** 要应用覆盖设置的 QQ 群号 */
52
102
  groupId: string;
103
+ /** 多张渲染图的发送方式 */
53
104
  sendMode: SendMode;
105
+ /** 引用及提及行为相对于全局配置的覆盖方式 */
54
106
  replyAndMention: ReplyAndMentionOverride;
55
107
  }
108
+ /** Koishi 控制台使用的插件配置模式 */
56
109
  export declare const Config: Schema<Config>;
110
+ /** 来自 Koishi 或 OneBot 事件的兼容文件元素 */
57
111
  interface FileElement {
58
112
  name?: string;
59
113
  filename?: string;
@@ -68,70 +122,259 @@ interface FileElement {
68
122
  fileId?: string;
69
123
  busid?: string | number;
70
124
  }
125
+ /** 投影中的非空气方块及其世界坐标 */
71
126
  interface Block {
72
127
  x: number;
73
128
  y: number;
74
129
  z: number;
75
130
  name: string;
76
131
  }
132
+ /** 已写入磁盘、可发送给会话的渲染图 */
77
133
  interface ImageResult {
78
134
  title: string;
79
135
  path: string;
80
136
  }
137
+ /** 从 Litematic 根标签中提取的展示元数据 */
81
138
  export interface LitematicMetadata {
139
+ /** 创建投影的游戏 ID,缺失时为“未知” */
82
140
  author: string;
141
+ /** 格式化后的创建时间,使用中国标准时间 */
83
142
  createdAt: string;
143
+ /** 文件声明的非空气方块总数 */
84
144
  totalBlocks?: number;
145
+ /** 文件声明的区域总体积 */
85
146
  totalVolume?: number;
147
+ /** 投影包围盒在 X、Y、Z 轴上的尺寸 */
86
148
  size?: [number, number, number];
149
+ /** Litematic 文件格式版本 */
87
150
  litematicVersion?: number;
151
+ /** Minecraft 数据版本号 */
88
152
  minecraftDataVersion?: number;
153
+ /** 由数据版本号推断出的 Minecraft 版本 */
89
154
  minecraftVersion?: string;
90
155
  }
156
+ /**
157
+ * 注册 Litematic 文件监听、中间件、命令、缓存和诊断端点
158
+ *
159
+ * @param ctx - 当前 Koishi 上下文
160
+ * @param config - 插件配置
161
+ * @returns 无返回值
162
+ */
91
163
  export declare function apply(ctx: Context, config: Config): void;
164
+ /**
165
+ * 为影响渲染结果的配置生成稳定的短哈希
166
+ *
167
+ * @param configuration - 可被 JSON 序列化的渲染配置
168
+ * @returns SHA-256 摘要的前 16 个十六进制字符
169
+ */
92
170
  export declare function hashRenderConfiguration(configuration: unknown): string;
171
+ /** OneBot 适配器源码兼容补丁的处理结果 */
93
172
  interface SourcePatchResult {
173
+ /** 处理后的适配器源码 */
94
174
  source: string;
175
+ /** 本次处理是否修改了源码 */
95
176
  changed: boolean;
177
+ /** 原始源码是否已经支持群文件上传事件 */
96
178
  alreadyCompatible: boolean;
97
179
  }
180
+ /**
181
+ * 恢复特定 OneBot 适配器版本中被注释的群文件上传事件映射
182
+ *
183
+ * @remarks
184
+ * 如果源码已经兼容或无法识别预期代码块,函数会原样返回源码
185
+ *
186
+ * @param source - OneBot 适配器编译后的 JavaScript 源码
187
+ * @returns 补丁后的源码以及是否修改、是否已兼容的状态
188
+ */
98
189
  export declare function patchOneBotAdapterSource(source: string): SourcePatchResult;
190
+ /**
191
+ * 从投影文件名生成跨平台安全的缓存名称片段
192
+ *
193
+ * @param filename - 原始投影文件名或路径
194
+ * @returns 移除扩展名和非法字符后、最长 80 个字符的名称
195
+ */
99
196
  export declare function cacheNameSegment(filename: string): string;
197
+ /**
198
+ * 按最近最少使用顺序删除缓存条目,直至容量不超过限制
199
+ *
200
+ * @param cacheDirectory - 包含版本子目录的缓存根目录
201
+ * @param maxBytes - 允许保留的最大总字节数
202
+ * @param protectedDirectory - 本轮清理中不得删除的缓存条目
203
+ * @returns 清理后的总字节数、删除字节数和删除条目数
204
+ * @throws 无法读取或删除缓存内容时抛出文件系统错误
205
+ */
100
206
  export declare function enforceCacheLimit(cacheDirectory: string, maxBytes: number, protectedDirectory?: string): Promise<{
101
207
  totalBytes: number;
102
208
  removedBytes: number;
103
209
  removedEntries: number;
104
210
  }>;
105
- type FileSession = Pick<Session, 'elements' | 'content'> & {
211
+ /** 查找上传文件所需的最小会话数据 */
212
+ type FileSession = Pick<Session, "elements" | "content"> & {
106
213
  event?: unknown;
107
214
  _data?: unknown;
108
215
  data?: unknown;
109
216
  message?: unknown;
110
217
  };
218
+ /**
219
+ * 在 Koishi 会话元素及常见适配器原始事件字段中查找 Litematic 文件
220
+ *
221
+ * @param session - 包含消息元素或适配器原始数据的会话
222
+ * @returns 首个识别出的 `.litematic` 文件;未找到时返回 `undefined`
223
+ */
111
224
  export declare function findLitematicFile(session: FileSession): FileElement | undefined;
225
+ /**
226
+ * 判断 Java 主版本是否满足独立渲染器的最低要求
227
+ *
228
+ * @param version - Java 主版本号;检测失败时为 `undefined`
229
+ * @returns 版本为 21 或更高时返回 `true`
230
+ */
112
231
  export declare function supportsStandaloneJavaVersion(version: number | undefined): boolean;
232
+ /**
233
+ * 生成独立 Java 渲染进程使用的 JVM 内存和垃圾回收参数
234
+ *
235
+ * @param maxHeapMb - 请求的最大堆内存,单位为 MiB
236
+ * @returns 最大堆被限制在 128 到 32768 MiB 范围内的 JVM 参数
237
+ */
113
238
  export declare function standaloneJvmOptions(maxHeapMb: number): string[];
239
+ /**
240
+ * 根据退出码和标准错误判断 Java 进程是否因内存不足而失败
241
+ *
242
+ * @param output - Java 进程的标准错误输出
243
+ * @param exitCode - Java 进程退出码
244
+ * @returns 输出包含常见内存错误或退出码为 137 时返回 `true`
245
+ */
114
246
  export declare function isJavaMemoryFailure(output: string, exitCode?: number | null): boolean;
115
- export declare function formatRenderError(error: unknown, config: Pick<Config, 'maxFileSize'>): string;
247
+ /**
248
+ * 将单次独立渲染诊断合并到插件级诊断文件
249
+ *
250
+ * @remarks
251
+ * 相同方块问题会累加计数并最多保留 20 个样本,相同渲染错误也会累加计数
252
+ *
253
+ * @param output - 包含 `render-diagnostics.json` 的渲染输出目录
254
+ * @param destination - 插件级诊断 JSON 文件路径
255
+ * @param logger - 用于报告新增诊断类别的 Koishi 日志器
256
+ * @returns 无诊断内容时直接解决,否则在合并文件写入后解决
257
+ * @throws 无法读取或写入诊断文件时抛出文件系统错误
258
+ */
259
+ export declare function mergeRenderDiagnostics(output: string, destination: string, logger: ReturnType<Context["logger"]>): Promise<void>;
260
+ /**
261
+ * 将内部渲染错误转换为不泄露本地路径的用户提示
262
+ *
263
+ * @param error - 捕获到的任意错误值
264
+ * @param config - 格式化文件大小提示所需的配置
265
+ * @returns 可直接发送给用户的中文错误消息
266
+ */
267
+ export declare function formatRenderError(error: unknown, config: Pick<Config, "maxFileSize">): string;
268
+ /** 已结合全局配置和群聊覆盖项的最终发送选项 */
116
269
  export interface ResolvedSendOptions {
270
+ /** 当前 QQ 机器人的接入方式 */
117
271
  qqBotType: QqBotType;
272
+ /** 多张图片的发送方式 */
118
273
  sendMode: SendMode;
274
+ /** 是否引用并按平台能力提及发送者 */
119
275
  replyAndMention: boolean;
276
+ /** 是否在图片前显示视图标题 */
120
277
  showViewTitles: boolean;
278
+ /** 是否生成并发送六面正交合成图 */
121
279
  sixFaceOverview: boolean;
122
280
  }
123
- type SendConfig = Pick<Config, 'sendAsForward' | 'replyAndMention' | 'groupSendOptions'> & Partial<Pick<Config, 'qqBotType' | 'showViewTitles' | 'sixFaceOverview'>>;
281
+ /** 解析消息发送选项所需的配置子集 */
282
+ type SendConfig = Pick<Config, "sendAsForward" | "replyAndMention" | "groupSendOptions"> & Partial<Pick<Config, "qqBotType" | "showViewTitles" | "sixFaceOverview">>;
283
+ /**
284
+ * 合并全局发送配置与指定群聊最后一条匹配的覆盖项
285
+ *
286
+ * @param config - 全局发送配置及群聊覆盖项
287
+ * @param groupId - 当前 QQ 群号
288
+ * @returns 适用于当前会话的最终发送选项
289
+ */
124
290
  export declare function resolveSendOptions(config: SendConfig, groupId?: string): ResolvedSendOptions;
291
+ /**
292
+ * 根据 QQ 接入类型和发送模式发送渲染图及投影元数据
293
+ *
294
+ * @remarks
295
+ * 官方 QQ 会先将所有图片合成为一张总览图,自建 QQ 支持合并转发或联合消息
296
+ *
297
+ * @param session - 接收渲染结果的 Koishi 会话
298
+ * @param images - 已写入磁盘的渲染图片
299
+ * @param metadata - 格式化后的投影元数据
300
+ * @param options - 已解析的发送选项
301
+ * @param projectionName - 在成功消息中展示的投影名称
302
+ * @returns 所有图片和元数据发送完成后解决的 Promise
303
+ * @throws 图片读取、合成或消息发送失败时抛出错误
304
+ */
125
305
  export declare function sendImages(session: Session, images: ImageResult[], metadata: string, options: ResolvedSendOptions, projectionName?: string): Promise<void>;
306
+ /**
307
+ * 将轴测图和可选六面图排版为官方 QQ 使用的单张总览 PNG
308
+ *
309
+ * @param images - 要合成的磁盘 PNG 图片
310
+ * @returns 写入首张图片所在目录的总览图绝对路径
311
+ * @throws 图片列表为空、图片无效或文件系统操作失败时抛出错误
312
+ */
126
313
  export declare function composeQqOverview(images: ImageResult[]): Promise<string>;
314
+ /**
315
+ * 创建适合当前 QQ 接入方式的引用和提及消息元素
316
+ *
317
+ * @param session - 要回复的 Koishi 会话
318
+ * @param qqBotType - QQ 机器人接入方式
319
+ * @returns 官方 QQ 最多包含引用,自建 QQ 还会包含发送者提及
320
+ */
127
321
  export declare function replyElements(session: Session, qqBotType?: QqBotType): h[];
322
+ /**
323
+ * 从 Litematic 文件读取展示和限制校验所需的元数据
324
+ *
325
+ * @param data - Gzip 压缩或未压缩的 Litematic NBT 数据
326
+ * @returns 规范化的作者、时间、尺寸和版本信息
327
+ * @throws 数据不是有效 NBT 或包含不支持的标签类型时抛出错误
328
+ */
128
329
  export declare function parseLitematicMetadata(data: Buffer): LitematicMetadata;
330
+ /**
331
+ * 校验文件声明值及每个区域的实际总体积是否超过资源限制
332
+ *
333
+ * @remarks
334
+ * 无效的自定义限制会回退为 5000000,区域体积使用绝对尺寸计算
335
+ *
336
+ * @param data - 原始 Litematic NBT 数据
337
+ * @param metadata - 预先解析的 Litematic 元数据
338
+ * @param configuredLimit - 允许的方块数和总体积上限
339
+ * @returns 校验通过时无返回值
340
+ * @throws 声明值、区域总体积或计算结果超过限制时抛出错误
341
+ */
129
342
  export declare function validateProjectionLimits(data: Buffer, metadata: LitematicMetadata, configuredLimit?: number): void;
343
+ /**
344
+ * 将 Litematic 元数据格式化为适合聊天消息展示的多行文本
345
+ *
346
+ * @param metadata - 已解析的 Litematic 元数据
347
+ * @param filename - 可选的源文件名,用于显示投影名称
348
+ * @returns 包含作者、时间、数量、尺寸及版本的中文文本
349
+ */
130
350
  export declare function formatLitematicMetadata(metadata: LitematicMetadata, filename?: string): string;
351
+ /**
352
+ * 解析 Litematic 所有区域中的非空气方块
353
+ *
354
+ * @param data - Gzip 压缩或未压缩的 Litematic NBT 数据
355
+ * @returns 带世界坐标和方块名称的非空气方块列表
356
+ * @throws 文件缺少区域数据或不包含非空气方块时抛出错误
357
+ */
131
358
  export declare function parseLitematic(data: Buffer): Block[];
359
+ /**
360
+ * 使用内置 CPU 栅格器生成正向和反向轴测 PNG
361
+ *
362
+ * @param blocks - 要渲染的非空气方块
363
+ * @param config - 控制尺寸、背景和方块比例的插件配置
364
+ * @returns 两张带固定文件名的内存 PNG
365
+ */
132
366
  export declare function renderSchematic(blocks: Block[], config: Config): {
133
367
  title: string;
134
368
  png: Buffer<ArrayBuffer>;
135
369
  }[];
370
+ /**
371
+ * 将投影的上下东西南北视图合成为一张正交总览 PNG
372
+ *
373
+ * @param blocks - 要投影的非空气方块
374
+ * @param config - 控制输出尺寸和背景的插件配置
375
+ * @param layout - 六张视图采用横向 3×2 或纵向 2×3 排列
376
+ * @returns 包含六个方向标签的 PNG 数据
377
+ * @throws 方块列表为空时抛出错误
378
+ */
136
379
  export declare function renderSixFaceOverview(blocks: Block[], config: Config, layout?: SixFaceLayout): Buffer<ArrayBuffer>;
137
380
  export {};