dsh-game-material-master 0.9.2 → 0.10.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/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { assertVideoBackendReady, videoBackendOf } from "./videogen.js";
1
2
  /**
2
3
  * dsh-8dir-sprites —— 宿主半区。
3
4
  *
@@ -19,7 +20,7 @@ import { ARK_MODEL_PRESETS, CUSTOM_PROTOCOLS, CUSTOM_PROTOCOL_DEFAULTS, DEFAULT_
19
20
  import { DEFAULT_ROW_ORDER, DIRECTION_KEYS, TURN_DIRECTION_DEFAULT, TURN_FRAME_COUNT_MAX, TURN_FRAME_COUNT_MIN, defaultPrompts, directionOf, localizePrompts, normalizePromptLang } from "./directions.js";
20
21
  import { checkFfmpeg } from "./media.js";
21
22
  import { testArk } from "./ark.js";
22
- import { customImageBlocker, imageModelOf, imageProviderBlocker, imageProviderSummary, isCustomProvider, testCustomImage } from "./imageprovider.js";
23
+ import { customImageBlocker, imageModelOf, imageSizeOf, imageProviderBlocker, imageProviderSummary, imageUsesConfiguredSize, testCustomImage } from "./imageprovider.js";
23
24
  import { detectComfyBindings, fetchComfyObjectInfo, formatBinding, normalizeComfyBaseUrl, normalizeComfyCookies, parseComfyWorkflow, testComfy } from "./comfy.js";
24
25
  import { COMP_SHARE_BASE_URL, COMP_SHARE_MODEL_ID, capabilityOf, isCompshareModel, normalizeDuration, normalizeResolution, pathPrefixOf, testMiniMax } from "./minimax.js";
25
26
  import { activatePipeline, applyTurnPicks, clearVideos, disposePipeline, ensurePoller, exportImages, importLocalVideo, listJobs, pollVideosOnce, resetFramePicks, resetTurnPicks, setFramePick, setFramePicks, setImageMode, setTurnPick, setTurnPicks, startAllImages, startCompose, startFramePick, startExtract, startImage, startRekey, startTurnFrames, startTurnVideo, startVideos } from "./pipeline.js";
@@ -27,7 +28,7 @@ import { assetPath, createProject, deleteProject, listProjects, log, patchProjec
27
28
  import * as imagegen from "./imagegen.js";
28
29
  import * as seqgen from "./seqgen.js";
29
30
  import * as riggen from "./riggen.js";
30
- import * as tilegen from "./tilegen.js";
31
+ import * as isogen from "./isogen.js";
31
32
  import * as mapgen from "./mapgen.js";
32
33
  import * as musicgen from "./musicgen.js";
33
34
  import * as sfxgen from "./sfxgen.js";
@@ -48,58 +49,6 @@ import { registerStudioTools } from "./tools.js";
48
49
  *
49
50
  * 另外用 `ctx.webServer` 注册一条 prefix 路由,把各模块的产物直接发给浏览器。
50
51
  */
51
- /**
52
- * 合并界面提交的地块清单:保留已生成的变体,只更新可编辑字段。
53
- *
54
- * 为什么要合并而不是直接覆盖:清单里带着 `variants`(那是花钱生成的产物),
55
- * 界面只提交 `key/label/content/variantCount/...`。直接覆盖会让用户
56
- * **改一个标签就丢掉整批已生成的图**,而且不会报错。
57
- *
58
- * 返回 `changed`:**提示词真的变了**的那些地块 key。调用方只能作废这些 ——
59
- * 只改标签 / 只改变体数不该把别的(或自己的)产物废掉。
60
- * 判断「提示词是否变化」看的是 `content` 与 `mode`,因为只有它们会进提示词。
61
- */
62
- function mergeTileItems(existing, incoming) {
63
- const byKey = new Map(existing.map((item) => [item.key, item]));
64
- const out = [];
65
- const changed = [];
66
- for (const raw of incoming) {
67
- const key = typeof raw?.key === "string" ? raw.key : "";
68
- if (key === "")
69
- continue;
70
- const previous = byKey.get(key);
71
- const variantCount = clampInt(raw.variantCount, previous?.variantCount ?? 1, 1, 6);
72
- // ★ 形状:以「相对锚点的格子集合」为准,任意形状(L 形 / T 形 / 线形)都收。
73
- // 老数据只有 `footprint`(列×行),由 `normalizeShape` 无损转成矩形形状。
74
- const shape = tilegen.normalizeShape(raw, previous);
75
- const footprint = tilegen.boundingRectOf(shape);
76
- const next = {
77
- key,
78
- label: typeof raw.label === "string" && raw.label !== "" ? raw.label : (previous?.label ?? key),
79
- kind: raw.kind === "decor" || raw.kind === "building" ? raw.kind : "terrain",
80
- family: typeof raw.family === "string" && raw.family !== "" ? raw.family : (previous?.family ?? key),
81
- // `footprint` 保留为**包围矩形**:老版本读到的至少还是个合理的矩形
82
- footprint,
83
- shape,
84
- content: typeof raw.content === "string" ? raw.content : (previous?.content ?? ""),
85
- mode: raw.mode === "plain" || raw.mode === "grid2x2" ? raw.mode : (previous?.mode ?? "template"),
86
- variantCount,
87
- variants: previous === undefined ? [] : previous.variants.slice(0, variantCount),
88
- approved: previous?.approved
89
- };
90
- // 内容、生成方式或**形状**变了 → 这个地块已生成的变体失效
91
- // (它们画的是旧内容 / 旧轮廓)。**只作废这一个**,别连累别的。
92
- const shapeChanged = previous !== undefined
93
- && tilegen.shapeKey(shape) !== tilegen.shapeKey(tilegen.normalizeShape(previous, undefined));
94
- if (previous !== undefined && (previous.content !== next.content || previous.mode !== next.mode || shapeChanged)) {
95
- next.variants = [];
96
- next.approved = undefined;
97
- changed.push(key);
98
- }
99
- out.push(next);
100
- }
101
- return { items: out.length > 0 ? out : existing, changed };
102
- }
103
52
  export const name = "dsh-game-material-master";
