dsh-game-material-master 0.7.0 → 0.9.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/store.js CHANGED
@@ -86,6 +86,76 @@ function emptyFrames() {
86
86
  out[key] = { status: "empty", frames: [], keyed: [], approved: false };
87
87
  return out;
88
88
  }
89
+ /**
90
+ * 换了源图:把「由源图派生出来的东西」全部作废。
91
+ *
92
+ * 源图是阶段①的输入。换了源图之后,之前那张图跑出来的八个方向图、转圈视频、
93
+ * 候选帧(`turn/raw.bin` 动辄上百 MB)以及阶段②③④的产物全都属于另一个角色。
94
+ * 留着它们不只是占地方——`turnFirstFrame()` 会**优先**拿 `images/front.png` 当首帧,
95
+ * 于是新源图根本进不了模型,表现就是「换了源图,生成结果一点没变」。
96
+ *
97
+ * 所以这里一律清回初始状态,并删掉对应的磁盘文件(删不掉的忽略,不影响主流程)。
98
+ * 返回被清掉的产物个数,供调用方记日志。
99
+ */
100
+ export async function resetDerivedFromSource(id) {
101
+ const orphans = await patchProject(id, (project) => {
102
+ const files = [];
103
+ const push = (file) => {
104
+ if (file !== undefined && file !== "")
105
+ files.push(file);
106
+ };
107
+ for (const key of DIRECTION_KEYS)
108
+ push(project.images[key]?.file);
109
+ push(project.turn?.video?.file);
110
+ push(project.turn?.frames?.raw);
111
+ push(project.turn?.frames?.strip);
112
+ for (const file of project.turn?.frames?.frames ?? [])
113
+ push(file);
114
+ for (const key of DIRECTION_KEYS) {
115
+ push(project.videos[key]?.file);
116
+ const frames = project.frames[key];
117
+ if (frames === undefined)
118
+ continue;
119
+ push(frames.raw);
120
+ push(frames.strip);
121
+ for (const file of frames.frames)
122
+ push(file);
123
+ for (const file of frames.keyed)
124
+ push(file);
125
+ const candidates = frames.candidates;
126
+ if (candidates === undefined)
127
+ continue;
128
+ push(candidates.raw);
129
+ push(candidates.strip);
130
+ for (const file of candidates.frames)
131
+ push(file);
132
+ }
133
+ push(project.sheet?.file);
134
+ push(project.sheet?.thumb);
135
+ project.images = emptyImages();
136
+ project.videos = emptyVideos();
137
+ project.frames = emptyFrames();
138
+ project.sheet = { status: "empty", approved: false };
139
+ project.turn.video = { status: "empty", approved: false };
140
+ // 抽帧位置回到「候选帧数 ÷ 8」的默认值:旧的 picks 指的是旧视频的帧号,
141
+ // 新视频未必有那么多帧,留着没有意义。转圈方向(cw / ccw)是用户的选择,保留。
142
+ project.turn.frames = {
143
+ status: "empty",
144
+ frames: [],
145
+ times: [],
146
+ picks: freshPicks(project.settings.turnFrameCount),
147
+ approved: false
148
+ };
149
+ if (files.length > 0) {
150
+ log(project, "warn", `换了源图:已作废由旧源图派生的 ${files.length} 个产物(方向图 / 转圈视频 / 候选帧 / 序列帧 / 整图),请重新生成。`);
151
+ }
152
+ return files;
153
+ });
154
+ for (const relative of orphans) {
155
+ await rm(assetPath(id, relative), { force: true }).catch(() => undefined);
156
+ }
157
+ return orphans.length;
158
+ }
89
159
  export async function ensureLayout(id) {
90
160
  const base = projectDir(id);
91
161
  for (const sub of ["source", "images", "videos", "frames", "keyed", "preview", "out", "turn"]) {
@@ -197,6 +267,15 @@ export function summarize(project) {
197
267
  };
198
268
  }
199
269
  /** 补齐历史版本缺字段,保证读进来的对象形状永远完整。 */
270
+ /**
271
+ * 视频节点的后端标记:只认两个已知值。
272
+ *
273
+ * 老项目 / 手写坏值一律折成 undefined(= 按 minimax 处理),而不是原样带进内存——
274
+ * 一个不认识的字符串会让查询分派悄悄走到「按配置猜」那条路上。
275
+ */
276
+ function normalizeVideoBackend(raw) {
277
+ return raw === "comfy" || raw === "minimax" ? raw : undefined;
278
+ }
200
279
  function normalizeProject(raw) {
201
280
  const now = Date.now();
202
281
  const settings = { ...(raw?.settings ?? {}) };
@@ -238,6 +317,7 @@ function normalizeProject(raw) {
238
317
  ...videos[key],
239
318
  ...node,
240
319
  approved: node.approved === true,
320
+ backend: normalizeVideoBackend(node.backend),
241
321
  origin: node.origin === "local" ? "local" : undefined,
242
322
  originalName: typeof node.originalName === "string" ? node.originalName : undefined
243
323
  };
@@ -360,6 +440,7 @@ function normalizeTurn(raw, frameCount) {
360
440
  video: {
361
441
  status: (raw?.video?.status ?? "empty"),
362
442
  taskId: typeof raw?.video?.taskId === "string" ? raw.video.taskId : undefined,
443
+ backend: normalizeVideoBackend(raw?.video?.backend),
363
444
  remoteStatus: typeof raw?.video?.remoteStatus === "string" ? raw.video.remoteStatus : undefined,
364
445
  file: typeof raw?.video?.file === "string" ? raw.video.file : undefined,
365
446
  approved: raw?.video?.approved === true,
package/lib/tilegen.js CHANGED
@@ -38,6 +38,7 @@ import { messageOf, readJson, writeJsonAtomic, appendJobLog, sweepTempFiles } fr
38
38
  import { DEFAULT_SETTINGS, assertSettings, decorAnchorY, diamondHeight, measureGroundDiamond, measurementLooksSane, regularizeBuilding, regularizeDecorSprite, regularizeToCell, renderBuildingTemplate, renderTemplate, upscale } from "./tilegeom.js";
39
39
  import { assembleMap, cropBitmap, emptyMapState, measureAssemblyBounds, pickVariantIndex, shapeOfEntry } from "./tilemap.js";
40
40
  import { decodeFile, encodeBitmap, pngSize, sniffImageExt } from "./bitmap.js";
41
+ import { assetBasePath } from "./links.js";
41
42
  export const TILE_STAGES = ["generate", "review", "map", "export"];
42
43
  export const TILE_INVALIDATION_ORDER = ["template", "generate", "review", "map", "export"];
43
44
  /** 由「列 × 行」矩形造形状。 */
@@ -1434,7 +1435,7 @@ export function tileView(project) {
1434
1435
  return {
1435
1436
  ...project,
1436
1437
  job: jobs.get(project.id),
1437
- assetBase: `/dsh-game-material-master/tile-assets/${project.id}/`,
1438
+ assetBase: assetBasePath(`/dsh-game-material-master/tile-assets/${project.id}/`),
1438
1439
  progress: tileProgress(project),
1439
1440
  // 参考图预览(原「① 模板」阶段,现在是 ② 里的只读面板)。
1440
1441
  //
@@ -1641,7 +1642,7 @@ export function tileAnchorY(project) {
1641
1642
  * 这里给模型用绝对 URL。两者都只带「判断所需的最小字段」,不是整个 project.json。
1642
1643
  */
1643
1644
  export function tileSnapshot(project, origin) {
1644
- const assetBase = `${origin}/dsh-game-material-master/tile-assets/${project.id}/`;
1645
+ const assetBase = `${origin}${assetBasePath(`/dsh-game-material-master/tile-assets/${project.id}/`)}`;
1645
1646
  const url = (relative) => typeof relative === "string" && relative !== "" ? `${assetBase}${relative}` : undefined;
1646
1647
  const items = project.items.map((item) => ({
1647
1648
  key: item.key,