dsh-game-material-master 0.4.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/lib/tools.js CHANGED
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * | 工具 | 作用 |
10
10
  * |---|---|
11
- * | `game_material_call` | 万能通道:45 个远程方法逐个可调,覆盖全部功能 |
11
+ * | `game_material_call` | 万能通道:插件全部远程方法逐个可调,覆盖全部功能 |
12
12
  * | `game_material_status` | 读一眼当前进度(项目 / 任务 / 阶段 / 是否有任务在跑) |
13
13
  * | `game_material_wait` | 阻塞等待到「没有任务在跑」或超时,回来就是可审查状态 |
14
14
  * | `game_material_review` | 出一个**验收包**:每个产物的绝对 URL、状态、通过标记、深链接 |
@@ -32,6 +32,8 @@ import { listImageJobs, readImageJob, sniffImage } from "./imagegen.js";
32
32
  import { listSequenceJobs, readSequenceJob, listSequenceTasks } from "./seqgen.js";
33
33
  import { listRigJobs, readRigJob, rigSnapshot } from "./riggen.js";
34
34
  import { listTileProjects, readTileProject, tileSnapshot } from "./tilegen.js";
35
+ import { listMapProjects, mapSnapshot, readMapProject } from "./mapgen.js";
36
+ import { MAP_STAGES } from "./links.js";
35
37
  import { TOOL_METHODS } from "./wire.js";
36
38
  import { PANEL_KEY, STUDIO_MODULES, buildOpenLink, originForLinks } from "./links.js";
37
39
  import { loadConfig } from "./config.js";
@@ -48,7 +50,8 @@ export const MODULE_LABELS = {
48
50
  image: "图片生成",
49
51
  sequence: "序列帧生成",
50
52
  rig: "骨骼动画生成",
51
- tile: "45°地图地块生成"
53
+ tile: "45°地图地块生成",
54
+ map: "地图编辑器(导入 tileset)"
52
55
  };
