dsh-game-material-master 0.4.0 → 0.7.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
  * 远程方法 → 它属于哪个模块。
@@ -70,6 +73,9 @@ export const METHOD_MODULE = {
70
73
  saveSettings: "sprite",
71
74
  setApproved: "sprite",
72
75
  revealProject: "sprite",
76
+ /** 本地自选视频(转圈 / 某个方向)与中间图片打包:都归八方向图模块。 */
77
+ uploadVideo: "sprite",
78
+ exportImages: "sprite",
73
79
  runImage: "sprite",
74
80
  runImages: "sprite",
75
81
  setImageMode: "sprite",
@@ -167,7 +173,28 @@ export const METHOD_MODULE = {
167
173
  saveTileMapCells: "tile",
168
174
  runTileExport: "tile",
169
175
  cancelTileJob: "tile",
170
- revealTileProject: "tile"
176
+ revealTileProject: "tile",
177
+ // 模块六 地图编辑器(单项目 = 单张地图,全本地零计费)
178
+ listMapProjects: "map",
179
+ createMapProject: "map",
180
+ getMapProject: "map",
181
+ saveMapProject: "map",
182
+ deleteMapProject: "map",
183
+ importMapTileset: "map",
184
+ importSampleTileset: "map",
185
+ saveMapTileset: "map",
186
+ removeMapTileset: "map",
187
+ saveMapDoc: "map",
188
+ applyMapOps: "map",
189
+ mapUndo: "map",
190
+ mapRedo: "map",
191
+ mapPlan: "map",
192
+ runMapGenerate: "map",
193
+ runMapPreview: "map",
194
+ runMapExport: "map",
195
+ cancelMapJob: "map",
196
+ setMapApproved: "map",
197
+ revealMapProject: "map"
171
198
  };
172
199
  /**
173
200
  * 不隶属于任何模块的方法:配置类 + 跨模块的审核模式
@@ -177,6 +204,7 @@ export const SHARED_TOOL_METHODS = new Set([
177
204
  "getConfig",
178
205
  "saveConfig",
179
206
  "testArk",
207
+ "testCustomImage",
180
208
  "testMinimax",
181
209
  "setReviewMode"
182
210
  ]);
@@ -229,7 +257,7 @@ const clampInt = (value, fallback, min, max) => {
229
257
  function moduleOf(value) {
230
258
  return typeof value === "string" && MODULES.includes(value) ? value : undefined;
231
259
  }
232
- /** 任务 id 前缀决定它属于哪个模块(p… / i… / s… / r… / t…)。 */
260
+ /** 任务 id 前缀决定它属于哪个模块(p… / i… / s… / r… / t… / m…)。 */
233
261
  export function moduleForId(id) {
234
262
  if (/^p[a-z0-9]+$/.test(id))
235
263
  return "sprite";
@@ -241,6 +269,8 @@ export function moduleForId(id) {
241
269
  return "rig";
242
270
  if (/^t[a-z0-9]+$/.test(id))
243
271
  return "tile";
272
+ if (/^m[a-z0-9]+$/.test(id))
273
+ return "map";
244
274
  return undefined;
245
275
  }
246
276
  /** 产物相对路径 → 浏览器可直接打开的绝对 URL。 */
@@ -500,6 +530,12 @@ async function snapshotOf(module, id) {
500
530
  throw new Error(`找不到地图地块项目:${id}`);
501
531
  return tileSnapshot(project, originForLinks());
502
532
  }
533
+ if (module === "map") {
534
+ const project = await readMapProject(id);
535
+ if (project === undefined)
536
+ throw new Error(`找不到地图项目:${id}`);
537
+ return mapSnapshot(project, originForLinks());
538
+ }
503
539
  const job = await readRigJob(id);
504
540
  if (job === undefined)
505
541
  throw new Error(`找不到骨骼动画任务:${id}`);
@@ -534,6 +570,20 @@ function intentFromCall(method, payload) {
534
570
  const projectId = asString(payload.projectId);
535
571
  const jobId = asString(payload.jobId);
536
572
  const stage = typeof payload.stage === "string" ? payload.stage : undefined;
573
+ /**
574
+ * ⚠️ **先按方法名认模块,再看字段名。**
575
+ *
576
+ * 以前是先判 `payload.projectId` 非空就当八方向图 —— 于是模块二/三/四/五/六里
577
+ * 凡是入参叫 `projectId` 的方法(`runTileMap`、`getMapProject`、`saveMapDoc`…)
578
+ * 返回的 openUrl 全都指向 `module=sprite&project=<别人的 id>`,用户点进去落在
579
+ * 八方向图页面上,看着就是「链接是坏的」。字段名靠不住,方法归属才是真源
580
+ * (`METHOD_MODULE`),非 sprite 模块的 id 一律放 `jobId`(宿主 `intentOf` 的约定)。
581
+ */
582
+ const owner = METHOD_MODULE[method];
583
+ if (owner !== undefined && owner !== "sprite") {
584
+ const targetId = projectId !== "" ? projectId : jobId;
585
+ return targetId === "" ? { module: owner } : { module: owner, jobId: targetId, stage };
586
+ }
537
587
  if (projectId !== "") {
538
588
  const framePick = method === "prepareFramePick" || method === "setFramePick" || method === "setFramePicks" || method === "resetFramePicks";
539
589
  return { module: "sprite", projectId, stage: framePick ? "frames" : stage };
@@ -546,6 +596,8 @@ function intentFromCall(method, payload) {
546
596
  return { module: "rig" };
547
597
  if (method.startsWith("listTileProject") || method.startsWith("createTileProject"))
548
598
  return { module: "tile" };
599
+ if (method.startsWith("listMapProject") || method.startsWith("createMapProject"))
600
+ return { module: "map" };
549
601
  if (method.startsWith("listImageJob") || method.startsWith("createImageJob"))
550
602
  return { module: "image" };
551
603
  if (method.startsWith("listSequenceJob") || method.startsWith("createSequenceJob"))
@@ -558,12 +610,16 @@ function intentFromCall(method, payload) {
558
610
  /** `game_material_call` 的描述:把每个远程方法的用途与入参写清楚。 */
559
611
  const CALL_DESCRIPTION = [
560
612
  "调用「游戏素材大师」插件的任意远程方法——插件界面上的每个功能都能在这里调用。",
561
- "配置:getConfig() / saveConfig(payload: 任意配置字段,如 arkApiKey、arkModel、minimaxModel、cellWidth…) / testArk() / testMinimax()",
613
+ "配置:getConfig() / saveConfig(payload: 任意配置字段,如 arkApiKey、arkModel、imageProvider(ark|custom)、customProtocol(openai|comfyui|sdwebui)、customBaseUrl、customModel、customWorkflow、minimaxModel、cellWidth…) / testArk() / testCustomImage() / testMinimax()",
614
+ " ★ 生图后端有两种:`ark`(火山方舟 Seedream,默认)与 `custom`(用户自己的服务,协议可选 openai / comfyui / sdwebui)。",
615
+ " 换后端只改 imageProvider 一个字段,八方向图 / 图片生成 / 骨骼动画 / 地图地块全都跟着走;图生视频始终只走 MiniMax。",
562
616
  " ⚠️ 用户可以在「设置 → 游戏素材大师 → 功能管理」里隐藏某些功能模块。被隐藏的模块**工具面一律拒绝**(界面也看不到),",
563
617
  " 调用会直接报错并说明去哪里打开;不要试图绕过。hiddenModules 本身只能由用户在设置界面里改,工具面不允许写。",
564
618
  "八方向图:listProjects() / createProject({name}) / getProject({projectId}) / deleteProject({projectId}) / renameProject({projectId,name}) /",
565
619
  " uploadSource({projectId,name,data:base64}) / savePrompts({projectId,images?,video?,turn?,videoPerDirection?,suffix?,resetImagesToDefault?,resetVideoToDefault?,resetTurnToDefault?}) /",
566
620
  " saveSettings({projectId,settings}) / setApproved({projectId,stage:images|videos|frames|sheet,key?,approved}) / revealProject({projectId}) /",
621
+ " uploadVideo({projectId,key:turn|<方向>,name,data:base64})【★本地自选视频:两处「要生成视频」的地方都能用自己电脑上的视频顶替远程生成——key=turn 是转圈视频(导入后自动抽候选帧并切八张图),key=<方向> 是某一段行走视频(之后到第 3 步抽帧);产物与远端生成完全同形,`origin:'local'` 标注来路】/",
622
+ " exportImages({projectId})【把所有中间图片(八方向绿幕图 / 转圈候选帧与条带 / 每段视频的绿幕帧与抠像帧 / 整图)打成一个 zip 落在 out/ 下,返回 file 与 assetBase 供下载】/",
567
623
  " runImage({projectId,key,prompt?}) / runImages({projectId,force?}) / runVideos({projectId,keys?,regenerate?}) / pollVideos({projectId}) /",
568
624
  " clearVideos({projectId,keys?}) / runFrames({projectId,keys?})【整段等分,同一套规则】 / rekey({projectId}) / compose({projectId})",
569
625
  " prepareFramePick({projectId,key,count?})【只抽这一个方向的候选帧,免费】/ setFramePick({projectId,key,slot,index})【拖动第 slot 个输出帧到候选 index】/",
@@ -606,6 +662,18 @@ const CALL_DESCRIPTION = [
606
662
  " ★ 四个阶段:generate → review → map → export。**没有「先做模板」这一步** —— 等距参考图在 runTileItems 开始时",
607
663
  " 按各建筑地块的占格形状自动渲染(形状 / 格子尺寸没变就直接复用,免费、不额外调用)。",
608
664
  " ★ 几何交给代码、内容交给 AI:参考图由本机渲染,AI 只填菱形内部;生成后本地量一次、仿射对齐回标准菱形。",
665
+ "地图编辑器(模块六,**全本地、零计费**;导入自己的素材图,四步:素材图 → 自动连接 → 环绕画布 → 导出 PNG/存档):",
666
+ " listMapProjects() / createMapProject({name,grid?,cols?,rows?}) / getMapProject({projectId,lang?}) / saveMapProject({projectId,name}) / deleteMapProject({projectId}) /",
667
+ " importMapTileset({projectId,name,data:素材图base64,cell?,shape?,animRows?})【新增素材:属性这一下就定死,之后只能删掉重来;cell/shape/animRows 留空 = 自动识别】/ importSampleTileset({projectId})【内置素材:本机现算、零成本,4 张自动连接图 + 1 张道具图;属性不可改、可删、可一键恢复】/",
668
+ " saveMapTileset({projectId,tilesetId,name?,cell?,shape?,animRows?})【形态由尺寸自动识别,改形态/删素材会让图块序号平移,宿主按「素材 id + 图块 id」自动重新映射每格】/ removeMapTileset({projectId,tilesetId}) /",
669
+ " saveMapDoc({projectId,name?,cols?,rows?,layers?,addLayer?,removeLayerId?,moveLayer?,clearLayerId?,wrap?})【地图只有一张:改尺寸/图层/环绕都走它】/",
670
+ " 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】/",
671
+ " mapUndo({projectId,have?}) / mapRedo({projectId,have?})【宿主持撤销栈,界面不用管】/ mapPlan({projectId,view:{x,y,width,height},have?,layerIds?})【绘制计划:每项 = {l 层, r,c 格号, t 图块序号, x,y 目标像素, a 不透明度, cycle? 动画帧序},界面画布与导出 PNG 执行同一份】/",
672
+ " runMapGenerate({projectId,kind:'random'|'maze'|'continent',tiles?,seed?,layerId?})【一键铺满:整层一次提交、一次撤销;同种子逐字节可复现】/",
673
+ " runMapPreview({projectId})【验收预览图 preview/map.png】/ runMapExport({projectId,scale?,formats?})【formats = {png?,json?,tilesets?,zip?}:默认 png+json,**产物超过一个自动打一个 zip**(zip:false 关掉);tilesets:true 会把素材原图一起拷进 tilesets/,整包自包含;manifest.json 是我们自己的账本】/",
674
+ " cancelMapJob({projectId}) / setMapApproved({projectId,stage?,approved})【stage 空 = 四阶段全打】/ revealMapProject({projectId,target?})【target:'export' 打开导出目录,省略 = 项目目录】",
675
+ " ★ 四个阶段:素材(assets)→ 自动连接(rules,宿主自动完成、界面不显示)→ 地图(paint)→ 导出(export)。**没有任何一步需要 API Key**。",
676
+ " ★ 地图四周**环绕**:视口范围可以越出边界,宿主会把这些格子映射回图内;一张地图就一个 `map.json`,没有多地图。",
609
677
  " 生成的几何报告看 game_material_review 返回的 variants[].geomMode —— measured 是量测成功,template 是回退模板几何。",
610
678
  " 出现 template 多半是模型不对:必须用 Seedream 5.0 系列;4.0 会把 2:1 等距菱形画成近正方形(实测比例 1.058)。",
611
679
  "说明:key 是方向英文字面量(front/back/downLeft/downRight/upLeft/upRight/left/right);data 是原始文件字节的 base64(不带 data: 前缀);",
@@ -713,12 +781,13 @@ export function registerStudioTools(host, gateway) {
713
781
  if (id === "") {
714
782
  // 只列可见模块的清单:隐藏的模块连「有哪些项目」都不给模型看一眼。
715
783
  await assertModuleVisible(moduleOf(args?.module));
716
- const [projects, images, sequences, rigs, tiles] = await Promise.all([
784
+ const [projects, images, sequences, rigs, tiles, maps] = await Promise.all([
717
785
  hidden.has("sprite") ? [] : listProjects(),
718
786
  hidden.has("image") ? [] : listImageJobs(),
719
787
  hidden.has("sequence") ? [] : listSequenceJobs(),
720
788
  hidden.has("rig") ? [] : listRigJobs(),
721
- hidden.has("tile") ? [] : listTileProjects()
789
+ hidden.has("tile") ? [] : listTileProjects(),
790
+ hidden.has("map") ? [] : listMapProjects()
722
791
  ]);
723
792
  const links = {};
724
793
  for (const key of MODULES)
@@ -732,8 +801,9 @@ export function registerStudioTools(host, gateway) {
732
801
  sequenceJobs: sequences,
733
802
  rigJobs: rigs,
734
803
  tileProjects: tiles,
804
+ mapProjects: maps,
735
805
  links,
736
- hint: "用 game_material_status({module,id}) 看某个目标的细节;八方向图的四步是 images → videos → frames → sheet,45°地图地块是 generate → review → map → export。"
806
+ hint: "用 game_material_status({module,id}) 看某个目标的细节;八方向图的四步是 images → videos → frames → sheet,45°地图地块是 generate → review → map → export,地图编辑器是 assets(素材)→ rules(自动连接)→ paint(地图)→ export(导出),全本地不花钱。"
737
807
  };
738
808
  }
739
809
  // ⚠️ 这里**不能**再按 module 短路:`status({module:'tile', id})` 也走到这里,
@@ -793,9 +863,10 @@ export function registerStudioTools(host, gateway) {
793
863
  description: [
794
864
  "把本机文件上传进「游戏素材大师」——界面上那些「上传」框的对话等价物。",
795
865
  "参数 `path` 是文件的绝对路径或相对当前工作目录的路径,宿主自己读盘,**不要把 base64 贴进来**。",
796
- "kind 取值:sprite=source(源设定图);image=ref(参考图,最多 10 张)| item(直接加一张图,只做抠像用);",
797
- "sequence=firstFrame | lastFrame | referenceImage | referenceVideo;rig=source(角色整图)| part(单个部件 PNG,文件名即部件名)。",
798
- "限制:图片 ≤30MB,参考视频 ≤40MB(平台请求体上限 64MB),图片类型按文件头嗅探。"
866
+ "kind 取值:sprite=source(源设定图)| video(**本地自选视频**,要用 `key` 指定槽位:turn=转圈视频,或 front/back/downLeft/downRight/upLeft/upRight/left/right 之一);",
867
+ "image=ref(参考图,最多 10 张)| item(直接加一张图,只做抠像用);",
868
+ "sequence=firstFrame | lastFrame | referenceImage | referenceVideo;rig=source(角色整图)| part(单个部件 PNG,文件名即部件名);map=tileset(图集原图)。",
869
+ "限制:图片 ≤30MB,视频 ≤40MB(平台请求体上限 64MB;界面上那条本地上传路更宽),类型按文件头嗅探。"
799
870
  ].join("\n"),
800
871
  parameters: {
801
872
  type: "object",
@@ -803,7 +874,8 @@ export function registerStudioTools(host, gateway) {
803
874
  properties: {
804
875
  module: { type: "string", enum: [...MODULES], description: "目标所属模块。" },
805
876
  id: { type: "string", description: "项目 id(p…)或任务 id(i… / s…)。" },
806
- kind: { type: "string", enum: ["source", "ref", "item", "firstFrame", "lastFrame", "referenceImage", "referenceVideo", "part"], description: "上传到哪个槽位。" },
877
+ kind: { type: "string", enum: ["source", "video", "ref", "item", "firstFrame", "lastFrame", "referenceImage", "referenceVideo", "part", "tileset"], description: "上传到哪个槽位。" },
878
+ key: { type: "string", description: "仅 sprite + kind=video 用:槽位 `turn`(转圈视频)或某个方向 key。" },
807
879
  path: { type: "string", description: "本机文件路径。" },
808
880
  name: { type: "string", description: "可选:展示用的文件名。" }
809
881
  },
@@ -820,7 +892,7 @@ export function registerStudioTools(host, gateway) {
820
892
  const path = asString(args?.path);
821
893
  if (path === "")
822
894
  throw new Error("path 不能为空");
823
- return uploadFromPath(gateway, module, id, kind, path, asString(args?.name) || undefined);
895
+ return uploadFromPath(gateway, module, id, kind, path, asString(args?.name) || undefined, asString(args?.key) || undefined);
824
896
  }
825
897
  });
826
898
  register({
@@ -912,7 +984,11 @@ export function registerStudioTools(host, gateway) {
912
984
  properties: {
913
985
  module: { type: "string", enum: [...MODULES], description: "目标所属模块;可省略,按 id 前缀判断。" },
914
986
  id: { type: "string", description: "项目 id(p…)/ 图片任务 id(i…)/ 序列帧任务 id(s…)。" },
915
- stage: { type: "string", enum: ["images", "videos", "frames", "sheet", "parts", "layout", "rig", "atlas"], description: "八方向图 / 骨骼动画专用:只看某一个阶段。" },
987
+ stage: {
988
+ type: "string",
989
+ enum: ["images", "videos", "frames", "sheet", "generate", "review", "map", "export", "parts", "layout", "rig", "atlas", ...MAP_STAGES],
990
+ description: "八方向图 / 地图地块 / 地图编辑器 / 骨骼动画专用:只看某一个阶段。"
991
+ },
916
992
  direction: { type: "string", description: "八方向图专用:只看某一个方位(front/back/…)。" },
917
993
  index: { type: "integer", description: "图片任务专用:只看第几张(从 0 开始)。" },
918
994
  step: { type: "string", enum: ["video", "frames", "sheet"], description: "序列帧任务专用:只看某一步。" }
@@ -968,6 +1044,32 @@ export function registerStudioTools(host, gateway) {
968
1044
  packet.steps = steps;
969
1045
  packet.nextActions = sequenceNextActions(snapshot);
970
1046
  }
1047
+ else if (module === "map") {
1048
+ const mapStages = snapshot.stages;
1049
+ const stageKeys = Object.keys(mapStages ?? {});
1050
+ if (stage !== undefined && !stageKeys.includes(stage)) {
1051
+ throw new Error(`未知阶段:${stage}(可选:${stageKeys.join(" / ")})`);
1052
+ }
1053
+ packet.stages = stageKeys
1054
+ .filter((key) => stage === undefined || key === stage)
1055
+ .map((key) => ({ stage: key, ...mapStages[key] }));
1056
+ packet.grid = snapshot.grid;
1057
+ packet.cols = snapshot.cols;
1058
+ packet.rows = snapshot.rows;
1059
+ // 素材带**绝对 URL**(模型要直接贴给用户点);调色板也跟着给,方便「让 agent
1060
+ // 自己画一张」时挑序号。
1061
+ packet.tilesets = snapshot.tilesets;
1062
+ packet.layers = snapshot.layers;
1063
+ packet.filled = snapshot.filled;
1064
+ packet.preview = snapshot.previewUrls;
1065
+ packet.previewUrls = snapshot.previewUrls;
1066
+ packet.exportBaseUrl = snapshot.exportBaseUrl;
1067
+ packet.exportFiles = snapshot.exportFiles;
1068
+ /** 导出目录的**绝对路径**(还没导出过 = 空串):产物埋在 DSH_HOME 底下,模型直接报路径比让用户找方便。 */
1069
+ packet.exportPath = snapshot.exportPath;
1070
+ packet.warnings = [...(snapshot.warnings ?? []), ...(snapshot.exportWarnings ?? [])];
1071
+ packet.nextActions = (snapshot.nextActions ?? []).map((action) => `${action.step}:${action.why}`);
1072
+ }
971
1073
  else if (module === "tile") {
972
1074
  // ⚠️ 地图地块的 `stages` 是**对象**({generate, review, map, export}),
973
1075
  // 不是数组。之前它掉进了 `else`(骨骼动画)分支,那边无条件当成数组用
@@ -1023,7 +1125,8 @@ export function registerStudioTools(host, gateway) {
1023
1125
  "八方向图:module=sprite,id=项目 id,stage=images|videos|frames|sheet,key 可只对某个方位生效(省略即整阶段)。",
1024
1126
  "图片任务:module=image,id=任务 id,index 可只对某一张生效(省略即全任务)。",
1025
1127
  "序列帧:module=sequence,id=任务 id,step=video|frames|sheet(省略即全部三步)。",
1026
- "骨骼动画:module=rig,id=任务 id,stage=parts|layout|rig|atlas(省略即四个阶段全打);stage=parts 时可再带 part 只对某个部件生效。"
1128
+ "骨骼动画:module=rig,id=任务 id,stage=parts|layout|rig|atlas(省略即四个阶段全打);stage=parts 时可再带 part 只对某个部件生效。",
1129
+ "地图编辑器:module=map,id=项目 id,stage=assets|rules|paint|export(省略即四个阶段全打)。这条链路全本地,打勾只是记录「这步看过了」。"
1027
1130
  ].join("\n"),
1028
1131
  parameters: {
1029
1132
  type: "object",
@@ -1031,7 +1134,7 @@ export function registerStudioTools(host, gateway) {
1031
1134
  properties: {
1032
1135
  module: { type: "string", enum: [...MODULES], description: "目标所属模块;可省略,按 id 前缀判断。" },
1033
1136
  id: { type: "string", description: "项目 / 任务 id。" },
1034
- stage: { type: "string", enum: ["images", "videos", "frames", "sheet"], description: "八方向图:阶段。" },
1137
+ stage: { type: "string", enum: ["images", "videos", "frames", "sheet", ...MAP_STAGES], description: "八方向图 / 地图编辑器:阶段。" },
1035
1138
  key: { type: "string", description: "八方向图:只对某个方位生效(front/back/…)。" },
1036
1139
  index: { type: "integer", description: "图片任务:只对某一张生效。" },
1037
1140
  step: { type: "string", enum: ["video", "frames", "sheet"], description: "序列帧:只对某一步生效。" },
@@ -1072,6 +1175,14 @@ export function registerStudioTools(host, gateway) {
1072
1175
  await gateway.saveImageJob(index === undefined ? { jobId: id, approved } : { jobId: id, approved, index });
1073
1176
  return { module, id, index: index ?? null, approved, count: targets.length, ...openInfo({ module: "image", jobId: id }, "点开看验收结果") };
1074
1177
  }
1178
+ if (module === "map") {
1179
+ const stage = asString(args?.stage) || undefined;
1180
+ if (stage !== undefined && !MAP_STAGES.includes(stage))
1181
+ throw new Error(`未知阶段:${stage}(可选:${MAP_STAGES.join(" / ")})`);
1182
+ // 单项目 = 单张地图:没有 mapId 这个维度了(打勾永远打整个项目)。
1183
+ await gateway.setMapApproved({ projectId: id, stage, approved });
1184
+ return { module, id, stage: stage ?? null, approved, ...openInfo({ module: "map", jobId: id, stage }, "点开看验收结果") };
1185
+ }
1075
1186
  if (module === "tile") {
1076
1187
  const key = asString(args?.key) || undefined;
1077
1188
  const variant = args?.variant === undefined ? undefined : clampInt(args.variant, 0, 0, 99);
@@ -1244,11 +1355,13 @@ function intakeFor(module, id, told, config, target) {
1244
1355
  questions.push({ key, question, why, how });
1245
1356
  };
1246
1357
  if (module === "sprite" || module === "image" || module === "rig") {
1247
- if (config?.arkApiKeySet !== true) {
1248
- blockers.push("还没配置火山方舟 API Key(生图必需):设置 → 游戏素材大师 → 火山方舟 API Key,配好点「测试连接」。");
1358
+ // 「配好了没」由宿主算好回传(`imageProviderBlocker`),工具面不再自己判 arkApiKey:
1359
+ // 生图后端可能是用户自己的服务,那种情况下没有 arkApiKey 也完全能用。
1360
+ if (config?.imageProviderBlocker !== null && config?.imageProviderBlocker !== undefined) {
1361
+ blockers.push(`${config.imageProviderBlocker},配好点「测试连接」。`);
1249
1362
  }
1250
- known.生图模型 = config?.arkModel;
1251
- known.出图尺寸 = config?.arkSize;
1363
+ known.生图后端 = config?.imageProviderSummary;
1364
+ known.出图尺寸 = config?.imageProvider === "custom" ? config?.customSize : config?.arkSize;
1252
1365
  }
1253
1366
  if (module === "sequence") {
1254
1367
  if (config?.minimaxApiKeySet !== true) {
@@ -1279,11 +1392,30 @@ function intakeFor(module, id, told, config, target) {
1279
1392
  known.默认拆件网格 = `${config ? "" : ""}4 列 × 4 行 = 16 个标准人形部件(头/脖子/躯干/胯/上臂/小臂/手/大腿/小腿/脚),格子位置即部件身份`;
1280
1393
  known.默认动画 = "idle 待机 / walk 行走 / run 奔跑 / wave 挥手 / jump 跳跃 / attack 攻击";
1281
1394
  }
1395
+ if (module === "map") {
1396
+ // ⚠️ 这里**故意不加** API Key 阻塞:整条链路(导入素材 / 自动连接 / 画地图 /
1397
+ // 导出)全在本地,一次模型调用都没有。写了阻塞就是让用户白配一次 Key。
1398
+ known.全本地不花钱 = "导入自己的素材图 → 自动连接 → 环绕画布上画 → 导出 PNG:一次模型调用都没有,不需要任何 API Key";
1399
+ known.四个阶段 = "① 素材(导入 PNG,形态按尺寸自动识别)→ ② 自动连接(宿主自动完成,界面不显示)→ ③ 地图(一张地图 / 多图层 / 四周环绕)→ ④ 导出(map.png + map.json)";
1400
+ known.单张地图 = "一个项目就是一张地图(`map.json`):改尺寸 / 图层 / 环绕都在 saveMapDoc 里,没有「多张地图」这一层";
1401
+ known.三种自动连接 = "拼块自动连接(RPG Maker A2 那种一格 4 象限的图)/ 整格 16 块 / 普通图块;形态与格子尺寸由素材尺寸自动识别,识别错了用 saveMapTileset 改";
1402
+ known.内置素材 = "importSampleTileset 可以装一套内置素材(4 张自动连接图 + 1 张道具图),本机现算、零成本";
1403
+ known.一键生成 = "runMapGenerate 支持 random(随机铺满)/ maze(迷宫)/ continent(大陆),整层一次提交、一次撤销,同种子逐字节可复现";
1404
+ known.预览等于导出 = "界面画布与导出 PNG 执行的是**同一份绘制计划**(宿主算、客户端只执行),所以不存在「预览好看、导出位移」";
1405
+ if (target?.grid)
1406
+ known.当前网格 = target.grid;
1407
+ if (target?.reviewMode)
1408
+ known.审核模式 = target.reviewMode;
1409
+ ask("tileset", "素材从哪来?把素材图 PNG 的**本机绝对路径**给我(可以多张),或者你自己在界面「素材」里上传;也可以先用内置素材试手。", "这个模块是「导入派」:不生成素材,只把已有素材图切成可用地块。", "用 game_material_upload({module:'map', id, kind:'tileset', path}),或 game_material_call 的 importMapTileset({projectId, name, data}) 传 base64,或 importSampleTileset({projectId}) 装内置素材。");
1410
+ ask("mapSize", "地图多大?(默认 32×32;改尺寸用 saveMapDoc 的 cols / rows)要分几层?(默认两层:图层 1 / 图层 2)", "尺寸与图层决定画布和最终 PNG 的像素大小;地图四周默认**环绕**。", "用 saveMapDoc({projectId, cols, rows, addLayer:{name}, wrap})。");
1411
+ ask("generate", "先一键铺一层再手改,还是直接手画?(一键生成:随机铺满 / 迷宫 / 大陆;也可以让 agent 直接拿坐标系画)", "一键生成是本地计算、不花钱,同一个种子结果完全一样,随时能撤销。", "用 runMapGenerate({projectId, kind:'random'|'maze'|'continent', tiles?, seed?, layerId?}),或 applyMapOps({projectId, ops}) 直接画。");
1412
+ }
1282
1413
  if (module === "tile") {
1283
- if (config?.arkApiKeySet !== true) {
1284
- blockers.push("还没配置火山方舟 API Key(生图必需):设置 → 游戏素材大师 → 火山方舟 API Key,配好点「测试连接」。");
1414
+ if (config?.imageProviderBlocker !== null && config?.imageProviderBlocker !== undefined) {
1415
+ blockers.push(`${config.imageProviderBlocker},配好点「测试连接」。`);
1285
1416
  }
1286
1417
  known.实验性 = "45°地图地块生成是实验性功能:几何(参考图/拼图/裁剪)由本地代码算、有像素级自检,可靠;不稳定的是「AI 能否照着占格形状画出对的造型」,非矩形占地经常要重跑。";
1418
+ known.生图后端 = config?.imageProviderSummary;
1287
1419
  known.四个阶段 = "① 生成地块(★计费;参考图会按占格形状自动渲染,不用手动准备)→ ② 验收 → ③ 拼成地图(本地免费,可反复)→ ④ 导出";
1288
1420
  known.几何由代码保证 = "等距参考图由本地代码按「占格形状」渲染(严格 2:1 等距),AI 只负责填内容。实测这样菱形比例达标率 100%";
1289
1421
  known.默认地块清单 = "9 类地形(草/土/石/灌木,各 1~2 变体)+ 4 个独立装饰(树/松树/巨石)+ 1 栋跨 2×2 格建筑";
@@ -1309,9 +1441,11 @@ function intakeFor(module, id, told, config, target) {
1309
1441
  ? "新建一个序列帧任务,还是在已有任务上继续?"
1310
1442
  : module === "tile"
1311
1443
  ? "新建一个地图地块项目,还是在已有项目上继续?"
1312
- : "新建一个骨骼动画任务,还是在已有任务上继续?",
1444
+ : module === "map"
1445
+ ? "新建一个地图项目,还是在已有项目上继续?"
1446
+ : "新建一个骨骼动画任务,还是在已有任务上继续?",
1313
1447
  why: "后面的参数都挂在项目 / 任务上。",
1314
- how: "新建:game_material_call({method:'createProject'|'createImageJob'|'createSequenceJob'|'createRigJob'|'createTileProject', payload:{name}}),返回的 id 就是后续 payload 里的 projectId / jobId。"
1448
+ how: "新建:game_material_call({method:'createProject'|'createImageJob'|'createSequenceJob'|'createRigJob'|'createTileProject'|'createMapProject', payload:{name}}),返回的 id 就是后续 payload 里的 projectId / jobId。"
1315
1449
  });
1316
1450
  }
1317
1451
  if (module === "sprite") {
@@ -1387,16 +1521,20 @@ const IMAGE_MAX_BYTES = 30 * 1024 * 1024;
1387
1521
  const VIDEO_MAX_BYTES = 40 * 1024 * 1024;
1388
1522
  /** 各模块允许的 kind,避免把「源图」传到「参考视频」这类错位。 */
1389
1523
  const UPLOAD_KINDS = {
1390
- sprite: ["source"],
1524
+ sprite: ["source", "video"],
1391
1525
  image: ["ref", "item"],
1392
1526
  sequence: ["firstFrame", "lastFrame", "referenceImage", "referenceVideo"],
1393
1527
  rig: ["source", "part"],
1394
1528
  // 地图地块**不需要上传素材**:地块由代码渲染的菱形模板 + 提示词生成。
1395
1529
  // 留空数组而不是漏掉这一项 —— 漏掉会让类型检查失败,而空数组能让
1396
1530
  // 「上传」这条路给出明确的报错信息(见 uploadFromPath)。
1397
- tile: []
1531
+ tile: [],
1532
+ // 地图编辑器就是**导入素材**起家的:这里上传的就是 tileset 图集原图。
1533
+ map: ["tileset"]
1398
1534
  };
1399
- async function uploadFromPath(gateway, module, id, kind, path, name) {
1535
+ /** sprite 的本地视频槽位:`turn`(转圈)或八个方向之一。 */
1536
+ const SPRITE_VIDEO_SLOTS = ["turn", "front", "back", "downLeft", "downRight", "upLeft", "upRight", "left", "right"];
1537
+ async function uploadFromPath(gateway, module, id, kind, path, name, key) {
1400
1538
  if (id === "")
1401
1539
  throw new Error("id 不能为空");
1402
1540
  if (!UPLOAD_KINDS[module].includes(kind)) {
@@ -1412,7 +1550,10 @@ async function uploadFromPath(gateway, module, id, kind, path, name) {
1412
1550
  }
1413
1551
  if (!info.isFile())
1414
1552
  throw new Error(`不是文件:${absolute}`);
1415
- const isVideo = kind === "referenceVideo";
1553
+ // 「是不是视频」按 kind 判(序列帧的参考视频、sprite 的本地自选视频),
1554
+ // 上限与嗅探都跟着它走:落到图片那条路上会被图片嗅探当场拒掉,而且 30MB 的上限
1555
+ // 会让一段正常的手机视频莫名其妙传不进来。
1556
+ const isVideo = kind === "referenceVideo" || kind === "video";
1416
1557
  const limit = isVideo ? VIDEO_MAX_BYTES : IMAGE_MAX_BYTES;
1417
1558
  if (info.size > limit) {
1418
1559
  throw new Error(`文件 ${(info.size / 1024 / 1024).toFixed(1)}MB 超过上限 ${(limit / 1024 / 1024).toFixed(0)}MB:${absolute}`);
@@ -1424,7 +1565,29 @@ async function uploadFromPath(gateway, module, id, kind, path, name) {
1424
1565
  throw new Error(`无法识别的图片格式(支持 PNG / JPEG / WebP / GIF / BMP):${absolute}`);
1425
1566
  }
1426
1567
  const call = gateway;
1568
+ /** sprite 的本地视频要额外回报「落到哪个槽位、有没有顺手抽帧」。 */
1569
+ let videoResult;
1427
1570
  if (module === "sprite") {
1571
+ if (kind === "video") {
1572
+ // 槽位必须显式给:猜一个(比如默认转圈)会把一段行走视频塞进错误的位置,
1573
+ // 而且产物看起来「成功了」——只能等着后面几步出错。
1574
+ const slot = key ?? "";
1575
+ if (!SPRITE_VIDEO_SLOTS.includes(slot)) {
1576
+ throw new Error(`sprite + kind=video 必须给 key(可用:${SPRITE_VIDEO_SLOTS.join(" / ")}),收到:${slot === "" ? "(空)" : slot}`);
1577
+ }
1578
+ videoResult = await call.uploadVideo({ projectId: id, key: slot, name: fileName, data: base64 });
1579
+ return {
1580
+ module,
1581
+ id,
1582
+ kind,
1583
+ key: slot,
1584
+ name: fileName,
1585
+ path: absolute,
1586
+ bytes: info.size,
1587
+ video: videoResult,
1588
+ ...openInfo({ module, projectId: id }, "点开确认视频已就位")
1589
+ };
1590
+ }
1428
1591
  await call.uploadSource({ projectId: id, name: fileName, data: base64 });
1429
1592
  }
1430
1593
  else if (module === "image") {
@@ -1433,6 +1596,9 @@ async function uploadFromPath(gateway, module, id, kind, path, name) {
1433
1596
  else
1434
1597
  await call.addImageItem({ jobId: id, name: fileName, data: base64 });
1435
1598
  }
1599
+ else if (module === "map") {
1600
+ await call.importMapTileset({ projectId: id, name: fileName, data: base64 });
1601
+ }
1436
1602
  else if (module === "rig") {
1437
1603
  if (kind === "part")
1438
1604
  await call.uploadRigPart({ jobId: id, name: fileName, data: base64 });
@@ -1488,7 +1654,16 @@ function renderIntake(value) {
1488
1654
  }
1489
1655
  function renderUpload(value) {
1490
1656
  const tail = typeof value.openUrl === "string" ? `\n打开界面:[${value.openHint}](${value.openUrl})` : "";
1491
- return `已上传 ${value.name}(${(value.bytes / 1024).toFixed(0)} KB)→ ${value.module} · ${value.id} · ${value.kind}${tail}`;
1657
+ const slot = typeof value.key === "string" ? ` · 槽位 ${value.key}` : "";
1658
+ const video = value.video ?? {};
1659
+ const note = typeof value.key === "string"
1660
+ ? video.key === "turn"
1661
+ ? video.extractStarted === true
1662
+ ? ";已自动开始抽候选帧并切出八个方向图"
1663
+ : `;抽帧没有自动开始(${video.extractReason ?? "未知原因"}),需要手动 runTurnFrames`
1664
+ : ";接着到第 3 步 runFrames 抽帧即可"
1665
+ : "";
1666
+ return `已上传 ${value.name}(${(value.bytes / 1024).toFixed(0)} KB)→ ${value.module} · ${value.id} · ${value.kind}${slot}${note}${tail}`;
1492
1667
  }
1493
1668
  function renderReviewMode(value) {
1494
1669
  const tail = typeof value.openUrl === "string" ? `\n打开界面:[${value.openHint}](${value.openUrl})` : "";
@@ -1552,6 +1727,42 @@ function renderRigStageDetail(stage) {
1552
1727
  }
1553
1728
  return lines;
1554
1729
  }
1730
+ /** 模块六四个阶段的显示名(key 与对话面契约不变,变的只是中文名)。 */
1731
+ const MAP_STAGE_LABELS = { assets: "素材", rules: "自动连接", paint: "地图", export: "导出" };
1732
+ /**
1733
+ * 地图编辑器的验收摘要:素材 / 阶段 / 地图 / 预览图 / 导出产物。
1734
+ *
1735
+ * 这里的每一条都是**能点开的绝对 URL** —— 模型把它贴进回复,用户点一下就能看图。
1736
+ * 判定依据用 `Array.isArray(value.tilesets)`(只有模块六的快照有这个字段)。
1737
+ */
1738
+ function renderMapSummary(value) {
1739
+ const lines = [];
1740
+ if (Array.isArray(value.stages)) {
1741
+ lines.push(` 阶段:${value.stages
1742
+ .map((stage) => `${MAP_STAGE_LABELS[stage.stage] ?? stage.stage}:${stage.status}${stage.approved ? " · 已通过" : ""}${stage.error ? ` · ${stage.error}` : ""}`)
1743
+ .join(" ")}`);
1744
+ }
1745
+ if (typeof value.cols === "number" && typeof value.rows === "number")
1746
+ lines.push(` 地图:${value.cols}×${value.rows},已画 ${value.filled ?? 0} 格`);
1747
+ for (const layer of value.layers ?? [])
1748
+ lines.push(` · ${layer.name}:${layer.filled} 格`);
1749
+ for (const tileset of value.tilesets ?? []) {
1750
+ lines.push(` 素材「${tileset.name}」${tileset.imageWidth}×${tileset.imageHeight} · ${tileset.reason ?? ""} · ${tileset.tileCount} 块 · 笔刷 ${tileset.palette?.length ?? 0} 个`);
1751
+ if (typeof tileset.url === "string")
1752
+ lines.push(` ${tileset.url}`);
1753
+ }
1754
+ for (const url of value.previewUrls ?? value.preview ?? [])
1755
+ lines.push(` 验收预览图:${url}`);
1756
+ if (typeof value.exportBaseUrl === "string" && value.exportBaseUrl !== "")
1757
+ lines.push(` 导出目录:${value.exportBaseUrl}`);
1758
+ if (typeof value.exportPath === "string" && value.exportPath !== "")
1759
+ lines.push(` 导出目录(本机路径):${value.exportPath}`);
1760
+ for (const file of value.exportFiles ?? [])
1761
+ lines.push(` ${file}`);
1762
+ for (const warning of value.warnings ?? [])
1763
+ lines.push(` ⚠ ${warning}`);
1764
+ return lines;
1765
+ }
1555
1766
  function renderStatus(value) {
1556
1767
  if (Array.isArray(value.projects)) {
1557
1768
  const lines = [
@@ -1581,6 +1792,11 @@ function renderStatus(value) {
1581
1792
  lines.push(detail);
1582
1793
  }
1583
1794
  }
1795
+ // 地图编辑器(模块六):它的阶段是**对象**(不是数组),素材 / 预览图 / 导出清单
1796
+ // 也不在通用字段里,单独一段。
1797
+ if (Array.isArray(value.tilesets))
1798
+ for (const line of renderMapSummary(value))
1799
+ lines.push(line);
1584
1800
  // 八方向图:阶段①的两种生成方式差异很大,状态里必须写明走的是哪条、
1585
1801
  // 转圈视频与八个截帧位置各是什么——否则 agent 只能对着一张张方向图猜。
1586
1802
  if (value.imageMode !== undefined && value.turn !== undefined) {
@@ -1642,6 +1858,10 @@ function renderReview(value) {
1642
1858
  const lines = [`${value.name}(${value.id})验收包${value.busy ? " — ⏳ 仍有任务在跑" : ""}`];
1643
1859
  if (value.qa !== null && value.qa !== undefined)
1644
1860
  lines.push(renderRigQa(value.qa));
1861
+ // 地图编辑器(模块六):产物形状和别的模块完全不同(素材 + 一张地图 + 导出清单),
1862
+ // 单独走一段,免得掉进下面按 cells / items 迭代的通用分支。
1863
+ if (value.module === "map")
1864
+ lines.push(...renderMapSummary(value));
1645
1865
  if (Array.isArray(value.stages)) {
1646
1866
  for (const stage of value.stages) {
1647
1867
  lines.push(`${stage.title}${stage.stale ? " · 需重做" : ""}`);
@@ -1709,6 +1929,9 @@ function spriteNextActions(snapshot, stage, direction) {
1709
1929
  actions.push(snapshot.sourceFile === null
1710
1930
  ? "还没有源图:先用 game_material_call({method:'uploadSource', payload:{projectId,name,data}}) 上传一张设定图"
1711
1931
  : `转圈视频还没有:game_material_call({method:'runTurnVideo', payload:{projectId}}) 然后 game_material_wait(★花钱一次,约几分钟);视频到手会自动抽候选帧并切出八个方向`);
1932
+ // 本地自选视频和远程生成是**并列**的两条路:用户手上已经有一段转圈视频时,
1933
+ // 这条一步到位、不花钱,不应该被埋在描述里。
1934
+ actions.push("也可以不用远程生成:把现成的视频用 game_material_upload({module:'sprite', id, kind:'video', key:'turn', path}) 传进来(等价于界面上的「选择本地视频」),导入后同样会自动抽候选帧并切出八个方向");
1712
1935
  }
1713
1936
  else {
1714
1937
  actions.push(`转圈视频已就绪,还差 ${images.total - images.ready} 张方向图:game_material_call({method:'runTurnFrames', payload:{projectId}}) 然后 game_material_wait(本地免费)`);
@@ -1728,6 +1951,7 @@ function spriteNextActions(snapshot, stage, direction) {
1728
1951
  const videos = pick("videos");
1729
1952
  if (videos !== undefined && videos.ready < videos.total && (images === undefined || images.ready === images.total)) {
1730
1953
  actions.push(`视频还差 ${videos.total - videos.ready} 段:game_material_call({method:'runVideos', payload:{projectId}}) 然后 game_material_wait(这一步最贵,约几分钟)`);
1954
+ actions.push("某个方向已经有现成视频时,用 game_material_upload({module:'sprite', id, kind:'video', key:'<方向>', path}) 直接顶替那一段(不花钱),之后照旧 runFrames 抽帧");
1731
1955
  }
1732
1956
  const frames = pick("frames");
1733
1957
  if (frames !== undefined && frames.ready < frames.total && (videos === undefined || videos.ready === videos.total)) {