dsh-game-material-master 0.10.2 → 0.11.1

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
@@ -12,7 +12,18 @@ third-party service.
12
12
  [![npm](https://img.shields.io/npm/v/dsh-game-material-master?color=blue)](https://www.npmjs.com/package/dsh-game-material-master)
13
13
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
14
14
 
15
- > **🆕 0.10.0 update**: the conversational surface is now a single **`game_material`** tool
15
+ > **🆕 0.11.0 update**: both map editors gain a full **Agent loop** — `mapInspect` / `isoInspect` read cells,
16
+ > objects, stamps, markers and passability by region, while `mapRender` / `isoRender` synchronously produce a
17
+ > **check image** (region crop, zoom, optional marker / grid / passability / outline overlays) and return a local
18
+ > absolute path for `read_image`. `applyMapOps` / `applyIsoOps` add **`dryRun`** (validate without writing) and
19
+ > **`ifRevision`** (reject stale writes instead of overwriting newer edits). Markers carry **kind / color / note /
20
+ > tags** (`marker update`; export formats move to `@5` / `@2`); stamps can be **moved / rotated**, the minimum
21
+ > footprint drops to **1×1**, and passability can be **repainted from the asset properties**; 45° objects can be
22
+ > **duplicated**; tile imports accept a **local path**; every project / task has a **Copy ID** button. Also fixes
23
+ > the multi-cell stamp brush leaking into marker / eraser tools. Wire methods 184 → **188**, new
24
+ > `verify-map-agent` self-check.
25
+ >
26
+ > **0.10.0 update**: the conversational surface is now a single **`game_material`** tool
16
27
  > (`action` picks `guide / intake / call / status / wait / review / approve / reviewMode / upload`).
17
28
  > The always-resident context drops from **49 KB to about 4 KB**; flows and method tables are loaded on demand
18
29
  > through `action:"guide"`. Module ⑤ is replaced by a fully local **45° isometric map editor** (2:1 diamonds,
@@ -342,7 +353,7 @@ not pay for them in context.
342
353
 
343
354
  | action | What it does |
344
355
  |---|---|
345
- | `guide` | Read the manual: `overview` / `workflow` / `config` / `methods` / `ai-asset` / eight module topics |
356
+ | `guide` | Read the manual: `overview` / `workflow` / `config` / `methods` / `ai-asset` / `map-agent` / eight module topics |
346
357
  | `intake` | **Step 0 of the fixed workflow**: nail down the key parameters and review mode before doing anything |
347
358
  | `call` | Universal channel: every remote method of the plugin is individually callable (`{method, payload}`) |
348
359
  | `upload` | Upload assets by local file path (character sheet / reference image / first and last frames / parts…) |
@@ -361,6 +372,14 @@ game_material({ action: "call", method: "runTurnVideo", payload: { projectId } }
361
372
  game_material({ action: "wait", module: "sprite", id: projectId })
362
373
  ```
363
374
 
375
+ The map editors also expose an Agent loop — inspect state, draw, render a check image, then read it:
376
+
377
+ ```js
378
+ game_material({ action: "call", method: "mapInspect", payload: { projectId, region: { r0: 0, c0: 0, r1: 16, c1: 16 } } })
379
+ game_material({ action: "call", method: "mapRender", payload: { projectId, region: { r0: 0, c0: 0, r1: 16, c1: 16 }, overlay: { markers: true, grid: true } } })
380
+ // pass the returned localPath to read_image; use isoInspect / isoRender for the 45° editor
381
+ ```
382
+
364
383
  The old per-tool registrations (`game_material_call` / `game_material_status` / …) have been merged into this single
365
384
  tool; see [docs/ENGINEERING.md](docs/ENGINEERING.md#对话调用agent-也能驱动整条流水线) for the migration mapping.
366
385
 
@@ -368,6 +387,9 @@ Review links are **deep links**: an `openUrl` posted by the agent in its reply t
368
387
  matching plugin page when clicked, landing on the right module / project / stage without any navigating
369
388
  on your part.
370
389
 
390
+ Every project / task header also has a **Copy ID** button (side-list rows show `⧉`); one click copies
391
+ the `projectId` / `jobId` to the clipboard so you can paste it to the agent.
392
+
371
393
  ---
372
394
 
373
395
  ## Installation
@@ -381,7 +403,7 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
381
403
  ```
382
404
 
383
405
  The package is published to npm: [dsh-game-material-master](https://www.npmjs.com/package/dsh-game-material-master)
384
- (currently `0.10.2`, `latest`). It has no runtime dependencies, so `dsh plugin add` is all you need.
406
+ (currently `0.11.0`, `latest`). It has no runtime dependencies, so `dsh plugin add` is all you need.
385
407
 
386
408
  **DSH version**: `>=0.2.0-rc.2 <0.3.0` (the `engines.dsh` field; since DSH 0.2.1 the plugin manager checks it first).
387
409
  When a Web deployment uses `--public-url https://host/prefix/`, deep links and asset URLs include that path prefix.
@@ -418,6 +440,8 @@ installation tree.
418
440
  | MiniMax API Key | "Test connection" is free and can tell an invalid key apart from other errors |
419
441
  | Video model | Defaults to `MiniMax-H3` (v2 protocol); Hailuo / I2V use v1; the UCloud version of H3 is selected explicitly |
420
442
  | Base URL | Host root, without `/v1` or `/v2`. `api.minimax.cn` in mainland China, `api.minimaxi.com` internationally |
443
+ | Output size | Shared by every image-generating module; accepts `1K` / `2K` / `4K` or `width x height`. Enter explicit pixels (for example 1024x1024) to pin the output |
444
+ | Key background color | Pure green `#00FF00` by default; switch to magenta / blue / white / black when the character wears green. "Green screen / #00FF00" in generated prompts is replaced accordingly, and every keying entry can pick its own color |
421
445
  | Default parameters | Cell width and height, frame count, pixel block size, keying threshold, and so on |
422
446
  | Local ComfyUI (image-to-video) | Routes image-to-video through a local **ComfyUI** instead of MiniMax; "Test connection" is read-only and free |
423
447
  | Music generation (Puyue AI) | Puyue AI API key, base URL, default music model and timeouts; "Test connection" reads one page of history and does not generate anything (no generation credits). Generation is billed by platform credits; the plugin does not collect payment |
package/README.md CHANGED
@@ -10,7 +10,14 @@
10
10
  [![npm](https://img.shields.io/npm/v/dsh-game-material-master?color=blue)](https://www.npmjs.com/package/dsh-game-material-master)
11
11
  [![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
12
12
 
13
- > **🆕 0.10.0 更新**:对话工具面收成一个 **`game_material`**(`action` 选 `guide / intake / call / status /
13
+ > **🆕 0.11.0 更新**:两套地图编辑器补上 **Agent 闭环** —— `mapInspect` / `isoInspect` 按区域读逐格、物件、整图、标记与通行性,
14
+ > `mapRender` / `isoRender` 同步出**检查图**(区域裁切、放大、可叠标记 / 网格 / 通行性 / 轮廓,返回本机绝对路径交给 `read_image`);
15
+ > `applyMapOps` / `applyIsoOps` 新增 **`dryRun`**(只校验不写盘)与 **`ifRevision`**(旧版本直接拒绝,防覆盖)。
16
+ > 标记可带 **类型 / 颜色 / 备注 / 标签**(`marker update`,导出格式升到 `@5` / `@2`);整图支持**移动 / 旋转**、最小占格放宽到 **1×1**,
17
+ > 素材属性里可**重画通行区域**;45° 物件可**复制**;导入素材支持直接传**本机路径**;所有项目 / 任务都能**一键复制 ID**。
18
+ > 另外修掉「整图多格笔刷被标记 / 橡皮借用」的问题。wire 方法 184 → **188**,新增自检 `verify-map-agent`。
19
+ >
20
+ > **0.10.0 更新**:对话工具面收成一个 **`game_material`**(`action` 选 `guide / intake / call / status /
14
21
  > wait / review / approve / reviewMode / upload`),常驻上下文从 **49 KB 降到约 4 KB**,流程与方法表改成按需读手册;
15
22
  > 模块⑤换成**全本地的 45° 地图编辑器**(2:1 等距、4×4 自动连接、多格 / 高处物件、动画地块、标记层、环绕、
16
23
  > 一键生成;还能「**AI 生成素材**」:自动开对话生成,整理好回链到「新增素材」确认导入);
@@ -282,7 +289,7 @@ flowchart LR
282
289
 
283
290
  | action | 作用 |
284
291
  |---|---|
285
- | `guide` | 读手册:`overview` / `workflow` / `config` / `methods` / `ai-asset` / 八个模块主题 |
292
+ | `guide` | 读手册:`overview` / `workflow` / `config` / `methods` / `ai-asset` / `map-agent` / 八个模块主题 |
286
293
  | `intake` | **固定流程第 0 步**:先把关键参数与审核模式问清楚,再动手 |
287
294
  | `call` | 万能通道:插件全部远程方法逐个可调(`{method, payload}`) |
288
295
  | `upload` | 按本机文件路径上传素材(设定图 / 参考图 / 首尾帧 / 部件…) |
@@ -301,12 +308,23 @@ game_material({ action: "call", method: "runTurnVideo", payload: { projectId } }
301
308
  game_material({ action: "wait", module: "sprite", id: projectId })
302
309
  ```
303
310
 
311
+ 地图编辑器还支持 Agent 专用的「读状态 → 画 → 看效果图」闭环:
312
+
313
+ ```js
314
+ game_material({ action: "call", method: "mapInspect", payload: { projectId, region: { r0: 0, c0: 0, r1: 16, c1: 16 } } })
315
+ game_material({ action: "call", method: "mapRender", payload: { projectId, region: { r0: 0, c0: 0, r1: 16, c1: 16 }, overlay: { markers: true, grid: true } } })
316
+ // 把返回的 localPath 交给 read_image;iso 用 isoInspect / isoRender
317
+ ```
318
+
304
319
  旧版按 `game_material_call` / `game_material_status` / … 逐个注册的工具已经合并到上面这一个工具,
305
320
  迁移对照见 [docs/ENGINEERING.md](docs/ENGINEERING.md#对话调用agent-也能驱动整条流水线)。
306
321
 
307
322
  验收链接是**深链接**:agent 在回复里贴出的 `openUrl` 点一下就切到插件对应页面,原地落到
308
323
  对应模块 / 项目 / 阶段上,不需要你自己翻。
309
324
 
325
+ 每个模块的项目 / 任务标题旁都有「**复制 ID**」按钮(侧栏项目行里还有 `⧉`),点一下就把
326
+ `projectId` / `jobId` 复制到剪贴板,直接粘贴给 agent 即可。
327
+
310
328
  ---
311
329
 
312
330
  ## 安装
@@ -320,7 +338,7 @@ dsh plugin --profile web add /path/to/dsh-game-material-master
320
338
  ```
321
339
 
322
340
  包已发布到 npm:[dsh-game-material-master](https://www.npmjs.com/package/dsh-game-material-master)
323
- (当前 `0.10.2`,`latest`)。本包没有运行时依赖,`dsh plugin add` 拉下来即可用。
341
+ (当前 `0.11.0`,`latest`)。本包没有运行时依赖,`dsh plugin add` 拉下来即可用。
324
342
 
325
343
  **DSH 版本**:`>=0.2.0-rc.2 <0.3.0`(`package.json` 的 `engines.dsh`;DSH 0.2.1 起插件管理器优先按它判断兼容性)。
326
344
  Web 部署用 `--public-url https://host/prefix/` 时,深链接与产物地址会跟着补路径前缀。
@@ -353,6 +371,8 @@ Windows 注册表里的同名变量 → WinGet / Scoop / Chocolatey 与 `C:\ffmp
353
371
  | MiniMax API Key | 「测试连接」免费,能区分 Key 无效与其它错误 |
354
372
  | 视频模型 | 默认 `MiniMax-H3`(v2 协议);Hailuo / I2V 走 v1;优云智算版 H3 显式选择 |
355
373
  | Base URL | 主机根,不含 `/v1` `/v2`。国内 `api.minimax.cn`,国际 `api.minimaxi.com` |
374
+ | 输出尺寸 | 所有生图模块共用;支持 `1K` / `2K` / `4K` 或 `宽x高`。要固定像素(例如永远 1024×1024)就直接填宽高 |
375
+ | 抠像背景色 | 默认纯绿 `#00FF00`;角色穿绿衣服时改成品红 / 蓝 / 白 / 黑等。生成提示词里的「绿幕 / #00FF00」会跟着替换,所有抠像入口都能单独选 |
356
376
  | 默认参数 | 单格宽高、抽帧张数、像素块边长、抠像阈值等 |
357
377
  | 本地 ComfyUI(图生视频) | 勾选后图生视频改走**本机 ComfyUI**,替代 MiniMax;「测试连接」只读状态、免费 |
358
378
  | 音乐生成(谱乐 AI) | 填谱乐 AI API Key、Base URL、默认音乐模型与超时;「测试连接」读一页历史,不产生生成费用。生成按平台积分计费,插件不代收 |
package/lib/chroma.js CHANGED
@@ -23,7 +23,9 @@
23
23
  * 基线上;再按盒式平均重采样到目标尺寸,最后量化成 pixelSize 的方块。
24
24
  */
25
25
  import { encodePng } from "./png.js";
26
+ import { DEFAULT_KEY_COLOR, isGreenKeyColor, keyColorRgb, keyDominantChannels, normalizeKeyColor } from "./keycolor.js";
26
27
  export const DEFAULT_KEY_OPTIONS = {
28
+ keyColor: DEFAULT_KEY_COLOR,
27
29
  keyLow: 14,
28
30
  keyHigh: 80,
29
31
  despill: 0.65,
@@ -269,11 +271,27 @@ export function segmentBackgroundDetailed(rgba, width, height, globalTolerance,
269
271
  }
270
272
  return { mask: background, samples: built.samples, kept: built.kept, dropped: built.dropped };
271
273
  }
274
+ /** 两个像素到某个背景色的 RGB 距离。 */
275
+ function keyDistance(rgba, offset, key) {
276
+ const dr = rgba[offset] - key.r;
277
+ const dg = rgba[offset + 1] - key.g;
278
+ const db = rgba[offset + 2] - key.b;
279
+ return Math.sqrt(dr * dr + dg * dg + db * db);
280
+ }
272
281
  /** 没启用空间分割时,用颜色判据粗略估一个背景占比,供界面判断可信度。 */
273
- function countGreenBackground(rgba, high) {
282
+ function countKeyBackground(rgba, high, keyColor) {
283
+ const key = keyColorRgb(keyColor);
284
+ const green = isGreenKeyColor(keyColor);
274
285
  let count = 0;
286
+ if (green) {
287
+ for (let p = 0; p < rgba.length; p += 4) {
288
+ if (rgba[p + 1] - Math.max(rgba[p], rgba[p + 2]) >= high)
289
+ count++;
290
+ }
291
+ return count;
292
+ }
275
293
  for (let p = 0; p < rgba.length; p += 4) {
276
- if (rgba[p + 1] - Math.max(rgba[p], rgba[p + 2]) >= high)
294
+ if (keyDistance(rgba, p, key) <= high)
277
295
  count++;
278
296
  }
279
297
  return count;
@@ -283,6 +301,10 @@ function countGreenBackground(rgba, high) {
283
301
  * 输入输出都是 `width * height * 4` 字节、非预乘 alpha。
284
302
  */
285
303
  export function keyGreen(rgba, width, height, options) {
304
+ const keyColor = normalizeKeyColor(options.keyColor ?? DEFAULT_KEY_COLOR);
305
+ const key = keyColorRgb(keyColor);
306
+ const greenMode = isGreenKeyColor(keyColor);
307
+ const dominant = keyDominantChannels(keyColor);
286
308
  const low = Math.max(0, Math.min(255, options.keyLow));
287
309
  const high = Math.max(low + 1, Math.min(255, options.keyHigh));
288
310
  const span = high - low;
@@ -315,33 +337,70 @@ export function keyGreen(rgba, width, height, options) {
315
337
  const g = rgba[p + 1];
316
338
  const b = rgba[p + 2];
317
339
  const srcAlpha = rgba[p + 3];
318
- const other = r > b ? r : b;
319
- const greenness = g - other;
320
340
  let alpha = 1;
321
- if (greenness >= high)
322
- alpha = 0;
323
- else if (greenness > low)
324
- alpha = 1 - (greenness - low) / span;
341
+ if (greenMode) {
342
+ const other = r > b ? r : b;
343
+ const greenness = g - other;
344
+ if (greenness >= high)
345
+ alpha = 0;
346
+ else if (greenness > low)
347
+ alpha = 1 - (greenness - low) / span;
348
+ }
349
+ else {
350
+ const distance = keyDistance(rgba, p, key);
351
+ if (distance >= high)
352
+ alpha = 1;
353
+ else if (distance > low)
354
+ alpha = (distance - low) / span;
355
+ else
356
+ alpha = 0;
357
+ }
325
358
  alpha *= srcAlpha / 255;
326
- // 空间上确认为背景的像素直接全透明;颜色判据只负责前景里的绿色残余。
359
+ // 空间上确认为背景的像素直接全透明;颜色判据只负责前景里的残余色边。
327
360
  if (background !== undefined && background[i] === 1)
328
361
  alpha = 0;
362
+ let outR = r;
329
363
  let outG = g;
330
- if (despill > 0 && g > other) {
364
+ let outB = b;
365
+ if (despill > 0) {
331
366
  const weight = despill * (1 - alpha);
332
- if (weight > 0)
333
- outG = Math.round(g - (g - other) * weight);
367
+ if (weight > 0) {
368
+ if (greenMode) {
369
+ const other = r > b ? r : b;
370
+ if (g > other)
371
+ outG = Math.round(g - (g - other) * weight);
372
+ }
373
+ else if (dominant.length > 0) {
374
+ const others = [0, 1, 2].filter((channel) => !dominant.includes(channel));
375
+ const values = [r, g, b];
376
+ const otherMax = others.length === 0 ? 0 : Math.max(...others.map((channel) => values[channel]));
377
+ for (const channel of dominant) {
378
+ const value = values[channel];
379
+ const excess = value - otherMax;
380
+ if (excess <= 0)
381
+ continue;
382
+ const next = Math.round(value - excess * weight);
383
+ if (channel === 0)
384
+ outR = next;
385
+ else if (channel === 1)
386
+ outG = next;
387
+ else
388
+ outB = next;
389
+ }
390
+ }
391
+ }
334
392
  }
335
- out[p] = r;
393
+ out[p] = outR;
336
394
  out[p + 1] = outG;
337
- out[p + 2] = b;
395
+ out[p + 2] = outB;
338
396
  out[p + 3] = Math.round(alpha * 255);
339
397
  }
340
398
  if (options.edgeShrink > 0)
341
399
  shrinkAlpha(out, width, height, Math.min(8, Math.round(options.edgeShrink)));
342
400
  return {
343
401
  rgba: out,
344
- backgroundFraction: background !== undefined ? backgroundCount / pixels : countGreenBackground(rgba, high) / pixels,
402
+ keyColor,
403
+ backgroundFraction: background !== undefined ? backgroundCount / pixels : countKeyBackground(rgba, high, keyColor) / pixels,
345
404
  usedSegmentation: background !== undefined,
346
405
  borderSamples,
347
406
  borderSamplesDropped