53
56
  /**
54
57
  * 远程方法 → 它属于哪个模块。
@@ -167,7 +170,28 @@ export const METHOD_MODULE = {
167
170
  saveTileMapCells: "tile",
168
171
  runTileExport: "tile",
169
172
  cancelTileJob: "tile",
170
- revealTileProject: "tile"
173
+ revealTileProject: "tile",
174
+ // 模块六 地图编辑器(单项目 = 单张地图,全本地零计费)
175
+ listMapProjects: "map",
176
+ createMapProject: "map",
177
+ getMapProject: "map",
178
+ saveMapProject: "map",
179
+ deleteMapProject: "map",
180
+ importMapTileset: "map",
181
+ importSampleTileset: "map",
182
+ saveMapTileset: "map",
183
+ removeMapTileset: "map",
184
+ saveMapDoc: "map",
185
+ applyMapOps: "map",
186
+ mapUndo: "map",
187
+ mapRedo: "map",
188
+ mapPlan: "map",
189
+ runMapGenerate: "map",
190
+ runMapPreview: "map",
191
+ runMapExport: "map",
192
+ cancelMapJob: "map",
193
+ setMapApproved: "map",
194
+ revealMapProject: "map"
171
195
  };
172
196
  /**
173
197
  * 不隶属于任何模块的方法:配置类 + 跨模块的审核模式
@@ -229,7 +253,7 @@ const clampInt = (value, fallback, min, max) => {
229
253
  function moduleOf(value) {
230
254
  return typeof value === "string" && MODULES.includes(value) ? value : undefined;
231
255
  }
232
- /** 任务 id 前缀决定它属于哪个模块(p… / i… / s… / r… / t…)。 */
256
+ /** 任务 id 前缀决定它属于哪个模块(p… / i… / s… / r… / t… / m…)。 */
233
257
  export function moduleForId(id) {
234
258
  if (/^p[a-z0-9]+$/.test(id))
235
259
  return "sprite";
@@ -241,6 +265,8 @@ export function moduleForId(id) {
241
265
  return "rig";
242
266
  if (/^t[a-z0-9]+$/.test(id))
243
267
  return "tile";
268
+ if (/^m[a-z0-9]+$/.test(id))
269
+ return "map";
244
270
  return undefined;
245
271
  }
246
272
  /** 产物相对路径 → 浏览器可直接打开的绝对 URL。 */
@@ -500,6 +526,12 @@ async function snapshotOf(module, id) {
500
526
  throw new Error(`找不到地图地块项目:${id}`);
501
527
  return tileSnapshot(project, originForLinks());
502
528
  }
529
+ if (module === "map") {
530
+ const project = await readMapProject(id);
531
+ if (project === undefined)
532
+ throw new Error(`找不到地图项目:${id}`);
533
+ return mapSnapshot(project, originForLinks());
534
+ }
503
535
  const job = await readRigJob(id);
504
536
  if (job === undefined)
505
537
  throw new Error(`找不到骨骼动画任务:${id}`);
@@ -534,6 +566,20 @@ function intentFromCall(method, payload) {
534
566
  const projectId = asString(payload.projectId);
535
567
  const jobId = asString(payload.jobId);
536
568
  const stage = typeof payload.stage === "string" ? payload.stage : undefined;
569
+ /**
570
+ * ⚠️ **先按方法名认模块,再看字段名。**
571
+ *
572
+ * 以前是先判 `payload.projectId` 非空就当八方向图 —— 于是模块二/三/四/五/六里
573
+ * 凡是入参叫 `projectId` 的方法(`runTileMap`、`getMapProject`、`saveMapDoc`…)
574
+ * 返回的 openUrl 全都指向 `module=sprite&project=<别人的 id>`,用户点进去落在
575
+ * 八方向图页面上,看着就是「链接是坏的」。字段名靠不住,方法归属才是真源
576
+ * (`METHOD_MODULE`),非 sprite 模块的 id 一律放 `jobId`(宿主 `intentOf` 的约定)。
577
+ */
578
+ const owner = METHOD_MODULE[method];
579
+ if (owner !== undefined && owner !== "sprite") {
580
+ const targetId = projectId !== "" ? projectId : jobId;
581
+ return targetId === "" ? { module: owner } : { module: owner, jobId: targetId, stage };
582
+ }
537
583
  if (projectId !== "") {
538
584
  const framePick = method === "prepareFramePick" || method === "setFramePick" || method === "setFramePicks" || method === "resetFramePicks";
539
585
  return { module: "sprite", projectId, stage: framePick ? "frames" : stage };
@@ -546,6 +592,8 @@ function intentFromCall(method, payload) {
546
592
  return { module: "rig" };
547
593
  if (method.startsWith("listTileProject") || method.startsWith("createTileProject"))
548
594
  return { module: "tile" };
595
+ if (method.startsWith("listMapProject") || method.startsWith("createMapProject"))
596
+ return { module: "map" };
549
597
  if (method.startsWith("listImageJob") || method.startsWith("createImageJob"))
550
598
  return { module: "image" };
551
599
  if (method.startsWith("listSequenceJob") || method.startsWith("createSequenceJob"))
@@ -606,6 +654,18 @@ const CALL_DESCRIPTION = [
606
654
  " ★ 四个阶段:generate → review → map → export。**没有「先做模板」这一步** —— 等距参考图在 runTileItems 开始时",
607
655
  " 按各建筑地块的占格形状自动渲染(形状 / 格子尺寸没变就直接复用,免费、不额外调用)。",
608
656
  " ★ 几何交给代码、内容交给 AI:参考图由本机渲染,AI 只填菱形内部;生成后本地量一次、仿射对齐回标准菱形。",
657
+ "地图编辑器(模块六,**全本地、零计费**;导入自己的素材图,四步:素材图 → 自动连接 → 环绕画布 → 导出 PNG/存档):",
658
+ " listMapProjects() / createMapProject({name,grid?,cols?,rows?}) / getMapProject({projectId,lang?}) / saveMapProject({projectId,name}) / deleteMapProject({projectId}) /",
659
+ " importMapTileset({projectId,name,data:素材图base64,cell?,shape?,animRows?})【新增素材:属性这一下就定死,之后只能删掉重来;cell/shape/animRows 留空 = 自动识别】/ importSampleTileset({projectId})【内置素材:本机现算、零成本,4 张自动连接图 + 1 张道具图;属性不可改、可删、可一键恢复】/",
660
+ " saveMapTileset({projectId,tilesetId,name?,cell?,shape?,animRows?})【形态由尺寸自动识别,改形态/删素材会让图块序号平移,宿主按「素材 id + 图块 id」自动重新映射每格】/ removeMapTileset({projectId,tilesetId}) /",
661
+ " saveMapDoc({projectId,name?,cols?,rows?,layers?,addLayer?,removeLayerId?,moveLayer?,clearLayerId?,wrap?})【地图只有一张:改尺寸/图层/环绕都走它】/",
662
+ " applyMapOps({projectId,ops,stroke?,have?})【★ agent 也能画:ops = [{kind:'paint',layerId,cells:[{r,c,tile}]}, {kind:'fill',layerId,r,c,tile}, {kind:'rect',layerId,r0,c0,r1,c1,tile,filled}, {kind:'replace',layerId,from,to}];tile 取 getMapProject 的 view.tilesets[].palette[].index(1 起,0 = 空)。have = 界面已有的 chunk key,宿主只回真正失效的 dropKeys】/",
663
+ " mapUndo({projectId,have?}) / mapRedo({projectId,have?})【宿主持撤销栈,界面不用管】/ mapPlan({projectId,view:{x,y,width,height},have?,layerIds?})【绘制计划:每项 = {l 层, r,c 格号, t 图块序号, x,y 目标像素, a 不透明度, cycle? 动画帧序},界面画布与导出 PNG 执行同一份】/",
664
+ " runMapGenerate({projectId,kind:'random'|'maze'|'continent',tiles?,seed?,layerId?})【一键铺满:整层一次提交、一次撤销;同种子逐字节可复现】/",
665
+ " runMapPreview({projectId})【验收预览图 preview/map.png】/ runMapExport({projectId,scale?,formats?})【formats = {png?,json?,tilesets?,zip?}:默认 png+json,**产物超过一个自动打一个 zip**(zip:false 关掉);tilesets:true 会把素材原图一起拷进 tilesets/,整包自包含;manifest.json 是我们自己的账本】/",
666
+ " cancelMapJob({projectId}) / setMapApproved({projectId,stage?,approved})【stage 空 = 四阶段全打】/ revealMapProject({projectId,target?})【target:'export' 打开导出目录,省略 = 项目目录】",
667
+ " ★ 四个阶段:素材(assets)→ 自动连接(rules,宿主自动完成、界面不显示)→ 地图(paint)→ 导出(export)。**没有任何一步需要 API Key**。",
668
+ " ★ 地图四周**环绕**:视口范围可以越出边界,宿主会把这些格子映射回图内;一张地图就一个 `map.json`,没有多地图。",
609
669
  " 生成的几何报告看 game_material_review 返回的 variants[].geomMode —— measured 是量测成功,template 是回退模板几何。",
610
670
  " 出现 template 多半是模型不对:必须用 Seedream 5.0 系列;4.0 会把 2:1 等距菱形画成近正方形(实测比例 1.058)。",
611
671
  "说明:key 是方向英文字面量(front/back/downLeft/downRight/upLeft/upRight/left/right);data 是原始文件字节的 base64(不带 data: 前缀);",
@@ -713,12 +773,13 @@ export function registerStudioTools(host, gateway) {
713
773
  if (id === "") {
714
774
  // 只列可见模块的清单:隐藏的模块连「有哪些项目」都不给模型看一眼。
715
775
  await assertModuleVisible(moduleOf(args?.module));
716
- const [projects, images, sequences, rigs, tiles] = await Promise.all([
776
+ const [projects, images, sequences, rigs, tiles, maps] = await Promise.all([
717
777
  hidden.has("sprite") ? [] : listProjects(),
718
778
  hidden.has("image") ? [] : listImageJobs(),
719
779
  hidden.has("sequence") ? [] : listSequenceJobs(),
720
780
  hidden.has("rig") ? [] : listRigJobs(),
721
- hidden.has("tile") ? [] : listTileProjects()
781
+ hidden.has("tile") ? [] : listTileProjects(),
782
+ hidden.has("map") ? [] : listMapProjects()
722
783
  ]);
723
784
  const links = {};
724
785
  for (const key of MODULES)
@@ -732,8 +793,9 @@ export function registerStudioTools(host, gateway) {
732
793
  sequenceJobs: sequences,
733
794
  rigJobs: rigs,
734
795
  tileProjects: tiles,
796
+ mapProjects: maps,
735
797
  links,
736
- hint: "用 game_material_status({module,id}) 看某个目标的细节;八方向图的四步是 images → videos → frames → sheet,45°地图地块是 generate → review → map → export。"
798
+ hint: "用 game_material_status({module,id}) 看某个目标的细节;八方向图的四步是 images → videos → frames → sheet,45°地图地块是 generate → review → map → export,地图编辑器是 assets(素材)→ rules(自动连接)→ paint(地图)→ export(导出),全本地不花钱。"
737
799
  };
738
800
  }
739
801
  // ⚠️ 这里**不能**再按 module 短路:`status({module:'tile', id})` 也走到这里,
@@ -794,7 +856,7 @@ export function registerStudioTools(host, gateway) {
794
856
  "把本机文件上传进「游戏素材大师」——界面上那些「上传」框的对话等价物。",
795
857
  "参数 `path` 是文件的绝对路径或相对当前工作目录的路径,宿主自己读盘,**不要把 base64 贴进来**。",
796
858
  "kind 取值:sprite=source(源设定图);image=ref(参考图,最多 10 张)| item(直接加一张图,只做抠像用);",
797
- "sequence=firstFrame | lastFrame | referenceImage | referenceVideo;rig=source(角色整图)| part(单个部件 PNG,文件名即部件名)。",
859
+ "sequence=firstFrame | lastFrame | referenceImage | referenceVideo;rig=source(角色整图)| part(单个部件 PNG,文件名即部件名);map=tileset(图集原图)。",
798
860
  "限制:图片 ≤30MB,参考视频 ≤40MB(平台请求体上限 64MB),图片类型按文件头嗅探。"
799
861
  ].join("\n"),
800
862
  parameters: {
@@ -803,7 +865,7 @@ export function registerStudioTools(host, gateway) {
803
865
  properties: {
804
866
  module: { type: "string", enum: [...MODULES], description: "目标所属模块。" },
805
867
  id: { type: "string", description: "项目 id(p…)或任务 id(i… / s…)。" },
806
- kind: { type: "string", enum: ["source", "ref", "item", "firstFrame", "lastFrame", "referenceImage", "referenceVideo", "part"], description: "上传到哪个槽位。" },
868
+ kind: { type: "string", enum: ["source", "ref", "item", "firstFrame", "lastFrame", "referenceImage", "referenceVideo", "part", "tileset"], description: "上传到哪个槽位。" },
807
869
  path: { type: "string", description: "本机文件路径。" },
808
870
  name: { type: "string", description: "可选:展示用的文件名。" }
809
871
  },
@@ -912,7 +974,11 @@ export function registerStudioTools(host, gateway) {
912
974
  properties: {
913
975
  module: { type: "string", enum: [...MODULES], description: "目标所属模块;可省略,按 id 前缀判断。" },
914
976
  id: { type: "string", description: "项目 id(p…)/ 图片任务 id(i…)/ 序列帧任务 id(s…)。" },
915
- stage: { type: "string", enum: ["images", "videos", "frames", "sheet", "parts", "layout", "rig", "atlas"], description: "八方向图 / 骨骼动画专用:只看某一个阶段。" },
977
+ stage: {
978
+ type: "string",
979
+ enum: ["images", "videos", "frames", "sheet", "generate", "review", "map", "export", "parts", "layout", "rig", "atlas", ...MAP_STAGES],
980
+ description: "八方向图 / 地图地块 / 地图编辑器 / 骨骼动画专用:只看某一个阶段。"
981
+ },
916
982
  direction: { type: "string", description: "八方向图专用:只看某一个方位(front/back/…)。" },
917
983
  index: { type: "integer", description: "图片任务专用:只看第几张(从 0 开始)。" },
918
984
  step: { type: "string", enum: ["video", "frames", "sheet"], description: "序列帧任务专用:只看某一步。" }
@@ -968,6 +1034,32 @@ export function registerStudioTools(host, gateway) {
968
1034
  packet.steps = steps;
969
1035
  packet.nextActions = sequenceNextActions(snapshot);
970
1036
  }
1037
+ else if (module === "map") {
1038
+ const mapStages = snapshot.stages;
1039
+ const stageKeys = Object.keys(mapStages ?? {});
1040
+ if (stage !== undefined && !stageKeys.includes(stage)) {
1041
+ throw new Error(`未知阶段:${stage}(可选:${stageKeys.join(" / ")})`);
1042
+ }
1043
+ packet.stages = stageKeys
1044
+ .filter((key) => stage === undefined || key === stage)
1045
+ .map((key) => ({ stage: key, ...mapStages[key] }));
1046
+ packet.grid = snapshot.grid;
1047
+ packet.cols = snapshot.cols;
1048
+ packet.rows = snapshot.rows;
1049
+ // 素材带**绝对 URL**(模型要直接贴给用户点);调色板也跟着给,方便「让 agent
1050
+ // 自己画一张」时挑序号。
1051
+ packet.tilesets = snapshot.tilesets;
1052
+ packet.layers = snapshot.layers;
1053
+ packet.filled = snapshot.filled;
1054
+ packet.preview = snapshot.previewUrls;
1055
+ packet.previewUrls = snapshot.previewUrls;
1056
+ packet.exportBaseUrl = snapshot.exportBaseUrl;
1057
+ packet.exportFiles = snapshot.exportFiles;
1058
+ /** 导出目录的**绝对路径**(还没导出过 = 空串):产物埋在 DSH_HOME 底下,模型直接报路径比让用户找方便。 */
1059
+ packet.exportPath = snapshot.exportPath;
1060
+ packet.warnings = [...(snapshot.warnings ?? []), ...(snapshot.exportWarnings ?? [])];
1061
+ packet.nextActions = (snapshot.nextActions ?? []).map((action) => `${action.step}:${action.why}`);
1062
+ }
971
1063
  else if (module === "tile") {
972
1064
  // ⚠️ 地图地块的 `stages` 是**对象**({generate, review, map, export}),
973
1065
  // 不是数组。之前它掉进了 `else`(骨骼动画)分支,那边无条件当成数组用
@@ -1023,7 +1115,8 @@ export function registerStudioTools(host, gateway) {
1023
1115
  "八方向图:module=sprite,id=项目 id,stage=images|videos|frames|sheet,key 可只对某个方位生效(省略即整阶段)。",
1024
1116
  "图片任务:module=image,id=任务 id,index 可只对某一张生效(省略即全任务)。",
1025
1117
  "序列帧:module=sequence,id=任务 id,step=video|frames|sheet(省略即全部三步)。",
1026
- "骨骼动画:module=rig,id=任务 id,stage=parts|layout|rig|atlas(省略即四个阶段全打);stage=parts 时可再带 part 只对某个部件生效。"
1118
+ "骨骼动画:module=rig,id=任务 id,stage=parts|layout|rig|atlas(省略即四个阶段全打);stage=parts 时可再带 part 只对某个部件生效。",
1119
+ "地图编辑器:module=map,id=项目 id,stage=assets|rules|paint|export(省略即四个阶段全打)。这条链路全本地,打勾只是记录「这步看过了」。"
1027
1120
  ].join("\n"),
1028
1121
  parameters: {
1029
1122
  type: "object",
@@ -1031,7 +1124,7 @@ export function registerStudioTools(host, gateway) {
1031
1124
  properties: {
1032
1125
  module: { type: "string", enum: [...MODULES], description: "目标所属模块;可省略,按 id 前缀判断。" },
1033
1126
  id: { type: "string", description: "项目 / 任务 id。" },
1034
- stage: { type: "string", enum: ["images", "videos", "frames", "sheet"], description: "八方向图:阶段。" },
1127
+ stage: { type: "string", enum: ["images", "videos", "frames", "sheet", ...MAP_STAGES], description: "八方向图 / 地图编辑器:阶段。" },
1035
1128
  key: { type: "string", description: "八方向图:只对某个方位生效(front/back/…)。" },
1036
1129
  index: { type: "integer", description: "图片任务:只对某一张生效。" },
1037
1130
  step: { type: "string", enum: ["video", "frames", "sheet"], description: "序列帧:只对某一步生效。" },
@@ -1072,6 +1165,14 @@ export function registerStudioTools(host, gateway) {
1072
1165
  await gateway.saveImageJob(index === undefined ? { jobId: id, approved } : { jobId: id, approved, index });
1073
1166
  return { module, id, index: index ?? null, approved, count: targets.length, ...openInfo({ module: "image", jobId: id }, "点开看验收结果") };
1074
1167
  }
1168
+ if (module === "map") {
1169
+ const stage = asString(args?.stage) || undefined;
1170
+ if (stage !== undefined && !MAP_STAGES.includes(stage))
1171
+ throw new Error(`未知阶段:${stage}(可选:${MAP_STAGES.join(" / ")})`);
1172
+ // 单项目 = 单张地图:没有 mapId 这个维度了(打勾永远打整个项目)。
1173
+ await gateway.setMapApproved({ projectId: id, stage, approved });
1174
+ return { module, id, stage: stage ?? null, approved, ...openInfo({ module: "map", jobId: id, stage }, "点开看验收结果") };
1175
+ }
1075
1176
  if (module === "tile") {
1076
1177
  const key = asString(args?.key) || undefined;
1077
1178
  const variant = args?.variant === undefined ? undefined : clampInt(args.variant, 0, 0, 99);
@@ -1279,6 +1380,24 @@ function intakeFor(module, id, told, config, target) {
1279
1380
  known.默认拆件网格 = `${config ? "" : ""}4 列 × 4 行 = 16 个标准人形部件(头/脖子/躯干/胯/上臂/小臂/手/大腿/小腿/脚),格子位置即部件身份`;
1280
1381
  known.默认动画 = "idle 待机 / walk 行走 / run 奔跑 / wave 挥手 / jump 跳跃 / attack 攻击";
1281
1382
  }
1383
+ if (module === "map") {
1384
+ // ⚠️ 这里**故意不加** API Key 阻塞:整条链路(导入素材 / 自动连接 / 画地图 /
1385
+ // 导出)全在本地,一次模型调用都没有。写了阻塞就是让用户白配一次 Key。
1386
+ known.全本地不花钱 = "导入自己的素材图 → 自动连接 → 环绕画布上画 → 导出 PNG:一次模型调用都没有,不需要任何 API Key";
1387
+ known.四个阶段 = "① 素材(导入 PNG,形态按尺寸自动识别)→ ② 自动连接(宿主自动完成,界面不显示)→ ③ 地图(一张地图 / 多图层 / 四周环绕)→ ④ 导出(map.png + map.json)";
1388
+ known.单张地图 = "一个项目就是一张地图(`map.json`):改尺寸 / 图层 / 环绕都在 saveMapDoc 里,没有「多张地图」这一层";
1389
+ known.三种自动连接 = "拼块自动连接(RPG Maker A2 那种一格 4 象限的图)/ 整格 16 块 / 普通图块;形态与格子尺寸由素材尺寸自动识别,识别错了用 saveMapTileset 改";
1390
+ known.内置素材 = "importSampleTileset 可以装一套内置素材(4 张自动连接图 + 1 张道具图),本机现算、零成本";
1391
+ known.一键生成 = "runMapGenerate 支持 random(随机铺满)/ maze(迷宫)/ continent(大陆),整层一次提交、一次撤销,同种子逐字节可复现";
1392
+ known.预览等于导出 = "界面画布与导出 PNG 执行的是**同一份绘制计划**(宿主算、客户端只执行),所以不存在「预览好看、导出位移」";
1393
+ if (target?.grid)
1394
+ known.当前网格 = target.grid;
1395
+ if (target?.reviewMode)
1396
+ known.审核模式 = target.reviewMode;
1397
+ ask("tileset", "素材从哪来?把素材图 PNG 的**本机绝对路径**给我(可以多张),或者你自己在界面「素材」里上传;也可以先用内置素材试手。", "这个模块是「导入派」:不生成素材,只把已有素材图切成可用地块。", "用 game_material_upload({module:'map', id, kind:'tileset', path}),或 game_material_call 的 importMapTileset({projectId, name, data}) 传 base64,或 importSampleTileset({projectId}) 装内置素材。");
1398
+ ask("mapSize", "地图多大?(默认 32×32;改尺寸用 saveMapDoc 的 cols / rows)要分几层?(默认两层:图层 1 / 图层 2)", "尺寸与图层决定画布和最终 PNG 的像素大小;地图四周默认**环绕**。", "用 saveMapDoc({projectId, cols, rows, addLayer:{name}, wrap})。");
1399
+ ask("generate", "先一键铺一层再手改,还是直接手画?(一键生成:随机铺满 / 迷宫 / 大陆;也可以让 agent 直接拿坐标系画)", "一键生成是本地计算、不花钱,同一个种子结果完全一样,随时能撤销。", "用 runMapGenerate({projectId, kind:'random'|'maze'|'continent', tiles?, seed?, layerId?}),或 applyMapOps({projectId, ops}) 直接画。");
1400
+ }
1282
1401
  if (module === "tile") {
1283
1402
  if (config?.arkApiKeySet !== true) {
1284
1403
  blockers.push("还没配置火山方舟 API Key(生图必需):设置 → 游戏素材大师 → 火山方舟 API Key,配好点「测试连接」。");
@@ -1309,9 +1428,11 @@ function intakeFor(module, id, told, config, target) {
1309
1428
  ? "新建一个序列帧任务,还是在已有任务上继续?"
1310
1429
  : module === "tile"
1311
1430
  ? "新建一个地图地块项目,还是在已有项目上继续?"
1312
- : "新建一个骨骼动画任务,还是在已有任务上继续?",
1431
+ : module === "map"
1432
+ ? "新建一个地图项目,还是在已有项目上继续?"
1433
+ : "新建一个骨骼动画任务,还是在已有任务上继续?",
1313
1434
  why: "后面的参数都挂在项目 / 任务上。",
1314
- how: "新建:game_material_call({method:'createProject'|'createImageJob'|'createSequenceJob'|'createRigJob'|'createTileProject', payload:{name}}),返回的 id 就是后续 payload 里的 projectId / jobId。"
1435
+ how: "新建:game_material_call({method:'createProject'|'createImageJob'|'createSequenceJob'|'createRigJob'|'createTileProject'|'createMapProject', payload:{name}}),返回的 id 就是后续 payload 里的 projectId / jobId。"
1315
1436
  });
1316
1437
  }
1317
1438
  if (module === "sprite") {
@@ -1394,7 +1515,9 @@ const UPLOAD_KINDS = {
1394
1515
  // 地图地块**不需要上传素材**:地块由代码渲染的菱形模板 + 提示词生成。
1395
1516
  // 留空数组而不是漏掉这一项 —— 漏掉会让类型检查失败,而空数组能让
1396
1517
  // 「上传」这条路给出明确的报错信息(见 uploadFromPath)。
1397
- tile: []
1518
+ tile: [],
1519
+ // 地图编辑器就是**导入素材**起家的:这里上传的就是 tileset 图集原图。
1520
+ map: ["tileset"]
1398
1521
  };
1399
1522
  async function uploadFromPath(gateway, module, id, kind, path, name) {
1400
1523
  if (id === "")
@@ -1433,6 +1556,9 @@ async function uploadFromPath(gateway, module, id, kind, path, name) {
1433
1556
  else
1434
1557
  await call.addImageItem({ jobId: id, name: fileName, data: base64 });
1435
1558
  }
1559
+ else if (module === "map") {
1560
+ await call.importMapTileset({ projectId: id, name: fileName, data: base64 });
1561
+ }
1436
1562
  else if (module === "rig") {
1437
1563
  if (kind === "part")
1438
1564
  await call.uploadRigPart({ jobId: id, name: fileName, data: base64 });
@@ -1552,6 +1678,42 @@ function renderRigStageDetail(stage) {
1552
1678
  }
1553
1679
  return lines;
1554
1680
  }
1681
+ /** 模块六四个阶段的显示名(key 与对话面契约不变,变的只是中文名)。 */
1682
+ const MAP_STAGE_LABELS = { assets: "素材", rules: "自动连接", paint: "地图", export: "导出" };
1683
+ /**
1684
+ * 地图编辑器的验收摘要:素材 / 阶段 / 地图 / 预览图 / 导出产物。
1685
+ *
1686
+ * 这里的每一条都是**能点开的绝对 URL** —— 模型把它贴进回复,用户点一下就能看图。
1687
+ * 判定依据用 `Array.isArray(value.tilesets)`(只有模块六的快照有这个字段)。
1688
+ */
1689
+ function renderMapSummary(value) {
1690
+ const lines = [];
1691
+ if (Array.isArray(value.stages)) {
1692
+ lines.push(` 阶段:${value.stages
1693
+ .map((stage) => `${MAP_STAGE_LABELS[stage.stage] ?? stage.stage}:${stage.status}${stage.approved ? " · 已通过" : ""}${stage.error ? ` · ${stage.error}` : ""}`)
1694
+ .join(" ")}`);
1695
+ }
1696
+ if (typeof value.cols === "number" && typeof value.rows === "number")
1697
+ lines.push(` 地图:${value.cols}×${value.rows},已画 ${value.filled ?? 0} 格`);
1698
+ for (const layer of value.layers ?? [])
1699
+ lines.push(` · ${layer.name}:${layer.filled} 格`);
1700
+ for (const tileset of value.tilesets ?? []) {
1701
+ lines.push(` 素材「${tileset.name}」${tileset.imageWidth}×${tileset.imageHeight} · ${tileset.reason ?? ""} · ${tileset.tileCount} 块 · 笔刷 ${tileset.palette?.length ?? 0} 个`);
1702
+ if (typeof tileset.url === "string")
1703
+ lines.push(` ${tileset.url}`);
1704
+ }
1705
+ for (const url of value.previewUrls ?? value.preview ?? [])
1706
+ lines.push(` 验收预览图:${url}`);
1707
+ if (typeof value.exportBaseUrl === "string" && value.exportBaseUrl !== "")
1708
+ lines.push(` 导出目录:${value.exportBaseUrl}`);
1709
+ if (typeof value.exportPath === "string" && value.exportPath !== "")
1710
+ lines.push(` 导出目录(本机路径):${value.exportPath}`);
1711
+ for (const file of value.exportFiles ?? [])
1712
+ lines.push(` ${file}`);
1713
+ for (const warning of value.warnings ?? [])
1714
+ lines.push(` ⚠ ${warning}`);
1715
+ return lines;
1716
+ }
1555
1717
  function renderStatus(value) {
1556
1718
  if (Array.isArray(value.projects)) {
1557
1719
  const lines = [
@@ -1581,6 +1743,11 @@ function renderStatus(value) {
1581
1743
  lines.push(detail);
1582
1744
  }
1583
1745
  }
1746
+ // 地图编辑器(模块六):它的阶段是**对象**(不是数组),素材 / 预览图 / 导出清单
1747
+ // 也不在通用字段里,单独一段。
1748
+ if (Array.isArray(value.tilesets))
1749
+ for (const line of renderMapSummary(value))
1750
+ lines.push(line);
1584
1751
  // 八方向图:阶段①的两种生成方式差异很大,状态里必须写明走的是哪条、
1585
1752
  // 转圈视频与八个截帧位置各是什么——否则 agent 只能对着一张张方向图猜。
1586
1753
  if (value.imageMode !== undefined && value.turn !== undefined) {
@@ -1642,6 +1809,10 @@ function renderReview(value) {
1642
1809
  const lines = [`${value.name}(${value.id})验收包${value.busy ? " — ⏳ 仍有任务在跑" : ""}`];
1643
1810
  if (value.qa !== null && value.qa !== undefined)
1644
1811
  lines.push(renderRigQa(value.qa));
1812
+ // 地图编辑器(模块六):产物形状和别的模块完全不同(素材 + 一张地图 + 导出清单),
1813
+ // 单独走一段,免得掉进下面按 cells / items 迭代的通用分支。
1814
+ if (value.module === "map")
1815
+ lines.push(...renderMapSummary(value));
1645
1816
  if (Array.isArray(value.stages)) {
1646
1817
  for (const stage of value.stages) {
1647
1818
  lines.push(`${stage.title}${stage.stale ? " · 需重做" : ""}`);
package/lib/wire.js CHANGED
@@ -63,8 +63,13 @@ const approvedSchema = z.object({
63
63
  */
64
64
  const setReviewModeSchema = z.object({
65
65
  id: z.string(),
66
- /** 四个模块都要能设审核模式——骨骼动画(rig)早期漏了,见 index.ts 的注释。 */
67
- module: z.enum(["sprite", "image", "sequence", "rig"]),
66
+ /**
67
+ * 六个模块都要能设审核模式。
68
+ *
69
+ * ⚠️ 这个枚举漏一个模块,那条模块的「固定流程必须问清审核模式」就落不了地
70
+ * (骨骼动画与地图地块都踩过:走到宿主才抛「未知模块」)。模块六(map)同理。
71
+ */
72
+ module: z.enum(["sprite", "image", "sequence", "rig", "tile", "map"]),
68
73
  reviewMode: z.enum(["auto", "manual"])
69
74
  });
70
75
  const runImageSchema = z.object({ projectId: z.string(), key: z.string(), prompt: z.string().optional() });
@@ -536,6 +541,156 @@ const saveTileMapCellsSchema = z.object({
536
541
  */
537
542
  layouts: z.array(z.record(z.string(), z.unknown())).optional()
538
543
  });
544
+ // ── 地图编辑器(模块六)──────────────────────────────────────────────────
545
+ //
546
+ // ⚠️ 同样的硬约束:typert 按 schema 校验 payload,**schema 里没有的键会被静默丢掉**。
547
+ // 尤其是 `applyMapOps` 的 `ops` 与 `mapPlan` 的 `view` —— 少了它们,界面画什么都不
548
+ // 生效 / 一张图都拉不下来,而且不报错。
549
+ //
550
+ // 单项目 = 单张地图:`mapId` 只剩 `getMapProject` 里那个兼容位(老深链接带的),
551
+ // 其它方法的 payload 一律不带 mapId。
552
+ const mapProjectIdSchema = z.object({ projectId: z.string() });
553
+ /**
554
+ * 「在文件夹中显示」。`target: "export"` = 导出目录(界面上的「打开导出目录」),
555
+ * 省略 = 项目目录。
556
+ *
557
+ * ⚠️ 这里必须给 reveal 单独一条 schema:它与 `deleteMapProject` / `cancelMapJob` 共用
558
+ * `mapProjectIdSchema`,直接把 `target` 加在那个共享 schema 上会让所有方法都多一个无意义字段;
559
+ * 而**不加**的后果是 typert 把 `target` 静默丢掉 —— 界面点「打开导出目录」打不开导出的那个目录,
560
+ * 且不报任何错。
561
+ */
562
+ const revealMapProjectSchema = z.object({
563
+ projectId: z.string(),
564
+ target: z.enum(["project", "export"]).optional()
565
+ });
566
+ const mapGetSchema = z.object({
567
+ projectId: z.string(),
568
+ /** 仅兼容旧深链接:单项目单地图后它没有意义,宿主忽略。 */
569
+ mapId: z.string().optional(),
570
+ lang: z.string().optional()
571
+ });
572
+ const createMapProjectSchema = z.object({
573
+ name: z.string().optional(),
574
+ grid: z.record(z.string(), z.unknown()).optional(),
575
+ cols: z.number().optional(),
576
+ rows: z.number().optional()
577
+ });
578
+ const saveMapProjectSchema = z.object({
579
+ projectId: z.string(),
580
+ name: z.string().optional()
581
+ });
582
+ const importMapTilesetSchema = z.object({
583
+ projectId: z.string(),
584
+ name: z.string().optional(),
585
+ /** 原始文件字节的 base64(不带 data: 前缀)。 */
586
+ data: z.string(),
587
+ /**
588
+ * 新增素材时可以**一次性**把属性定下来(留空 = 自动识别)。属性之后不能再改:
589
+ * 内置素材一律拒绝,自己新增的也只能删掉重来。
590
+ */
591
+ cell: z.record(z.string(), z.unknown()).optional(),
592
+ shape: z.string().optional(),
593
+ animRows: z.boolean().optional()
594
+ });
595
+ const saveMapTilesetSchema = z.object({
596
+ projectId: z.string(),
597
+ tilesetId: z.string(),
598
+ name: z.string().optional(),
599
+ /** 逻辑块尺寸;不给就沿用当前值。 */
600
+ cell: z.record(z.string(), z.unknown()).optional(),
601
+ /** `plain` / `a2quad` / `corner16`。 */
602
+ shape: z.string().optional(),
603
+ animRows: z.boolean().optional()
604
+ });
605
+ const removeMapTilesetSchema = z.object({ projectId: z.string(), tilesetId: z.string() });
606
+ const saveMapDocSchema = z.object({
607
+ projectId: z.string(),
608
+ name: z.string().optional(),
609
+ cols: z.number().optional(),
610
+ rows: z.number().optional(),
611
+ /** 图层改名补丁:`[{id, name}]`。 */
612
+ layers: z.array(z.record(z.string(), z.unknown())).optional(),
613
+ addLayer: z.record(z.string(), z.unknown()).optional(),
614
+ removeLayerId: z.string().optional(),
615
+ moveLayer: z.record(z.string(), z.unknown()).optional(),
616
+ clearLayerId: z.string().optional(),
617
+ /** 地图四周是否环绕(落在项目网格上)。 */
618
+ wrap: z.boolean().optional()
619
+ });
620
+ const applyMapOpsSchema = z.object({
621
+ projectId: z.string(),
622
+ /**
623
+ * 笔画 id(一次拖拽 / 一次填充一个)。
624
+ *
625
+ * ⚠️ 必须写进 schema:typert 会**静默丢掉**没声明的键,漏了它界面传不进来,
626
+ * 一次拖拽又会变回好几步撤销(而且不报任何错)。
627
+ */
628
+ stroke: z.string().optional(),
629
+ /**
630
+ * 编辑操作:`{kind:"paint"|"fill"|"rect"|"replace", …}`。
631
+ * 返回脏 chunk 与该丢的客户端缓存 key。
632
+ */
633
+ ops: z.array(z.record(z.string(), z.unknown())),
634
+ /** 客户端已经有的 chunk key(未 wrap);宿主据此回 `dropKeys`。 */
635
+ have: z.array(z.string()).optional()
636
+ });
637
+ const mapHaveSchema = z.object({ projectId: z.string(), have: z.array(z.string()).optional() });
638
+ const mapPlanSchema = z.object({
639
+ projectId: z.string(),
640
+ /**
641
+ * 视口矩形(画布像素坐标)。
642
+ *
643
+ * ⚠️ 必须逐键声明:typert 会**静默丢掉** schema 之外的键,只写
644
+ * `z.record(...)` 之外的东西都行,但漏一个字段就是「计划永远算的是 0×0 视口」。
645
+ */
646
+ view: z.object({ x: z.number(), y: z.number(), width: z.number(), height: z.number() }),
647
+ /**
648
+ * 预览用:还在笔里、还没提交的 op。宿主盖到一份克隆上算计划,**不落盘** ——
649
+ * 「画的过程中看得见,但一次都没存」。提交后客户端会把这些 chunk 标成待重拉。
650
+ */
651
+ pending: z.array(z.record(z.string(), z.unknown())).optional(),
652
+ /** 客户端已有的 chunk key(未 wrap)。 */
653
+ have: z.array(z.string()).optional(),
654
+ /** 只算这几个层号(0 起)。 */
655
+ layerIds: z.array(z.number()).optional()
656
+ });
657
+ const runMapGenerateSchema = z.object({
658
+ projectId: z.string(),
659
+ kind: z.enum(["random", "maze", "continent"]),
660
+ /** 用哪些图块序号(1-based 全局序号;0 = 空)。不给就用项目里全部图块。 */
661
+ tiles: z.array(z.number()).optional(),
662
+ seed: z.number().optional(),
663
+ layerId: z.string().optional()
664
+ });
665
+ const runMapPreviewSchema = z.object({ projectId: z.string() });
666
+ const runMapExportSchema = z.object({
667
+ projectId: z.string(),
668
+ scale: z.number().optional(),
669
+ /**
670
+ * 导出内容(**逐项写清楚**,不再是 `record(unknown)`):界面上是三个复选框 +
671
+ * 一个倍率,宿主按同一组键决定写哪些文件。
672
+ *
673
+ * - `png` / `json`:地图图片、存档数据(都不给 = 都要,与旧行为一致);
674
+ * - `tilesets`:把素材原图一起拷进 `tilesets/`(整包自包含);
675
+ * - `zip`:打一个 zip;不给 = 产物超过一个就自动打;
676
+ * - `scale`:只影响 PNG 的整数倍率。
677
+ */
678
+ formats: z
679
+ .object({
680
+ png: z.boolean().optional(),
681
+ json: z.boolean().optional(),
682
+ tilesets: z.boolean().optional(),
683
+ zip: z.boolean().optional(),
684
+ scale: z.number().optional()
685
+ })
686
+ .optional()
687
+ });
688
+ const setMapApprovedSchema = z.object({
689
+ projectId: z.string(),
690
+ /** 空 = 四个阶段全打。 */
691
+ stage: z.string().optional(),
692
+ approved: z.boolean()
693
+ });
539
694
  export const METHODS = [{ method: "getConfig", result: configViewSchema },
540
695
  { method: "saveConfig", payload: saveConfigSchema, result: configViewSchema },
541
696
  { method: "testArk", result: jsonObject },
@@ -650,7 +805,28 @@ export const METHODS = [{ method: "getConfig", result: configViewSchema },
650
805
  { method: "saveTileMapCells", payload: saveTileMapCellsSchema, result: okSchema },
651
806
  { method: "runTileExport", payload: tileIdSchema, result: startedSchema },
652
807
  { method: "cancelTileJob", payload: tileIdSchema, result: okSchema },
653
- { method: "revealTileProject", payload: tileIdSchema, result: okSchema }
808
+ { method: "revealTileProject", payload: tileIdSchema, result: okSchema },
809
+ // 地图编辑器(模块六,单项目 = 单张地图)
810
+ { method: "listMapProjects", result: z.object({ projects: z.array(jsonObject) }) },
811
+ { method: "createMapProject", payload: createMapProjectSchema, result: jsonObject },
812
+ { method: "getMapProject", payload: mapGetSchema, result: projectViewSchema },
813
+ { method: "saveMapProject", payload: saveMapProjectSchema, result: jsonObject },
814
+ { method: "deleteMapProject", payload: mapProjectIdSchema, result: okSchema },
815
+ { method: "importMapTileset", payload: importMapTilesetSchema, result: jsonObject },
816
+ { method: "importSampleTileset", payload: mapProjectIdSchema, result: jsonObject },
817
+ { method: "saveMapTileset", payload: saveMapTilesetSchema, result: jsonObject },
818
+ { method: "removeMapTileset", payload: removeMapTilesetSchema, result: jsonObject },
819
+ { method: "saveMapDoc", payload: saveMapDocSchema, result: jsonObject },
820
+ { method: "applyMapOps", payload: applyMapOpsSchema, result: jsonObject },
821
+ { method: "mapUndo", payload: mapHaveSchema, result: jsonObject },
822
+ { method: "mapRedo", payload: mapHaveSchema, result: jsonObject },
823
+ { method: "mapPlan", payload: mapPlanSchema, result: jsonObject },
824
+ { method: "runMapGenerate", payload: runMapGenerateSchema, result: jsonObject },
825
+ { method: "runMapPreview", payload: runMapPreviewSchema, result: startedSchema },
826
+ { method: "runMapExport", payload: runMapExportSchema, result: startedSchema },
827
+ { method: "cancelMapJob", payload: mapProjectIdSchema, result: okSchema },
828
+ { method: "setMapApproved", payload: setMapApprovedSchema, result: okSchema },
829
+ { method: "revealMapProject", payload: revealMapProjectSchema, result: okSchema }
654
830
  ];
655
831
  export const PACKAGE_NAME = "dsh-game-material-master";
656
832
  export const SERVICE_NAME = "gameStudio";