104
53
  /**
105
54
  * `webServer` 必须声明成硬依赖:它要等真正 listen 成功之后才可用,
@@ -285,6 +234,17 @@ export class GameStudioGateway extends TypertRemoteService {
285
234
  imageProviderSummary: imageProviderSummary(config),
286
235
  /** 当前生效的生图模型(模块里那个只读展示位用它,比 summary 短)。 */
287
236
  imageModel: imageModelOf(config),
237
+ imageProviderSize: imageSizeOf(config),
238
+ videoProviderBackend: videoBackendOf(config),
239
+ videoProviderModel: videoBackendOf(config) === "toapis" ? config.toapisVideoModel : config.minimaxModel,
240
+ videoProviderBaseUrl: videoBackendOf(config) === "toapis" ? config.toapisBaseUrl : videoBackendOf(config) === "comfy" ? config.comfyBaseUrl : config.minimaxBaseUrl,
241
+ videoProviderBlocker: (() => { try {
242
+ assertVideoBackendReady(config);
243
+ return null;
244
+ }
245
+ catch (error) {
246
+ return error.message;
247
+ } })(),
288
248
  imageProviderBlocker: imageProviderBlocker(config) ?? null,
289
249
  customImageBlocker: customImageBlocker(config) ?? null,
290
250
  minimaxModels: MINIMAX_MODEL_PRESETS,
