dsh-game-material-master 0.3.0 → 0.6.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.en.md CHANGED
@@ -18,8 +18,12 @@ no system image libraries required, and your assets are never uploaded to a thir
18
18
  > upload your character sheet → click "Generate turn video" (the default path: the character rotates steadily
19
19
  > in place for one full turn, then the eight directions are cut out automatically; switch the method in
20
20
  > stage ① if you'd rather generate each direction separately).
21
+ >
22
+ > The sidebar entry also carries a **small chevron menu button**: click it to pop up the six features and
23
+ > jump straight into the one you want. Features you do not use can be turned off in settings (see
24
+ > "Feature management").
21
25
 
22
- All four modules share the same "generate → review → re-run" workbench. Every stage can be **redone on its
26
+ All six modules share the same "generate → review → re-run" workbench. Every stage can be **redone on its
23
27
  own**, and every asset can be **approved item by item**. The "review mode" lets an agent approve each step
24
28
  and move on automatically, or stop at every step and wait for your go-ahead.
25
29
 
@@ -29,6 +33,7 @@ and move on automatically, or stop at every step and wait for your go-ahead.
29
33
  | **② Image generation** | Prompt (optionally with reference images) → images → green-screen keying | Clean transparent PNG character art / props |
30
34
  | **③ Sequence frames** | First/last frame or a reference video → generate video → extract frames → key | A horizontally laid out, loopable sequence |
31
35
  | **⑤ Map tile generation** | Isometric tiles → assemble a whole map | A tile pack (PNGs) + map PNG + layout JSON |
36
+ | **⑥ Map editor** (experimental, **fully local, zero cost**) | Pick a tileset → paint directly (rebuilt after AsLib's RPG Map Maker: one screen, icon-only, no jargon) | PNG + save-file JSON (wrapping map, auto-tiling, animated tiles); tick what to export and multiple files come as one ZIP download |
32
37
  | ~~④ Rigged animation~~ | Part extraction → assembly → skeletal animation → Spine / DragonBones atlas | **Experimental, not covered in this document** |
33
38
 
34
39
  > 💡 **Module ⑤ "Map tile generation" is built on one idea: geometry by code, content by AI.**
@@ -38,6 +43,28 @@ and move on automatically, or stop at every step and wait for your go-ahead.
38
43
  > re-assembling with the same seed is pixel-identical. Measured: letting the model draw the diamond freely
39
44
  > gives ratios of 1.03–1.55 (nowhere near 2:1), while template filling hits 100%.
40
45
 
46
+ > 💡 **Module ⑥ "Map editor" is modelled after the RPG Map Maker in [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master) and rebuilt as one screen, icon-only, with no jargon.**
47
+ > The asset palette and twelve icon buttons sit on the left, the canvas on the right. **Pick one tileset image and start
48
+ > painting**. "Assets" opens a **list of images plus an "Add image" button**: the dialog asks for the
49
+ > **image file / name / cell size / usage / animation** (hover any control for an explanation) and the properties
50
+ > are then **fixed for good -- delete the image and add it again to change them**. Leave the cell size empty and
51
+ > it is detected from the image. The built-in set (4 autotile sheets + 1 prop grid, the water animating on 2
52
+ > frames) is in the list by default, can be deleted just like your own, and "Restore built-ins" brings it back;
53
+ > its properties cannot be edited. To animate **your own plain sheets**, pick "**Flip-book**" when adding (one
54
+ > row per page); autotile sheets need no setting -- their variants are the frames, and the list shows
55
+ > "Animates: N frames". Map size and cell size are both free-form; the map **wraps around on all four sides** at
56
+ > the data level (auto-tiling joins the top/bottom and left/right edges). The canvas cannot be dragged off the
57
+ > map — it stops at the edge and the map's top-left lines up with the canvas — and the blank area outside cannot
58
+ > be painted
59
+ > ("try the built-in tileset" — its water already has a 2-frame animation). To animate **your own plain
60
+ > sheets**, pick "**Flip-book**" under "Does it animate?" in the Assets card: like a flip-book, each row is one
61
+ > page, and the card states the result ("Animates: N rows = N frames"). Autotile-block sheets need no setting —
62
+ > their variants are the frames. You can also generate random terrain, a maze or a continent in one go.
63
+ > **Not a single model call is made — so nothing is billed.**
64
+
65
+ > 🏷️ **Creating anything in any of the six modules asks for a name first**: the field is pre-filled with the
66
+ > default (just press Enter to keep it), and cancelling creates nothing. Map projects can also be renamed later.
67
+
41
68
  > ⚠️ **Module ④ "Rigged animation" is still experimental and not yet finished**: the quality of part extraction
42
69
  > depends on the image model, automatic assembly and bone inference frequently need manual correction on real
43
70
  > character art (agent visual priors or manual dragging), and the exported Spine / DragonBones output has not
@@ -145,8 +172,8 @@ without spending anything on generation.
145
172
  2. Optional: drop in **reference images** (up to 10); with references present, it runs image-to-image. To cite
146
173
  several of them, refer to "image one", "image two" in the prompt.
147
174
  3. Pick the model / size / count and click **Generate**.
148
- 4. In the results area, review **image by image**: approve, download the PNG, regenerate, delete. The background
149
- percentage is shown right there so you can judge how clean the keying is.
175
+ 4. In the results area, review **image by image**: approve, download the original / download the PNG (the keyed
176
+ result), regenerate, delete. The background percentage is shown right there so you can judge how clean the keying is.
150
177
 
151
178
  ![Image generation · prompt and reference images](https://raw.githubusercontent.com/universe-st/dsh-game-material-master/main/docs/images/gmm-06-image.png)
152
179
 
@@ -185,7 +212,7 @@ flowchart LR
185
212
 
186
213
  ## Driving it from chat
187
214
 
188
- **Every feature of all four modules** (including the experimental rigged animation) **is available through
215
+ **Every feature of all six modules** (including the experimental rigged animation, map tiles and the map editor) **is available through
189
216
  chat**. The plugin registers the whole pipeline as `game_material_*` tools, so an agent can drive it forward,
190
217
  wait, review, and also stop at each step for you to approve.
191
218
 
@@ -217,7 +244,7 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
217
244
  ```
218
245
 
219
246
  The package is published to npm: [dsh-game-material-master](https://www.npmjs.com/package/dsh-game-material-master)
220
- (currently `0.1.1`, `latest`). It has no runtime dependencies, so `dsh plugin add` is all you need.
247
+ (currently `0.6.0`, `latest`). It has no runtime dependencies, so `dsh plugin add` is all you need.
221
248
 
222
249
  After installing, **restart DSH** (the host half is loaded at startup). The browser half is read from
223
250
  `lib/client.js` on disk on each request, so refreshing the browser is enough for it to take effect.
@@ -238,16 +265,32 @@ point `FFMPEG_PATH` / `FFPROBE_PATH` at absolute paths. The package has **no run
238
265
  | Item | Description |
239
266
  |---|---|
240
267
  | Volcengine Ark API Key | "Test connection" really generates a 1K thumbnail (a small charge) and validates both the key and the model |
241
- | Image model | Defaults to `doubao-seedream-4-0-250828`; switchable to 4.5 / 5.0 Lite / Pro |
268
+ | Image model | Defaults to `doubao-seedream-5-0-flash-260915`; switchable to 5.0 Pro / Lite / 4.5 |
242
269
  | MiniMax API Key | "Test connection" is free and can tell an invalid key apart from other errors |
243
270
  | Video model | Defaults to `MiniMax-H3` (v2 protocol); Hailuo / I2V use v1; the UCloud version of H3 is selected explicitly |
244
271
  | Base URL | Host root, without `/v1` or `/v2`. `api.minimax.cn` in mainland China, `api.minimaxi.com` internationally |
245
272
  | Default parameters | Cell width and height, frame count, pixel block size, keying threshold, and so on |
273
+ | Feature management | Per-module switches: a disabled module disappears from the UI **and the agent cannot call it either** (see below) |
246
274
 
247
275
  Keys are written only to `<DSH_HOME>/game-material-master/config.json` on your machine, and the UI always
248
276
  masks them when displaying them back. **The model is a plugin-level setting shared by all three modules**;
249
277
  after you switch models, tasks align to the new tier automatically.
250
278
 
279
+ ### Feature management (hiding modules you do not use)
280
+
281
+ Turn a module off under **Settings → Game Material Master → Feature management**; turn it back on any time.
282
+ Existing project data is never deleted.
283
+
284
+ - **UI**: the module disappears from the workbench tabs and from the sidebar shortcut menu. If you were
285
+ sitting on that module, the workbench falls back to the first visible one.
286
+ - **Chat**: `game_material_call` / `status` / `intake` / `upload` / `wait` / `review` / `approve` all refuse,
287
+ and the error says where to turn the feature back on. Hiding only the UI would not be hiding at all: the
288
+ agent cannot see the tab but could still call generation methods and spend real money, so the host half
289
+ re-checks the current setting on every call.
290
+ - Visibility is **user-only**: the tool surface rejects `saveConfig({hiddenModules})`, otherwise the model
291
+ could simply unhide a feature by itself.
292
+ - Hiding everything is allowed; the workbench then says every feature is hidden.
293
+
251
294
  ## UI language
252
295
 
253
296
  **The plugin UI follows DSH's own language setting** (Settings → General → Language). Chinese and English are
@@ -268,7 +311,7 @@ the host side (the host has no access to the locale service), so the browser hal
268
311
  along every time it reads a project or resets prompts.
269
312
 
270
313
  Scope note: **localization covers the browser half's UI text and the built-in default prompts** — the workbench
271
- title, the four module tabs, every card's buttons and notice bars, dialogs, the settings page, the review
314
+ title, the six module tabs, every card's buttons and notice bars, dialogs, the settings page, the review
272
315
  controls, and the default prompts. Two categories remain in Chinese, because DSH currently only exposes the
273
316
  locale service to the browser half:
274
317
 
@@ -297,8 +340,9 @@ Everything in the UI that you can click, change or approve is bilingual.
297
340
  ├── projects/<id>/ eight-direction sheet (source / images / videos / frames / keyed / preview / out)
298
341
  ├── image-jobs/<id>/ image generation
299
342
  ├── sequence-jobs/<id>/ sequence frames
300
- └── rig-jobs/<id>/ rigged animation (experimental: sheet / parts / layout / rig / atlas)
301
- └── tile-jobs/<id>/ map tiles (template / raw / cell / decor / map / export)
343
+ ├── rig-jobs/<id>/ rigged animation (experimental: sheet / parts / layout / rig / atlas)
344
+ ├── tile-jobs/<id>/ map tiles (template / raw / cell / decor / map / export)
345
+ └── map-jobs/<id>/ map editor (project.json / map.json / tilesets / preview / export)
302
346
  ```
303
347
 
304
348
  > Map tiles keep the **raw generation output** in `raw/`: after changing regularisation parameters such as
@@ -355,6 +399,27 @@ The screenshots in this document were taken by Playwright against the real UI; t
355
399
  - MiniMax occasionally rejects content on moderation (about 10% in practice); just reword to a more neutral
356
400
  prompt and retry.
357
401
 
402
+ ## Credits
403
+
404
+ - **Module ⑥ "Map editor" is modelled after the RPG Map Maker in
405
+ [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master).** What was borrowed is its **interaction and
406
+ layout** (one screen: tile palette plus an icon toolbar on the left, canvas on the right; the pen / eraser /
407
+ bucket / pipette / hand tools together with single-layer preview, layer up-down and undo-redo; click a
408
+ palette tile to pick a brush, a red frame marking the current one, wheel to zoom, drag to pan) and two
409
+ **geometry conventions**:
410
+ 1. **The map wraps around** — auto-tiling works modulo the map size, so the top/bottom and left/right
411
+ edges join up (a data-level property); the camera is clamped inside the map (dragging stops at the
412
+ edge, with the map's top-left aligned to the canvas) and nothing can be painted outside it;
413
+ 2. **A2 auto-tiling** — a 64×160 sheet is 2 variants × 5 shapes; each cell is drawn as four 16px quadrants,
414
+ and each quadrant is picked from one 5-state table over left / up / up-left. Both the small-cell index
415
+ formula and the fact that "1-based index − 1 == AsLib's chip index" come from its `AsMap.hpp`.
416
+
417
+ Its code is **CC0**; this plugin re-implements the behaviour in TypeScript and **does not copy its source**.
418
+ - ⚠️ **The `Picture/MapChip/*_pipo.png` tiles shipped in the AsLib repository belong to a third party and are
419
+ not bundled here** (its README states "Third party content is copyrighted by its respective owners").
420
+ The built-in tileset is generated procedurally on this machine by `scripts/make-map-sample-tileset.mjs`,
421
+ to the same A2 spec.
422
+
358
423
  ## License
359
424
 
360
425
  [MIT](LICENSE)
package/README.md CHANGED
@@ -15,8 +15,11 @@
15
15
  > **30 秒上手**:`dsh plugin --profile web add dsh-game-material-master` → 重启 DSH →
16
16
  > 侧栏点「游戏素材大师」→ 设置里填两个 API Key → 新建项目、上传设定图 → 点「生成转圈视频」
17
17
  >(默认路径:角色原地匀速转一圈,再自动截出八个方向;要逐方向生图就在阶段①切一下方式)。
18
+ >
19
+ > 侧栏那个入口上还有一个**小折角菜单按钮**:点它直接弹出六个功能,一步跳进要用的那个;
20
+ > 不用的功能可以在设置里关掉(见「功能管理」)。
18
21
 
19
- 四个模块共用同一套「生成 → 验收 → 重跑」工作台。每个阶段都能**单独重做**,每份产物都能
22
+ 六个模块共用同一套「生成 → 验收 → 重跑」工作台。每个阶段都能**单独重做**,每份产物都能
20
23
  **逐项打「通过」**;「审核模式」可以选 agent 自动审完就往下走,也可以选每一步停下来等你点头。
21
24
 
22
25
  | 模块 | 做什么 | 走完能拿到 |
@@ -25,6 +28,7 @@
25
28
  | **② 图片生成** | 提示词(可带参考图)→ 出图 → 抠绿幕 | 干净透明的 PNG 立绘 / 道具 |
26
29
  | **③ 序列帧生成** | 首尾帧或参考视频 → 生成视频 → 抽帧 → 抠像 | 横向排布、可循环播放的序列帧 |
27
30
  | **⑤ 45°地图地块生成**(实验性) | 45° 等距地块 → 铺成整张地图 | 地块包(PNG)+ 地图 PNG + 布局 JSON |
31
+ | **⑥ 地图编辑器**(实验性,**全本地零计费**) | 选一张素材图 → 直接画(参照 AsLib 的 RPG Map Maker 重做:一屏、纯图标、零术语) | PNG + 存档 JSON(地图四周环绕、自动连接、动画地块);勾几项就导几项,多个产物自动打成一个 ZIP 下载 |
28
32
  | ~~④ 骨骼动画生成~~ | 拆件 → 装配 → 骨骼动画 → Spine / DragonBones 图集 | **实验性功能,本文不展示** |
29
33
 
30
34
  > 💡 **模块⑤「45°地图地块生成」的核心思路是「几何交给代码,内容交给 AI」。**
@@ -33,6 +37,23 @@
33
37
  > 好处是**几何永远精确**——地块拼起来不会有缝,换种子重铺逐像素可复现。
34
38
  > 实测「让模型自由画菱形」的比例只有 1.03~1.55(对不上 2:1),而模板填充的达标率是 100%。
35
39
 
40
+ > 💡 **模块⑥「地图编辑器」借鉴了 [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master) 的 RPG Map Maker,按它重做为一屏、纯图标、零术语。**
41
+ > 左边是素材调色板与 12 个图标按钮,右边就是画布。**「素材」点开是一张素材列表 + 一个「新增素材」**:
42
+ > 新增时弹窗口填**素材图 / 名字 / 格子大小 / 用法 / 会动吗**(鼠标移上去都有解释),一步填完
43
+ > **属性就定下来了,之后只能删掉重来**;尺寸不用你算,留空就按图片尺寸自动识别。
44
+ > 内置素材默认就在列表里(自带 4 张自动连接图 + 1 张道具,水自带 2 帧动画),
45
+ > 同样可以删,删错了点「恢复默认素材」一键拿回来 —— 它的属性不允许改。
46
+ > 想让**自己的普通素材**也动,新增时选「**翻页图**」—— 像手翻书,每一行是一页;
47
+ > 拼块自动连接素材不用设,它的变体本来就是帧,列表上直接标出「会动 N 帧」。
48
+ > 地图大小、格子大小都能随便填(宽高各填各的);
49
+ > **四周环绕**在数据层:自动连接会把上下、左右两边接起来。画布拖不出地图 —— 拖到边就停,
50
+ > 地图左上角对齐后不会再乱动,图外那片空白也画不上;
51
+ > 还能一键生成随机地形 / 迷宫 / 大陆。
52
+ > **一次模型调用都没有,也就不花钱。**
53
+
54
+ > 🏷️ **六个模块的新建都先问一个名字**:输入框里已经填好默认名(直接回车就用默认值),点取消则不会创建;
55
+ > 地图项目还能随时「重命名」。
56
+
36
57
  > ⚠️ **模块④「骨骼动画生成」仍是实验性功能,尚未完善**:拆件质量取决于生图模型,自动装配与骨骼推导
37
58
  > 对真实立绘经常需要人工校正(agent 视觉先验或手工拖放),导出的 Spine / DragonBones 产物也还没经过
38
59
  > 足够的引擎侧验证。界面上该模块带「实验性」角标,并在每次进入时弹窗说明。本文只展示前三个模块。
@@ -120,7 +141,7 @@ flowchart LR
120
141
  1. 写主提示词;需要跨批次复用的共同要求(比如「不要出现文字水印」)写进**统一附加提示词**。
121
142
  2. 可选:拖入**参考图**(最多 10 张),有参考图时走图生图;引用多张可在提示词里写「图一」「图二」。
122
143
  3. 选好模型 / 尺寸 / 张数,点**生成**。
123
- 4. 结果区**逐张**看:通过、下载 PNG、重新生成、删除;背景占比会直接标出来,判断抠像干不干净。
144
+ 4. 结果区**逐张**看:通过、下载原图 / 下载 PNG(抠像结果)、重新生成、删除;背景占比会直接标出来,判断抠像干不干净。
124
145
 
125
146
  ![图片生成 · 提示词与参考图](https://raw.githubusercontent.com/universe-st/dsh-game-material-master/main/docs/images/gmm-06-image.png)
126
147
 
@@ -157,7 +178,7 @@ flowchart LR
157
178
 
158
179
  ## 用对话驱动
159
180
 
160
- 四个模块(含实验性的骨骼动画)的**全部功能都能通过对话调用**。插件把整条流水线注册成
181
+ 六个模块(含实验性的骨骼动画、地图地块与地图编辑器)的**全部功能都能通过对话调用**。插件把整条流水线注册成
161
182
  `game_material_*` 工具,agent 能自己推进、等待、审查,也可以在每一步停下来让你验收。
162
183
 
163
184
  | 工具 | 作用 |
@@ -187,7 +208,7 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
187
208
  ```
188
209
 
189
210
  包已发布到 npm:[dsh-game-material-master](https://www.npmjs.com/package/dsh-game-material-master)
190
- (当前 `0.1.1`,`latest`)。本包没有运行时依赖,`dsh plugin add` 拉下来即可用。
211
+ (当前 `0.6.0`,`latest`)。本包没有运行时依赖,`dsh plugin add` 拉下来即可用。
191
212
 
192
213
  装完**重启 DSH**(宿主半区在启动时装入)。浏览器半区按磁盘上的 `lib/client.js` 现取,
193
214
  刷新浏览器即可生效。
@@ -207,19 +228,32 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
207
228
  | 项 | 说明 |
208
229
  |---|---|
209
230
  | 火山方舟 API Key | 「测试连接」会真实生成一张 1K 小图(少量费用),同时验证 Key 与模型 |
210
- | 生图模型 | 默认 `doubao-seedream-4-0-250828`,可切 4.5 / 5.0 Lite / Pro |
231
+ | 生图模型 | 默认 `doubao-seedream-5-0-flash-260915`,可切 5.0 Pro / Lite / 4.5 |
211
232
  | MiniMax API Key | 「测试连接」免费,能区分 Key 无效与其它错误 |
212
233
  | 视频模型 | 默认 `MiniMax-H3`(v2 协议);Hailuo / I2V 走 v1;优云智算版 H3 显式选择 |
213
234
  | Base URL | 主机根,不含 `/v1` `/v2`。国内 `api.minimax.cn`,国际 `api.minimaxi.com` |
214
235
  | 默认参数 | 单格宽高、抽帧张数、像素块边长、抠像阈值等 |
236
+ | 功能管理 | 逐个开关六个模块:关掉的模块界面上不再出现,**对话里的 AI 也调不到**(见下) |
215
237
 
216
238
  Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显始终脱敏。
217
239
  **模型是插件级设置,三个模块共用**,切换模型后任务自动对齐新档位。
218
240
 
241
+ ### 功能管理(隐藏不用的模块)
242
+
243
+ 不用的模块可以在**设置 → 游戏素材大师 → 功能管理**里关掉,随时再打开,已有项目数据不会删:
244
+
245
+ - **界面**:工作台页签、侧栏快捷菜单里都不再出现它;如果当时正停在这个模块,会自动落到第一个可见模块。
246
+ - **对话**:`game_material_call` / `status` / `intake` / `upload` / `wait` / `review` / `approve`
247
+ 一律拒绝,报错里说明去哪里打开。只藏界面不拦工具等于没藏——模型看不见页签,
248
+ 照样能调生成类方法真实计费,所以宿主半区每次都按最新配置再拦一次。
249
+ - 可见性**只能由用户在设置页里改**:工具面拒绝 `saveConfig({hiddenModules})`,
250
+ 否则模型能自己把隐藏的功能放出来。
251
+ - 全部关掉也是允许的,工作台会提示「所有功能都已被隐藏」。
252
+
219
253
  ## 界面语言
220
254
 
221
255
  **插件界面跟随 DSH 自身的语言设置**(设置 → 通用 → 语言),中文 / 英文都是一等公民,
222
- 切换**即时生效**、不用刷新页面:工作台标题、四个模块页签、每一张卡片的按钮、提示条、
256
+ 切换**即时生效**、不用刷新页面:工作台标题、六个模块页签、每一张卡片的按钮、提示条、
223
257
  弹窗与设置页全部跟着走。
224
258
 
225
259
  实现上不猜也不复制 DSH 的语言状态,而是接 DSH 的 `locale` 服务
@@ -233,7 +267,7 @@ Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显
233
267
  所以浏览器半区每次读项目、重置提示词时把当前语言一起带过去。
234
268
 
235
269
  范围说明:**多语言覆盖的是浏览器半区的界面文案与内置默认提示词**——工作台标题、
236
- 四个模块页签、每一张卡片的按钮与提示条、弹窗、设置页、验收控件、默认提示词。
270
+ 六个模块页签、每一张卡片的按钮与提示条、弹窗、设置页、验收控件、默认提示词。
237
271
  以下两类仍是中文,因为 DSH 目前只把 locale 服务提供给浏览器半区:
238
272
 
239
273
  - **运行日志里由宿主写入的行**(「开始生成「南 · 正对镜头」」「…生成完成,用时 12.3 秒」等)
@@ -257,7 +291,8 @@ Key 只写入本机 `<DSH_HOME>/game-material-master/config.json`,界面回显
257
291
  ├── image-jobs/<id>/ 图片生成
258
292
  ├── sequence-jobs/<id>/ 序列帧生成
259
293
  ├── rig-jobs/<id>/ 骨骼动画(实验性:sheet / parts / layout / rig / atlas)
260
- └── tile-jobs/<id>/ 地图地块(template / raw / cell / decor / map / export)
294
+ ├── tile-jobs/<id>/ 地图地块(template / raw / cell / decor / map / export)
295
+ └── map-jobs/<id>/ 地图编辑器(project.json / map.json / tilesets / preview / export)
261
296
  ```
262
297
 
263
298
  > 地图地块的 `raw/` 会**保留原始生成结果**:改了单元格尺寸之类的规整参数后,
@@ -314,6 +349,23 @@ T("第 {n0} 帧", { n0: index + 1 }) // 带插值,英
314
349
  - 也可以在 [GitHub Issues](https://github.com/universe-st/dsh-game-material-master/issues)
315
350
  提 issue 或直接发 PR。
316
351
 
352
+ ## 致谢
353
+
354
+ - **模块⑥「地图编辑器」借鉴了 [AsPJT/AsLib](https://github.com/AsPJT/AsLib/tree/master) 的 RPG Map Maker。**
355
+ 具体借鉴的是它的**交互与界面**(一屏:左边素材调色板 + 图标工具栏、右边画布;画笔 / 橡皮 / 油漆桶 /
356
+ 吸管 / 抓手 + 单层预览 + 图层上下 + 撤销重做这一组工具;点调色板选笔刷、红框标当前笔刷、
357
+ 滚轮缩放、拖动平移)和两处**几何约定**:
358
+ 1. **地图四周环绕** —— 自动连接的邻域判断取模,上下 / 左右两边接得上(数据层语义);
359
+ 相机被夹在地图内(拖到边就停、地图左上角与画布左上角对齐),图外不落笔;
360
+ 2. **A2 拼块自动连接** —— 一张 64×160 的图 = 2 变体 × 5 形状,一格拆成四个 16px 象限,
361
+ 每个象限按「左 / 上 / 左上」查同一张 5 状态表;小格的挑选公式,以及
362
+ 「1-based 序号 − 1 == AsLib 的 chip 下标」这条对应关系,都出自它的 `AsMap.hpp`。
363
+
364
+ 它的代码是 **CC0**;本插件是照它的行为用 TypeScript 重写的,**没有拷贝它的源码**。
365
+ - ⚠️ **AsLib 仓库里的 `Picture/MapChip/*_pipo.png` 素材属于第三方,没有打包进本插件**
366
+ (它的 README 写明 "Third party content is copyrighted by its respective owners")。
367
+ 内置素材由 `scripts/make-map-sample-tileset.mjs` 按同样的 A2 规格在本机程序化生成。
368
+
317
369
  ## 许可
318
370
 
319
371
  [MIT](LICENSE)
@@ -1,14 +1,17 @@
1
1
  /**
2
- * 地图地块模块的图像编解码与基础像素操作。
2
+ * 图像编解码与基础像素操作 —— **全插件共用**(原名 `tilemedia.ts`)。
3
3
  *
4
- * 这一层只做「字节 ↔ RGBA 缓冲区」和几个原语(PNG 头、颜色统计、菱形遮罩)。
5
- * 一切几何算法都在 `tilegeom.ts`,拼图在 `tilemap.ts`。
4
+ * 这一层只做「字节 ↔ RGBA 缓冲区」和几个与业务无关的原语
5
+ * (PNG 头、颜色统计、前景/背景掩码、包围盒)。地块几何在 `tilegeom.ts`、
6
+ * 拼图在 `tilemap.ts`、地图编辑器在 `mapgeom.ts` / `maprender.ts` ——
7
+ * 它们都只是这里的调用方,所以这个文件不叫 `tile*`。
6
8
  *
7
9
  * 为什么 PNG 解码走 ffmpeg:仓库**没有任何运行时依赖**(见 AGENTS.md),
8
10
  * 手写 PNG 解码器要处理 5 种 filter 类型,而 ffmpeg 已经是本插件的既有依赖
9
11
  * (抽帧、抠像都用它)。这里把调用集中成一个函数,以后要换只改一处。
10
12
  */
11
13
  import { spawn } from "node:child_process";
14
+ import { readFile } from "node:fs/promises";
12
15
  import { encodePng } from "./png.js";
13
16
  import { ffmpegPath } from "./media.js";
14
17
  /** PNG 头里的尺寸(不解码像素,用来做廉价校验)。 */
@@ -86,6 +89,21 @@ function runFfmpeg(args) {
86
89
  export async function decodeFile(file, maxEdge = 0) {
87
90
  return decodeImage(file, maxEdge);
88
91
  }
92
+ /**
93
+ * 只问尺寸、不要像素。
94
+ *
95
+ * PNG 直接读文件头(零成本);JPEG / WebP / GIF 让 ffmpeg 解一帧成 PNG 再读头。
96
+ * 图集导入只需要知道「几乘几」,为了这个把几千万像素全解出来是白等。
97
+ */
98
+ export async function probeImageSize(file) {
99
+ const head = await readFile(file).catch(() => undefined);
100
+ if (head !== undefined) {
101
+ const size = pngSize(head);
102
+ if (size !== undefined)
103
+ return size;
104
+ }
105
+ return probeDecodedSize(file, 0);
106
+ }
89
107
  /** 编码落盘用的 PNG 字节。 */
90
108
  export function encodeBitmap(bitmap) {
91
109
  return encodePng(bitmap.rgba, bitmap.width, bitmap.height);