@@ -343,6 +303,15 @@ export class GameStudioGateway extends TypertRemoteService {
343
303
  const input = asRecord(payload);
344
304
  const patch = {};
345
305
  const directKeys = [
306
+ "toapisBaseUrl",
307
+ "toapisImageModel",
308
+ "toapisImageSize",
309
+ "toapisImageQuality",
310
+ "toapisVideo",
311
+ "toapisVideoModel",
312
+ "toapisVideoDuration",
313
+ "toapisVideoResolution",
314
+ "toapisTimeoutMs",
346
315
  "imageProvider",
347
316
  "customProtocol",
348
317
  "customBaseUrl",
@@ -420,6 +389,10 @@ export class GameStudioGateway extends TypertRemoteService {
420
389
  if (input[key] !== undefined)
421
390
  patch[key] = input[key];
422
391
  }
392
+ if (typeof input.toapisApiKey === "string")
393
+ patch.toapisApiKey = input.toapisApiKey.trim();
394
+ if (input.clearToapisApiKey === true)
395
+ patch.toapisApiKey = "";
423
396
  if (typeof input.arkApiKey === "string")
424
397
  patch.arkApiKey = input.arkApiKey.trim();
425
398
  if (typeof input.minimaxApiKey === "string")
@@ -901,12 +874,9 @@ export class GameStudioGateway extends TypertRemoteService {
901
874
  await riggen.writeRigJob(job);
902
875
  return { ok: true, id, module, reviewMode };
903
876
  }
904
- // 地图地块(模块五)。**别重犯 rig 早期那个漏**:
905
- // 少了这个分支,「固定流程第 0 步必须问清审核模式」对 tile 就落不了地。
906
- if (module === "tile") {
907
- // 走 `patchTileProject`(带写队列),别用裸的 `writeTileProject`:
908
- // 裸写会绕过队列,与后台作业的 report() 撞同一个 project.json。
909
- await tilegen.patchTileProject(id, (project) => {
877
+ // 45° 地图编辑器(模块五 · iso)。与模块六同一套「固定流程第 0 步问审核模式」。
878
+ if (module === "iso") {
879
+ await isogen.patchIsoProject(id, (project) => {
910
880
  project.reviewMode = reviewMode;
911
881
  });
912
882
  return { ok: true, id, module, reviewMode };
@@ -940,269 +910,175 @@ export class GameStudioGateway extends TypertRemoteService {
940
910
  }
941
911
  throw new Error(`未知模块:${module}`);
942
912
  }
943
- // ── 地图地块生成(模块五)──────────────────────────────────────────────
944
- async listTileProjects() {
945
- return { projects: await tilegen.listTileProjects() };
913
+ // ── 45° 地图编辑器(模块五 · iso)──────────────────────────────────────
914
+ async listIsoProjects() {
915
+ return { projects: await isogen.listIsoProjects() };
946
916
  }
947
- async createTileProject(payload) {
917
+ async createIsoProject(payload) {
948
918
  const input = asRecord(payload);
949
- const project = await tilegen.createTileProject(asString(input.name, "未命名地图"), {
950
- style: typeof input.style === "string" ? input.style : undefined,
951
- lang: typeof input.lang === "string" ? input.lang : undefined,
952
- settings: input.settings
919
+ const project = await isogen.createIsoProject(asString(input.name, "未命名地图"), {
920
+ cell: input.cell,
921
+ cols: typeof input.cols === "number" ? input.cols : undefined,
922
+ rows: typeof input.rows === "number" ? input.rows : undefined,
923
+ wrap: typeof input.wrap === "boolean" ? input.wrap : undefined
953
924
  });
954
- return tilegen.tileView(project);
925
+ return isogen.isoView(project);
955
926
  }
956
- /**
957
- * 读项目。
958
- * `lang` 决定「从没改过的地块清单 / 画风描述」用哪一国话的默认值 ——
959
- * 它必须出现在 wire 的 schema 里,否则会被静默丢掉(见 wire.ts 的注释)。
960
- */
961
- async getTileProject(payload) {
962
- const input = asRecord(payload);
963
- const project = await tilegen.readTileProject(asString(input.projectId), asString(input.lang));
927
+ async getIsoProject(payload) {
928
+ const project = await isogen.readIsoProject(asString(asRecord(payload).projectId));
964
929
  if (project === undefined)
965
- throw new Error(`项目不存在:${asString(input.projectId)}`);
966
- return tilegen.tileView(project);
930
+ throw new Error("项目不存在");
931
+ return isogen.isoView(project);
967
932
  }
968
- async deleteTileProject(payload) {
933
+ async saveIsoProject(payload) {
934
+ const input = asRecord(payload);
935
+ return isogen.saveIsoProject(asString(input.projectId), {
936
+ name: typeof input.name === "string" ? input.name : undefined,
937
+ wrap: typeof input.wrap === "boolean" ? input.wrap : undefined
938
+ });
939
+ }
940
+ async deleteIsoProject(payload) {
969
941
  const id = asString(asRecord(payload).projectId);
970
- await tilegen.deleteTileProject(id);
942
+ await isogen.deleteIsoProject(id);
971
943
  return { ok: true };
972
944
  }
973
- async saveTileProject(payload) {
945
+ async importIsoTileset(payload) {
974
946
  const input = asRecord(payload);
975
- const id = asString(input.projectId);
976
- const lang = typeof input.lang === "string" ? input.lang : undefined;
977
- // ⚠️ 整个「读 → 改 → 写」都放进 `patchTileProject`(它带写队列)。
978
- // 以前这里是自己 read、改完再调裸的 `writeTileProject` —— 那条路径**绕过队列**,
979
- // 于是它和后台作业的 `report()` 会同时 rename 同一个 project.json,
980
- // 在 Windows 上报 EPERM、并且互相覆盖(丢更新)。
981
- // 实测:用户点「保存布局」时后台恰好在收尾,就报「保存失败」。
982
- const next = await tilegen.patchTileProject(id, (project) => {
983
- if (typeof input.name === "string" && input.name.trim() !== "")
984
- project.name = input.name.trim();
985
- if (typeof input.style === "string" && input.style !== project.style) {
986
- project.style = input.style;
987
- // 改画风 = 改**每一个**地块的提示词 → 全部产物作废(重新生成要花钱)
988
- tilegen.invalidateItems(project);
989
- }
990
- if (input.resetItemsToDefault === true) {
991
- project.items = tilegen.defaultTileItems(lang);
992
- tilegen.invalidateItems(project);
993
- }
994
- else if (Array.isArray(input.items)) {
995
- const merged = mergeTileItems(project.items, input.items);
996
- project.items = merged.items;
997
- // ⚠️ 只作废**提示词真的变了**的那些地块。
998
- // 这里一度无脑调 `invalidateFrom(project, "generate")`,而它是全量销毁 ——
999
- // 结果「只改一个标签」也会把全部(花钱生成的)产物清空。
1000
- // 真机验证时抓出来的:验收之后任何一次保存都会让产物消失。
1001
- if (merged.changed.length > 0)
1002
- tilegen.invalidateItems(project, merged.changed);
1003
- }
1004
- if (input.settings !== undefined) {
1005
- const settings = { ...project.settings, ...input.settings };
1006
- if (settings.cellWidth !== project.settings.cellWidth || settings.cellHeight !== project.settings.cellHeight) {
1007
- project.settings = settings;
1008
- // 几何规格变了:模板与全部产物都作废
1009
- tilegen.invalidateFrom(project, "template");
1010
- }
1011
- else {
1012
- project.settings = settings;
1013
- }
1014
- }
1015
- return project;
947
+ const result = await isogen.importIsoTileset(asString(input.projectId), asString(input.name), asString(input.data), {
948
+ kind: input.kind,
949
+ sourceCell: input.sourceCell,
950
+ animRows: input.animRows,
951
+ frames: input.frames,
952
+ fps: input.fps,
953
+ loop: input.loop,
954
+ clarity: input.clarity,
955
+ footprint: input.footprint,
956
+ anchor: input.anchor,
957
+ objectScale: input.objectScale,
958
+ pass: input.pass,
959
+ keyGreen: input.keyGreen
1016
960
  });
1017
- return tilegen.tileView(next);
961
+ const project = await isogen.readIsoProject(asString(input.projectId));
962
+ const revisions = await isogen.tilesetRevisions(asString(input.projectId));
963
+ return { tilesets: result.tilesets.map((tileset) => isogen.isoTilesetBrief(tileset, revisions.get(tileset.id), project?.tilesets)), warnings: result.warnings };
1018
964
  }
1019
- async runTileItems(payload) {
1020
- const input = asRecord(payload);
1021
- const keys = Array.isArray(input.keys) ? input.keys.filter((k) => typeof k === "string") : undefined;
1022
- return tilegen.runGenerateStage(asString(input.projectId), { keys });
965
+ async importIsoSampleTileset(payload) {
966
+ const result = await isogen.importIsoSampleTileset(asString(asRecord(payload).projectId));
967
+ const project = await isogen.readIsoProject(asString(asRecord(payload).projectId));
968
+ const revisions = await isogen.tilesetRevisions(asString(asRecord(payload).projectId));
969
+ return { tilesets: result.tilesets.map((tileset) => isogen.isoTilesetBrief(tileset, revisions.get(tileset.id), project?.tilesets)), warnings: result.warnings };
1023
970
  }
1024
- async runTileItem(payload) {
971
+ async composeIsoAsset(payload) {
1025
972
  const input = asRecord(payload);
1026
- return tilegen.runGenerateStage(asString(input.projectId), {
1027
- key: asString(input.key),
1028
- variant: typeof input.variant === "number" ? input.variant : undefined
973
+ return isogen.composeIsoAsset({
974
+ projectId: asString(input.projectId),
975
+ name: asString(input.name),
976
+ files: Array.isArray(input.files) ? input.files.map((file) => asString(file)) : [],
977
+ kind: input.kind,
978
+ footprint: input.footprint,
979
+ keyGreen: input.keyGreen === false ? false : true
1029
980
  });
1030
981
  }
1031
- async setTileApproved(payload) {
982
+ async saveIsoTileset(payload) {
1032
983
  const input = asRecord(payload);
1033
- const id = asString(input.projectId);
1034
- const approved = input.approved === true;
1035
- const key = typeof input.key === "string" ? input.key : undefined;
1036
- const variant = typeof input.variant === "number" ? input.variant : undefined;
1037
- await tilegen.patchTileProject(id, (project) => {
1038
- let touched = 0;
1039
- for (const item of project.items) {
1040
- if (key !== undefined && item.key !== key)
1041
- continue;
1042
- if (variant !== undefined) {
1043
- const entry = item.variants[variant];
1044
- if (entry === undefined)
1045
- continue;
1046
- entry.approved = approved;
1047
- touched++;
1048
- continue;
1049
- }
1050
- item.approved = approved;
1051
- for (const entry of item.variants)
1052
- entry.approved = approved;
1053
- touched++;
1054
- }
1055
- if (touched === 0)
1056
- throw new Error(key === undefined ? "没有可验收的地块" : `找不到地块:${key}`);
1057
- // 验收只影响打勾,不作废任何东西(这一条是有意的)
1058
- const allApproved = project.items.every((item) => item.variants.length > 0 && item.variants.every((v) => v.approved === true));
1059
- project.stages.review = { status: allApproved ? "done" : "idle", at: new Date().toISOString() };
1060
- // ⚠️ 日志要用 tile 项目自己的字段(`project.logs`),不能用模块一那个 `log()` ——
1061
- // 它写的是 `project.log`,对 tile 项目来说是 undefined,一调就抛
1062
- // `Cannot read properties of undefined (reading 'push')`。
1063
- // 实测:走网关验收一个地块就会直接崩(纯函数自检发现不了)。
1064
- appendJobLog(project.logs, "info", `${approved ? "通过" : "取消通过"}:${key ?? "全部"}${variant !== undefined ? ` 第 ${variant + 1} 张` : ""}`);
984
+ const result = await isogen.saveIsoTileset(asString(input.projectId), asString(input.tilesetId), {
985
+ name: typeof input.name === "string" ? input.name : undefined,
986
+ fps: input.fps === null ? null : typeof input.fps === "number" ? input.fps : undefined,
987
+ loop: input.loop
1065
988
  });
1066
- return { ok: true };
989
+ return { tileset: isogen.isoTilesetBrief(result.tileset), warnings: result.warnings };
1067
990
  }
1068
- async runTileMap(payload) {
991
+ async removeIsoTileset(payload) {
1069
992
  const input = asRecord(payload);
1070
- return tilegen.runMapStage(asString(input.projectId), {
1071
- rows: typeof input.rows === "number" ? input.rows : undefined,
993
+ const result = await isogen.removeIsoTileset(asString(input.projectId), asString(input.tilesetId));
994
+ return { ok: true, ...result };
995
+ }
996
+ async saveIsoDoc(payload) {
997
+ const input = asRecord(payload);
998
+ const result = await isogen.saveIsoDoc(asString(input.projectId), {
999
+ name: typeof input.name === "string" ? input.name : undefined,
1072
1000
  cols: typeof input.cols === "number" ? input.cols : undefined,
1001
+ rows: typeof input.rows === "number" ? input.rows : undefined,
1002
+ layers: Array.isArray(input.layers) ? input.layers : undefined,
1003
+ addLayer: input.addLayer,
1004
+ removeLayerId: typeof input.removeLayerId === "string" ? input.removeLayerId : undefined,
1005
+ moveLayer: input.moveLayer,
1006
+ clearLayerId: typeof input.clearLayerId === "string" ? input.clearLayerId : undefined
1007
+ });
1008
+ return result;
1009
+ }
1010
+ async applyIsoOps(payload) {
1011
+ const input = asRecord(payload);
1012
+ return isogen.applyIsoOps(asString(input.projectId), Array.isArray(input.ops) ? input.ops : [], {
1013
+ stroke: typeof input.stroke === "string" ? input.stroke : undefined,
1014
+ have: Array.isArray(input.have) ? input.have : undefined
1015
+ });
1016
+ }
1017
+ async isoUndo(payload) {
1018
+ const input = asRecord(payload);
1019
+ return isogen.isoUndo(asString(input.projectId), Array.isArray(input.have) ? input.have : []);
1020
+ }
1021
+ async isoRedo(payload) {
1022
+ const input = asRecord(payload);
1023
+ return isogen.isoRedo(asString(input.projectId), Array.isArray(input.have) ? input.have : []);
1024
+ }
1025
+ async isoPlan(payload) {
1026
+ const input = asRecord(payload);
1027
+ return isogen.isoPlan(asString(input.projectId), {
1028
+ view: input.view,
1029
+ have: Array.isArray(input.have) ? input.have : undefined,
1030
+ layerIds: Array.isArray(input.layerIds) ? input.layerIds : undefined,
1031
+ pending: Array.isArray(input.pending) ? input.pending : undefined,
1032
+ pass: input.pass === true
1033
+ });
1034
+ }
1035
+ async runIsoGenerate(payload) {
1036
+ const input = asRecord(payload);
1037
+ const kind = input.kind === "maze" || input.kind === "continent" ? input.kind : "random";
1038
+ return isogen.runIsoGenerate(asString(input.projectId), {
1039
+ kind,
1040
+ tiles: Array.isArray(input.tiles) ? input.tiles : undefined,
1073
1041
  seed: typeof input.seed === "number" ? input.seed : undefined,
1074
- fill: typeof input.fill === "string" ? input.fill : undefined,
1075
- decorDensity: typeof input.decorDensity === "number" ? input.decorDensity : undefined,
1076
- reroll: input.reroll === true
1042
+ layerId: typeof input.layerId === "string" ? input.layerId : undefined
1077
1043
  });
1078
1044
  }
1079
- async saveTileMapCells(payload) {
1045
+ async runIsoPreview(payload) {
1046
+ return isogen.runIsoPreview(asString(asRecord(payload).projectId));
1047
+ }
1048
+ async runIsoExport(payload) {
1080
1049
  const input = asRecord(payload);
1081
- const id = asString(input.projectId);
1082
- await tilegen.patchTileProject(id, (project) => {
1083
- if (Array.isArray(input.cells)) {
1084
- const cells = input.cells
1085
- .filter((row) => Array.isArray(row))
1086
- .map((row) => row.map((cell) => String(cell)));
1087
- if (cells.length > 0) {
1088
- project.map.cells = cells;
1089
- project.map.rows = cells.length;
1090
- project.map.cols = Math.max(...cells.map((row) => row.length));
1091
- // ⚠️ `buildings` / `buildingGround` 是**由布局推导出来的**记录,
1092
- // 布局一换就必须丢掉重推。留着的话会出现「幽灵建筑」:
1093
- // 用户把建筑挪到别处,旧位置那条记录还在,拼图会在**没有建筑的地方**
1094
- // 硬画一栋楼(实测地图上凭空多出一片屋顶)。
1095
- project.map.buildings = [];
1096
- project.map.buildingGround = [];
1097
- }
1098
- }
1099
- if (typeof input.seed === "number")
1100
- project.map.seed = Math.trunc(input.seed);
1101
- // 装饰与垫底地面:界面回传的既可能是**地块键**(`tree`),也可能是
1102
- // 早期版本留下的**贴图路径**(`decor/tree.v1.png`)。两种都接受,
1103
- // 统一落成宿主认识的 `key#index`。
1104
- const resolveVariant = (raw) => {
1105
- const value = String(raw ?? "");
1106
- if (value === "")
1107
- return "";
1108
- const item = project.items.find((it) => it.key === value);
1109
- if (item !== undefined) {
1110
- const first = item.variants.find((v) => v.cell !== undefined);
1111
- if (first !== undefined)
1112
- return `${value}#${first.index}`;
1113
- }
1114
- for (const it of project.items) {
1115
- const hit = it.variants.find((v) => v.cell === value);
1116
- if (hit !== undefined)
1117
- return `${it.key}#${hit.index}`;
1118
- }
1119
- return "";
1120
- };
1121
- if (input.decor !== undefined && typeof input.decor === "object") {
1122
- const next = {};
1123
- for (const [pos, raw] of Object.entries(input.decor)) {
1124
- const name = resolveVariant(raw);
1125
- if (name !== "")
1126
- next[pos] = name;
1127
- }
1128
- project.map.decor = next;
1129
- }
1130
- // ★ 建筑由界面**显式回传**(`layouts`):它带着占格与垫底地面。
1131
- //
1132
- // 不靠「cells 里有没有建筑键」反推:那样界面为了预览就得把建筑键铺满占格,
1133
- // 而一旦占格被清空(拼图会清)就再也推不出来了 —— 建筑会凭空消失。
1134
- if (Array.isArray(input.layouts)) {
1135
- project.map.buildings = [];
1136
- project.map.buildingGround = [];
1137
- for (const raw of input.layouts) {
1138
- const e = raw;
1139
- const r = Math.trunc(Number(e.r));
1140
- const c = Math.trunc(Number(e.c));
1141
- const key = String(e.key ?? "");
1142
- if (!Number.isFinite(r) || !Number.isFinite(c) || key === "")
1143
- continue;
1144
- // ★ 形状优先(任意形状,含 L 形);界面只给了宽高才退回矩形。
1145
- const shape = tilegen.parseShape(e.shape)
1146
- ?? tilegen.rectShape(Math.max(1, Math.min(64, Math.trunc(Number(e.width ?? 1)))), Math.max(1, Math.min(64, Math.trunc(Number(e.height ?? 1)))));
1147
- const [fw, fh] = tilegen.boundingRectOf(shape);
1148
- // 越界按**每个格子**判,不是包围矩形 —— L 形的包围盒可能出界而格子还在里面。
1149
- if (r < 0 || c < 0)
1150
- continue;
1151
- if (shape.some(([dr, dc]) => r + dr >= project.map.rows || c + dc >= project.map.cols))
1152
- continue;
1153
- const name = (project.items.find((it) => it.key === key)?.variants ?? [])
1154
- .find((v) => v.cell !== undefined);
1155
- if (name === undefined)
1156
- continue;
1157
- const underName = resolveVariant(e.under);
1158
- project.map.buildings.push([r, c, `${key}#${name.index}`]);
1159
- // 第 5 位是形状:拼图/包围盒读它,`fw/fh` 只是包围矩形(兼容老版本)。
1160
- project.map.buildingGround.push([r, c, fw, fh, underName, shape]);
1161
- // ⚠️ **不要**把占格清成空串。
1162
- //
1163
- // 清了的话这一格什么都不铺,建筑底面菱形的四个角是透明的,
1164
- // 露出来的就是那块**纯色垫底**,和周围有纹理的草地格格不入
1165
- // (真机上看着像建筑拖着一块塑料板)。占格留着地面键,
1166
- // 拼图会照铺地面、再让建筑贴图盖上去。
1167
- //
1168
- // 填的是**地块键**:界面回传的 `cells` 里本来就是地块键;
1169
- // 万一那格是空串或还留着建筑键,就从垫底名反推地块键
1170
- // (`grass#0` → `grass`),反推不出来就退回界面的 `under` 地块键。
1171
- const underItem = String(e.under ?? "");
1172
- const groundKeyForFootprint = project.items.some((it) => it.key === underItem)
1173
- ? underItem
1174
- : String(underName).split("#")[0];
1175
- for (const [dr, dc] of shape) {
1176
- const row = project.map.cells[r + dr];
1177
- const cell = row?.[c + dc];
1178
- if (row === undefined)
1179
- continue;
1180
- // 已经有真地面就留着;空串或残留的建筑键才替换
1181
- const isGround = project.items.some((it) => it.key === cell && it.kind === "terrain");
1182
- if (!isGround && groundKeyForFootprint !== "")
1183
- row[c + dc] = groundKeyForFootprint;
1184
- }
1185
- }
1186
- }
1187
- // 手动改布局不作废地块(那是花钱买的),只作废下游
1188
- tilegen.invalidateFrom(project, "map");
1050
+ return isogen.runIsoExport(asString(input.projectId), {
1051
+ scale: typeof input.scale === "number" ? input.scale : undefined,
1052
+ formats: input.formats
1189
1053
  });
1190
- return { ok: true };
1191
1054
  }
1192
- async runTileExport(payload) {
1193
- return tilegen.runExportStage(asString(asRecord(payload).projectId));
1055
+ async cancelIsoJob(payload) {
1056
+ isogen.cancelIsoJob(asString(asRecord(payload).projectId));
1057
+ return { ok: true };
1194
1058
  }
1195
- async cancelTileJob(payload) {
1196
- const id = asString(asRecord(payload).projectId);
1197
- tilegen.cancelTileJob(id);
1059
+ async setIsoApproved(payload) {
1060
+ const input = asRecord(payload);
1061
+ const id = asString(input.projectId);
1062
+ const approved = input.approved === true;
1063
+ const stage = typeof input.stage === "string" ? input.stage : undefined;
1064
+ await isogen.patchIsoProject(id, (project) => {
1065
+ const stages = stage === undefined ? isogen.ISO_STAGES : [stage];
1066
+ for (const key of stages) {
1067
+ if (key !== "assets" && key !== "paint" && key !== "export")
1068
+ continue;
1069
+ project.stages[key] = { ...project.stages[key], approved, approvedAt: approved ? new Date().toISOString() : undefined };
1070
+ }
1071
+ });
1198
1072
  return { ok: true };
1199
1073
  }
1200
- async revealTileProject(payload) {
1201
- const id = asString(asRecord(payload).projectId);
1202
- const project = await tilegen.readTileProject(id);
1074
+ async revealIsoProject(payload) {
1075
+ const input = asRecord(payload);
1076
+ const id = asString(input.projectId);
1077
+ const project = await isogen.readIsoProject(id);
1203
1078
  if (project === undefined)
1204
1079
  throw new Error(`项目不存在:${id}`);
1205
- const dir = tilegen.tileProjectDir(id);
1080
+ const target = input.target === "export" ? "export" : "project";
1081
+ const dir = await isogen.isoRevealDir(id, target);
1206
1082
  const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "explorer" : "xdg-open";
1207
1083
  try {
1208
1084
  spawn(command, [dir], { detached: true, stdio: "ignore" }).unref();
@@ -1210,7 +1086,7 @@ export class GameStudioGateway extends TypertRemoteService {
1210
1086
  catch (error) {
1211
1087
  throw new Error(`无法打开目录:${error instanceof Error ? error.message : String(error)}`);
1212
1088
  }
1213
- return { ok: true, dir };
1089
+ return { ok: true, dir, fallback: target === "export" && dir === isogen.isoProjectDir(id) ? true : undefined };
1214
1090
  }
1215
1091
  // ── 地图编辑器(模块六,单项目 = 单张地图)──────────────────────────────
1216
1092
  async listMapProjects() {
@@ -1710,7 +1586,7 @@ export class GameStudioGateway extends TypertRemoteService {
1710
1586
  // 生图模型是全局设置(设置 → 游戏素材大师 → 生图后端),任务里不保留可覆盖的副本。
1711
1587
  job.settings.model = imageModelOf(current);
1712
1588
  // 自定义后端的尺寸也是全局参数;火山方舟下才保留任务级覆盖。
1713
- job.settings.size = isCustomProvider(current) ? current.customSize : asString(raw.size, job.settings.size);
1589
+ job.settings.size = imageUsesConfiguredSize(current) ? imageSizeOf(current) : asString(raw.size, job.settings.size);
1714
1590
  job.settings.count = clampInt(raw.count, job.settings.count, 1, 8);
1715
1591
  job.settings.watermark = raw.watermark === true;
1716
1592
  }
@@ -2308,7 +2184,7 @@ export class GameStudioGateway extends TypertRemoteService {
2308
2184
  const input = asRecord(payload);
2309
2185
  return { ok: true, ...(await riggen.removeRigTextureVersion(asString(input.jobId), asString(input.name), Number(input.version))) };
2310
2186
  }
2311
- /** AI 逐部件重绘(花钱)。生图要几十秒,所以走后台任务 + `game_material_wait`。 */
2187
+ /** AI 逐部件重绘(花钱)。生图要几十秒,所以走后台任务 + `game_material({action:'wait'})`。 */
2312
2188
  async runRigRedraw(payload) {
2313
2189
  const input = asRecord(payload);
2314
2190
  return riggen.startRigRedraw(asString(input.jobId), asString(input.name), asString(input.prompt), {
@@ -2779,8 +2655,6 @@ const SERVABLE_SEQUENCE_DIRS = new Set(["refs", "video-refs", "videos", "frames"
2779
2655
  // `export/` 是后加的第二条导出路径(DragonBones 5.5 的 `_ske.json`)。
2780
2656
  // 白名单只比对**第一段**路径,所以 `export/dragonbones/xxx.json` 加一条 `export` 就够。
2781
2657
  const SERVABLE_RIG_DIRS = new Set(["source", "sheet", "parts", "layout", "rig", "atlas", "export"]);
2782
- /** 地图地块:模板、原始生成、规整产物、装饰、地图、导出包。 */
2783
- const SERVABLE_TILE_DIRS = new Set(["template", "raw", "cell", "decor", "map", "export"]);
2784
2658
  /**
2785
2659
  * 地图编辑器(模块六):素材原图、验收预览图、导出包、AI 素材暂存区。
2786
2660
  *
@@ -2814,10 +2688,10 @@ function resolveAssetTarget(scope, id, relative) {
2814
2688
  return undefined;
2815
2689
  return { file: riggen.rigAssetPath(id, relative), dirs: SERVABLE_RIG_DIRS };
2816
2690
  }
2817
- if (scope === "tile-assets") {
2818
- if (!tilegen.isValidTileProjectId(id))
2691
+ if (scope === "iso-assets") {
2692
+ if (!isogen.isValidIsoProjectId(id))
2819
2693
  return undefined;
2820
- return { file: tilegen.tileAssetPath(id, relative), dirs: SERVABLE_TILE_DIRS };
2694
+ return { file: isogen.isoAssetPath(id, relative), dirs: isogen.SERVABLE_ISO_DIRS };
2821
2695
  }
2822
2696
  if (scope === "map-assets") {
2823
2697
  if (!mapgen.isValidMapProjectId(id))
@@ -2848,7 +2722,7 @@ function sendText(res, status, text) {
2848
2722
  * /dsh-game-material-master/image-assets/<任务 id>/<相对路径> 图片生成
2849
2723
  * /dsh-game-material-master/sequence-assets/<任务 id>/<相对路径> 序列帧生成
2850
2724
  * /dsh-game-material-master/rig-assets/<任务 id>/<相对路径> 骨骼动画生成
2851
- * /dsh-game-material-master/tile-assets/<项目 id>/<相对路径> 45°地图地块生成
2725
+ * /dsh-game-material-master/iso-assets/<项目 id>/<相对路径> 45°地图编辑器
2852
2726
  * /dsh-game-material-master/map-assets/<项目 id>/<相对路径> 地图编辑器
2853
2727
  * /dsh-game-material-master/music-assets/<任务 id>/<相对路径> 音乐生成编辑
2854
2728
  *
@@ -2883,8 +2757,8 @@ async function handleAsset(req, res) {
2883
2757
  // ⚠️ 这是**运行时**白名单,必须与 `AssetScope` 类型和 `resolveAssetTarget` 的分支
2884
2758
  // 三处同步。只改类型不改这里,TypeScript 一句话都不会说 —— `scope` 是断言出来的,
2885
2759
  // 而漏掉的那个 scope 会在这里直接掉进 404(界面表现只是「图裂了」)。
2886
- // 实测:`tile-assets` 就这么漏过一轮,模板图全 404。
2887
- const SCOPES = ["assets", "image-assets", "sequence-assets", "rig-assets", "tile-assets", "map-assets", "music-assets", "sfx-assets"];
2760
+ // 实测:`iso-assets` / `tile-assets` 这类 scope 都漏过一轮,素材全 404。
2761
+ const SCOPES = ["assets", "image-assets", "sequence-assets", "rig-assets", "iso-assets", "map-assets", "music-assets", "sfx-assets"];
2888
2762
  if (!SCOPES.includes(scope)) {
2889
2763
  sendText(res, 404, "Not Found");
2890
2764
  return;