dsh-game-material-master 0.10.2 → 0.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/isorender.js CHANGED
@@ -15,6 +15,7 @@ import { cellIndex } from "./isodoc.js";
15
15
  import { cellCenter, cellTopLeft, chunkKey, chunkOf, expandBounds, groundBounds, isoDepthZ, layoutOf, objectTopLeft, parseChunkKey, wrapCell } from "./isogeom.js";
16
16
  import { corner16Mask, nearestMask } from "./mapauto.js";
17
17
  import { applyLoop, flatTiles } from "./maptiles.js";
18
+ import { checkerBackground, drawDigits, fillCircle, fillDiamond, fillRect, strokeCircle, strokeDiamond } from "./imagedraw.js";
18
19
  /** 单张导出图的最大像素数(超过就明确拒绝,而不是把进程 OOM 掉)。 */
19
20
  export const MAX_ISO_RENDER_PIXELS = 64_000_000;
20
21
  /** 动画帧率:与模块六一致,1 帧/秒是默认档。 */
@@ -466,6 +467,220 @@ export function rasterizeIso(context, doc, lookup, options = {}) {
466
467
  }
467
468
  return { bitmap, bounds: plan.bounds, warnings, drawn };
468
469
  }
470
+ const ISO_MARKER_COLORS = {
471
+ spawn: [63, 185, 80],
472
+ exit: [88, 166, 255],
473
+ chest: [240, 192, 64],
474
+ boss: [255, 59, 48],
475
+ event: [163, 113, 247],
476
+ resource: [57, 197, 207],
477
+ npc: [255, 159, 26],
478
+ custom: [240, 192, 64]
479
+ };
480
+ function parseIsoColor(value, fallback = [240, 192, 64]) {
481
+ if (typeof value !== "string")
482
+ return fallback;
483
+ const match = /^#?([0-9a-f]{6})$/i.exec(value.trim());
484
+ if (match === null)
485
+ return fallback;
486
+ const n = Number.parseInt(match[1], 16);
487
+ return [(n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff];
488
+ }
489
+ function isoMarkerColor(marker) {
490
+ const kind = typeof marker.kind === "string" ? marker.kind : "custom";
491
+ return parseIsoColor(marker.color, ISO_MARKER_COLORS[kind] ?? ISO_MARKER_COLORS.custom);
492
+ }
493
+ function isoPassColor(kind) {
494
+ if (kind === 0)
495
+ return [255, 80, 80];
496
+ if (kind === 2)
497
+ return [90, 160, 255];
498
+ return [90, 210, 120];
499
+ }
500
+ /** 一块地格范围的像素包围盒(只按整格;物件另算)。 */
501
+ function isoRangeGroundBounds(layout, range) {
502
+ const points = [
503
+ [range.r0, range.c0],
504
+ [range.r0, range.c1 - 1],
505
+ [range.r1 - 1, range.c0],
506
+ [range.r1 - 1, range.c1 - 1]
507
+ ];
508
+ let minX = Infinity;
509
+ let minY = Infinity;
510
+ let maxX = -Infinity;
511
+ let maxY = -Infinity;
512
+ for (const [r, c] of points) {
513
+ const topLeft = cellTopLeft(layout, r, c, layout.cell.width, layout.cell.height);
514
+ minX = Math.min(minX, topLeft.x);
515
+ minY = Math.min(minY, topLeft.y);
516
+ maxX = Math.max(maxX, topLeft.x + layout.cell.width);
517
+ maxY = Math.max(maxY, topLeft.y + layout.cell.height);
518
+ }
519
+ const originX = Math.floor(minX);
520
+ const originY = Math.floor(minY);
521
+ return { originX, originY, width: Math.max(1, Math.ceil(maxX) - originX), height: Math.max(1, Math.ceil(maxY) - originY) };
522
+ }
523
+ function intersectsRange(object, footprint, range) {
524
+ for (let dr = 0; dr < footprint.rows; dr++) {
525
+ for (let dc = 0; dc < footprint.cols; dc++) {
526
+ const r = object.r + dr;
527
+ const c = object.c + dc;
528
+ if (r >= range.r0 && r < range.r1 && c >= range.c0 && c < range.c1)
529
+ return true;
530
+ }
531
+ }
532
+ return false;
533
+ }
534
+ /**
535
+ * 渲染一块 45° 地图区域。与导出共用 `buildIsoPlan` 和同一个 `z` 排序;
536
+ * crop 会把区域内物件向上的溢出也算进去,避免树冠 / 屋顶被裁掉。
537
+ */
538
+ export function renderIsoView(context, doc, lookup, options = {}) {
539
+ const layout = context.layout;
540
+ const requested = options.range ?? { r0: 0, c0: 0, r1: doc.rows, c1: doc.cols };
541
+ const range = {
542
+ r0: Math.round(requested.r0),
543
+ c0: Math.round(requested.c0),
544
+ r1: Math.round(requested.r1),
545
+ c1: Math.round(requested.c1)
546
+ };
547
+ if (!(range.r1 > range.r0) || !(range.c1 > range.c0))
548
+ throw new Error("渲染区域必须是正矩形(r1 > r0、c1 > c0)。");
549
+ const scale = Math.max(1, Math.min(4, Math.round(options.scale ?? 1)));
550
+ const pad = Math.max(0, Math.min(8, Math.round(options.padding ?? 2)));
551
+ const drawRange = { r0: range.r0 - pad, c0: range.c0 - pad, r1: range.r1 + pad, c1: range.c1 + pad };
552
+ const keepLayers = options.layers === undefined ? undefined : new Set(options.layers);
553
+ const plan = buildIsoPlan(context, doc, { range: drawRange, layers: options.layers, includeLegend: true });
554
+ let crop;
555
+ if (options.range === undefined) {
556
+ crop = plan.bounds;
557
+ }
558
+ else {
559
+ crop = isoRangeGroundBounds(layout, range);
560
+ for (const object of doc.objects) {
561
+ if (keepLayers !== undefined && !keepLayers.has(doc.layers.findIndex((layer) => layer.id === object.layerId)))
562
+ continue;
563
+ const tileset = context.tilesets.find((entry) => entry.id === object.tilesetId);
564
+ if (tileset === undefined || tileset.kind !== "object" || tileset.footprint === undefined)
565
+ continue;
566
+ if (!intersectsRange(object, tileset.footprint, range))
567
+ continue;
568
+ const rect = objectFrameRect(tileset);
569
+ if (rect === undefined)
570
+ continue;
571
+ const topLeft = objectTopLeft(layout, object.r, object.c, tileset.footprint, rect.width, rect.height, tileset.anchor);
572
+ crop = expandBounds(crop, { x: topLeft.x, y: topLeft.y, width: rect.width, height: rect.height });
573
+ }
574
+ // 标记圆圈可能压住边缘;留一点余量,免得编号被裁掉。
575
+ crop = {
576
+ originX: crop.originX - 2,
577
+ originY: crop.originY - 2,
578
+ width: crop.width + 4,
579
+ height: crop.height + 4
580
+ };
581
+ }
582
+ const width = Math.max(1, Math.ceil(crop.width * scale));
583
+ const height = Math.max(1, Math.ceil(crop.height * scale));
584
+ const maxPixels = Math.max(1, Math.round(options.maxPixels ?? 16_000_000));
585
+ if (width * height > maxPixels) {
586
+ throw new Error(`检查图会到 ${width}×${height}(超过 ${maxPixels} 像素上限):请缩小 region 或 scale。`);
587
+ }
588
+ const bitmap = { width, height, rgba: Buffer.alloc(width * height * 4) };
589
+ const background = options.background ?? "transparent";
590
+ if (background === "checker")
591
+ checkerBackground(bitmap, Math.max(4, 8 * scale));
592
+ else if (background === "white")
593
+ fillRect(bitmap, 0, 0, width, height, [255, 255, 255], 1);
594
+ else if (background === "dark")
595
+ fillRect(bitmap, 0, 0, width, height, [42, 42, 42], 1);
596
+ const warnings = [...plan.warnings];
597
+ const legend = new Map(plan.legend.map((entry) => [entry.index, entry]));
598
+ const missing = new Set();
599
+ let drawn = 0;
600
+ const frame = Math.max(0, Math.round(options.frame ?? 0));
601
+ const ops = plan.chunks.flatMap((chunk) => chunk.ops).sort((a, b) => a.z - b.z || a.r - b.r || a.c - b.c);
602
+ for (const op of ops) {
603
+ const entry = legend.get(op.t);
604
+ if (entry === undefined)
605
+ continue;
606
+ let actual = entry;
607
+ if (op.cycle !== undefined && op.cycle.length > 0) {
608
+ actual = legend.get(op.cycle[frame % op.cycle.length]) ?? entry;
609
+ }
610
+ const source = lookup.get(actual.tilesetId);
611
+ if (source === undefined) {
612
+ missing.add(actual.tilesetId);
613
+ continue;
614
+ }
615
+ blitScaled(bitmap, source, actual.rect, Math.round((op.x - crop.originX) * scale), Math.round((op.y - crop.originY) * scale), scale, op.a);
616
+ drawn++;
617
+ }
618
+ for (const id of missing) {
619
+ const name = context.tilesets.find((tileset) => tileset.id === id)?.name ?? id;
620
+ warnings.push(`素材「${name}」的图片没有解码出来,它上面的内容没有画进检查图。`);
621
+ }
622
+ const overlay = options.overlay ?? {};
623
+ if (overlay.pass === true && Array.isArray(options.passCells)) {
624
+ for (const cell of options.passCells) {
625
+ if (cell.r < range.r0 || cell.r >= range.r1 || cell.c < range.c0 || cell.c >= range.c1)
626
+ continue;
627
+ const center = cellCenter(layout, cell.r, cell.c);
628
+ fillDiamond(bitmap, (center.x - crop.originX) * scale, (center.y - crop.originY) * scale, (layout.cell.width / 2) * scale, (layout.cell.width / 4) * scale, isoPassColor(cell.kind), 0.16);
629
+ }
630
+ }
631
+ if (overlay.grid === true) {
632
+ const gridColor = [255, 255, 255];
633
+ for (let r = range.r0; r < range.r1; r++) {
634
+ for (let c = range.c0; c < range.c1; c++) {
635
+ const center = cellCenter(layout, r, c);
636
+ strokeDiamond(bitmap, (center.x - crop.originX) * scale, (center.y - crop.originY) * scale, (layout.cell.width / 2) * scale, (layout.cell.width / 4) * scale, gridColor, 0.22, 1);
637
+ }
638
+ }
639
+ }
640
+ if (overlay.axes === true) {
641
+ const labelColor = [255, 255, 255];
642
+ const every = Math.max(1, Math.ceil(Math.max(range.c1 - range.c0, range.r1 - range.r0) / 12));
643
+ for (let c = range.c0; c < range.c1; c += every) {
644
+ const center = cellCenter(layout, range.r0, c);
645
+ drawDigits(bitmap, String(((c % doc.cols) + doc.cols) % doc.cols), (center.x - crop.originX) * scale, 4 * scale, 5 * scale, labelColor, 0.8);
646
+ }
647
+ for (let r = range.r0; r < range.r1; r += every) {
648
+ const center = cellCenter(layout, r, range.c0);
649
+ drawDigits(bitmap, String(((r % doc.rows) + doc.rows) % doc.rows), 4 * scale, (center.y - crop.originY) * scale, 5 * scale, labelColor, 0.8);
650
+ }
651
+ }
652
+ if (Array.isArray(overlay.outlines)) {
653
+ for (const outline of overlay.outlines) {
654
+ if (outline.r < range.r0 || outline.r >= range.r1 || outline.c < range.c0 || outline.c >= range.c1)
655
+ continue;
656
+ const center = cellCenter(layout, outline.r, outline.c);
657
+ const color = parseIsoColor(outline.color, [255, 59, 48]);
658
+ strokeDiamond(bitmap, (center.x - crop.originX) * scale, (center.y - crop.originY) * scale, (layout.cell.width / 2) * scale, (layout.cell.width / 4) * scale, color, 0.95, Math.max(1, scale));
659
+ if (typeof outline.label === "string" && outline.label !== "") {
660
+ drawDigits(bitmap, outline.label, (center.x - crop.originX) * scale, (center.y - crop.originY) * scale, 5 * scale, color, 0.95);
661
+ }
662
+ }
663
+ }
664
+ let markersDrawn = 0;
665
+ if (overlay.markers === true) {
666
+ const byId = new Map(doc.markers.map((marker) => [marker.id, marker]));
667
+ for (const marker of plan.markers) {
668
+ if (marker.x < crop.originX || marker.x > crop.originX + crop.width || marker.y < crop.originY || marker.y > crop.originY + crop.height)
669
+ continue;
670
+ const source = byId.get(marker.id);
671
+ const color = isoMarkerColor((source ?? {}));
672
+ const cx = (marker.x - crop.originX) * scale;
673
+ const cy = (marker.y - crop.originY) * scale;
674
+ const radius = Math.max(4, marker.radius * scale);
675
+ fillCircle(bitmap, cx, cy, radius, [20, 20, 20], 0.88);
676
+ strokeCircle(bitmap, cx, cy, radius, [255, 214, 64], 0.95, Math.max(1, scale));
677
+ if (overlay.markerLabels !== false)
678
+ drawDigits(bitmap, String(marker.n), cx, cy, Math.max(6, marker.font * scale), color, 1);
679
+ markersDrawn++;
680
+ }
681
+ }
682
+ return { bitmap, crop, range, scale, drawn, markersDrawn, warnings };
683
+ }
469
684
  export function isoBitmapToPng(bitmap) {
470
685
  return encodePng(bitmap.rgba, bitmap.width, bitmap.height);
471
686
  }
@@ -0,0 +1,251 @@
1
+ /**
2
+ * 抠像底色(chroma key 背景色)。
3
+ *
4
+ * 这个模块解决两件事:
5
+ *
6
+ * 1. **抠像不再只认绿色**。角色自己穿绿衣服时,绿幕会把衣服一起吃掉;用户可以
7
+ * 改用品红 / 蓝 / 白 / 黑等背景。这里负责把界面 / 配置里的颜色规整成
8
+ * `#RRGGBB`,并给出颜色名与颜色通道方向(去溢色要用)。
9
+ * 2. **提示词里的「绿幕」跟着换**。默认提示词里写死了「纯绿幕 / #00FF00」,
10
+ * 配置成蓝幕后如果还把这些字发给模型,模型会继续画绿幕 —— 于是抠像参数
11
+ * 与画面背景对不上。`applyKeyColorToPrompt` / `backgroundClause` 就是这层的
12
+ * 唯一真源:服务端默认提示词与浏览器半区的 AI 素材提示词都走它。
13
+ *
14
+ * 颜色计算只做纯函数,不读配置、不碰 IO —— 这样 chroma / directions / client
15
+ * 都能安全引用,也方便自检逐条断言。
16
+ */
17
+ /** 默认抠像底色:标准 chroma key 绿。 */
18
+ export const DEFAULT_KEY_COLOR = "#00FF00";
19
+ /**
20
+ * 内置可选底色。
21
+ *
22
+ * 只放**饱和、均匀**的纯色:抠像最怕背景本身有纹理 / 渐变,模型也最容易画准
23
+ * 这种颜色。白 / 黑放在最后:它们适合「绿、蓝、品红都不能用」的极端衣服配色,
24
+ * 但边缘溢色不如彩色幕好处理。
25
+ */
26
+ export const KEY_COLOR_PRESETS = [
27
+ { hex: "#00FF00", zh: "绿幕", en: "green screen", zhColor: "绿", enColor: "green" },
28
+ { hex: "#0000FF", zh: "蓝幕", en: "blue screen", zhColor: "蓝", enColor: "blue" },
29
+ { hex: "#FF00FF", zh: "品红幕", en: "magenta screen", zhColor: "品红", enColor: "magenta" },
30
+ { hex: "#00FFFF", zh: "青幕", en: "cyan screen", zhColor: "青", enColor: "cyan" },
31
+ { hex: "#FFFF00", zh: "黄幕", en: "yellow screen", zhColor: "黄", enColor: "yellow" },
32
+ { hex: "#FF0000", zh: "红幕", en: "red screen", zhColor: "红", enColor: "red" },
33
+ { hex: "#FFFFFF", zh: "白幕", en: "white screen", zhColor: "白", enColor: "white" },
34
+ { hex: "#000000", zh: "黑幕", en: "black screen", zhColor: "黑", enColor: "black" }
35
+ ];
36
+ const NAMED_COLORS = {
37
+ green: "#00FF00",
38
+ blue: "#0000FF",
39
+ magenta: "#FF00FF",
40
+ cyan: "#00FFFF",
41
+ yellow: "#FFFF00",
42
+ red: "#FF0000",
43
+ white: "#FFFFFF",
44
+ black: "#000000",
45
+ gray: "#808080",
46
+ grey: "#808080",
47
+ 绿: "#00FF00",
48
+ 绿幕: "#00FF00",
49
+ 蓝: "#0000FF",
50
+ 蓝幕: "#0000FF",
51
+ 品红: "#FF00FF",
52
+ 品红幕: "#FF00FF",
53
+ 青: "#00FFFF",
54
+ 青幕: "#00FFFF",
55
+ 黄: "#FFFF00",
56
+ 黄幕: "#FFFF00",
57
+ 红: "#FF0000",
58
+ 红幕: "#FF0000",
59
+ 白: "#FFFFFF",
60
+ 白幕: "#FFFFFF",
61
+ 黑: "#000000",
62
+ 黑幕: "#000000"
63
+ };
64
+ /** 任意输入 → 规范的 `#RRGGBB`;认不出来回退到 `fallback`。 */
65
+ export function normalizeKeyColor(value, fallback = DEFAULT_KEY_COLOR) {
66
+ const text = typeof value === "string" ? value.trim().toLowerCase() : "";
67
+ if (text === "")
68
+ return fallback;
69
+ const named = NAMED_COLORS[text];
70
+ if (named !== undefined)
71
+ return named;
72
+ const short = /^#([0-9a-f]{3})$/.exec(text);
73
+ if (short !== null) {
74
+ const [r, g, b] = short[1].split("");
75
+ return `#${r}${r}${g}${g}${b}${b}`.toUpperCase();
76
+ }
77
+ const full = /^#?([0-9a-f]{6})$/.exec(text);
78
+ if (full !== null)
79
+ return `#${full[1]}`.toUpperCase();
80
+ return fallback;
81
+ }
82
+ /** `#RRGGBB` → 0~255 三个通道。 */
83
+ export function keyColorRgb(hex) {
84
+ const color = normalizeKeyColor(hex);
85
+ return {
86
+ r: Number.parseInt(color.slice(1, 3), 16),
87
+ g: Number.parseInt(color.slice(3, 5), 16),
88
+ b: Number.parseInt(color.slice(5, 7), 16)
89
+ };
90
+ }
91
+ /** 是不是「绿幕」那一档。绿色走原有的绿色优势判据(对实拍 / 视频帧更稳)。 */
92
+ export function isGreenKeyColor(hex) {
93
+ const { r, g, b } = keyColorRgb(hex);
94
+ return g > r + 64 && g > b + 64;
95
+ }
96
+ /** 当前底色对应的预设;自定义颜色返回 undefined。 */
97
+ export function keyColorPreset(hex) {
98
+ const color = normalizeKeyColor(hex);
99
+ return KEY_COLOR_PRESETS.find((preset) => preset.hex === color);
100
+ }
101
+ /** 颜色字的语言版本。自定义颜色退回 `#RRGGBB`。 */
102
+ export function keyColorWord(hex, lang = "zh") {
103
+ const preset = keyColorPreset(hex);
104
+ if (preset !== undefined)
105
+ return lang === "en" ? preset.enColor : preset.zhColor;
106
+ return normalizeKeyColor(hex);
107
+ }
108
+ /** 「绿幕 / 蓝幕 / 品红幕…」;自定义颜色说「纯色背景」。 */
109
+ export function keyScreenName(hex, lang = "zh") {
110
+ const preset = keyColorPreset(hex);
111
+ if (preset !== undefined)
112
+ return lang === "en" ? preset.en : preset.zh;
113
+ return lang === "en" ? "solid background" : "纯色背景";
114
+ }
115
+ /** 是否标准 `#00FF00`:默认提示词与旧项目都按这个判断。 */
116
+ export function isDefaultKeyColor(hex) {
117
+ return normalizeKeyColor(hex) === DEFAULT_KEY_COLOR;
118
+ }
119
+ /**
120
+ * 去溢色要压制的通道。
121
+ *
122
+ * 绿幕只压 G;蓝幕只压 B;品红幕同时压 R / B。返回**主色通道的下标**,
123
+ * 其余通道取最大值作为「其它颜色」的基准 —— 这样品红幕的白色边缘(R≈G≈B)
124
+ * 不会被误压,而偏品红的软边会被拉回中性。
125
+ */
126
+ export function keyDominantChannels(hex) {
127
+ const { r, g, b } = keyColorRgb(hex);
128
+ const channels = [r, g, b];
129
+ const out = [];
130
+ for (let i = 0; i < 3; i++) {
131
+ const others = channels.filter((_, index) => index !== i);
132
+ const otherAverage = (others[0] + others[1]) / 2;
133
+ if (channels[i] - otherAverage >= 48)
134
+ out.push(i);
135
+ }
136
+ return out;
137
+ }
138
+ /**
139
+ * 默认提示词里「整幅背景」那句话。
140
+ *
141
+ * 这一段会**真的发给模型**,所以绿色必须保持与旧版逐字一致(有一批老项目、
142
+ * 自检与模型行为都按那几句验证过);其它颜色按同一句式生成。
143
+ */
144
+ export function backgroundClause(hex, lang = "zh", variant = "image") {
145
+ const color = normalizeKeyColor(hex);
146
+ if (color === DEFAULT_KEY_COLOR) {
147
+ return variant === "turn"
148
+ ? lang === "en"
149
+ ? "Solid green screen, the color is standard chroma key green #00FF00, the whole background is a completely uniform single color, pure green throughout, with no shadows, gradients, ground or cast shadow."
150
+ : "纯色绿幕,颜色是标准 chroma key 绿 #00FF00,整幅背景颜色完全均匀一致,全程保持纯绿,不要任何阴影、渐变、地面或投影。"
151
+ : lang === "en"
152
+ ? "Solid green screen, the color is standard chroma key green #00FF00, the whole background is a completely uniform single color, with no shadows, gradients or noise of any kind."
153
+ : "纯色绿幕,颜色是标准 chroma key 绿 #00FF00,整幅背景颜色完全均匀一致,不要任何阴影、渐变或噪点。";
154
+ }
155
+ const screen = keyScreenName(color, lang);
156
+ const word = keyColorWord(color, lang);
157
+ const screenClause = keyColorPreset(color) === undefined ? (lang === "en" ? "Solid background" : "纯色背景") : (lang === "en" ? `Solid ${screen}` : `纯色${screen}`);
158
+ if (variant === "turn") {
159
+ return lang === "en"
160
+ ? `${screenClause} (${color}), the whole background is a completely uniform single color, pure ${word} throughout, with no shadows, gradients, ground or cast shadow.`
161
+ : `${screenClause},颜色是 ${color},整幅背景颜色完全均匀一致,全程保持纯${word},不要任何阴影、渐变、地面或投影。`;
162
+ }
163
+ return lang === "en"
164
+ ? `${screenClause} (${color}), the whole background is a completely uniform single color, with no shadows, gradients or noise of any kind.`
165
+ : `${screenClause},颜色是 ${color},整幅背景颜色完全均匀一致,不要任何阴影、渐变或噪点。`;
166
+ }
167
+ /**
168
+ * 把默认提示词里的背景描述换成目标颜色。
169
+ *
170
+ * 只替换**内置默认句式**(对所有内置颜色 + 目标自定义颜色都认),用户自己改写过的
171
+ * 句子一个字都不动。这样:
172
+ * · 老项目里存着「纯绿幕 #00FF00」的默认提示词,切到蓝幕后仍会自动更新;
173
+ * · 用户手写「我要一个绿色背景」不会被误替换(不匹配默认句式)。
174
+ */
175
+ export function applyKeyColorToPrompt(text, hex, lang = "zh") {
176
+ if (typeof text !== "string" || text === "")
177
+ return text;
178
+ const target = normalizeKeyColor(hex);
179
+ let out = text;
180
+ // 1) 整句背景:内置颜色 + 目标自定义颜色都替换成目标句式。
181
+ const colors = new Set([target, ...KEY_COLOR_PRESETS.map((preset) => preset.hex)]);
182
+ const variants = ["image", "turn"];
183
+ for (const variant of variants) {
184
+ const replacement = backgroundClause(target, lang, variant);
185
+ for (const color of colors) {
186
+ const old = backgroundClause(color, lang, variant);
187
+ if (old !== replacement)
188
+ out = out.split(old).join(replacement);
189
+ }
190
+ }
191
+ // 2) 句中的短称呼:`绿幕背景` / `干净的绿幕` / `同一片绿` / `抠绿幕` …
192
+ // 也覆盖「目标颜色是绿」时从蓝幕 / 品红幕默认值改回来的情况。
193
+ const screenNames = new Set(KEY_COLOR_PRESETS.map((preset) => (lang === "en" ? preset.en : preset.zh)));
194
+ const targetScreen = keyScreenName(target, lang);
195
+ const targetWord = keyColorWord(target, lang);
196
+ const targetShort = lang === "en"
197
+ ? keyColorPreset(target) === undefined ? targetWord : targetScreen.replace(/\s+screen$/u, "")
198
+ : targetScreen.endsWith("幕") ? targetScreen.slice(0, -1) : targetWord;
199
+ const targetBackground = lang === "en"
200
+ ? keyColorPreset(target) === undefined ? "solid background" : `${targetScreen} background`
201
+ : targetScreen.endsWith("幕") ? `${targetScreen}背景` : "纯色背景";
202
+ for (const screen of screenNames) {
203
+ const short = lang === "en" ? screen.replace(/\s+screen$/u, "") : screen.replace(/幕$/u, "");
204
+ if (screen === targetScreen && short === targetShort)
205
+ continue;
206
+ out = out.split(`${screen}背景`).join(targetBackground);
207
+ out = out.split(`干净的${screen}`).join(`干净的${targetScreen}`);
208
+ out = out.split(`没检测到${screen}`).join(`没检测到${targetScreen}`);
209
+ out = out.split(`抠${screen}`).join(`抠${targetScreen}`);
210
+ out = out.split(`抠${short}`).join(`抠${targetShort}`);
211
+ out = out.split(`抠掉${screen}背景`).join(`抠掉${targetBackground}`);
212
+ out = out.split(`同一片${short}`).join(`同一片${targetShort}`);
213
+ out = out.split(`纯${short}`).join(`纯${targetShort}`);
214
+ out = out.split(`每一片${short}`).join(`每一片${targetShort}`);
215
+ out = out.split(`${short}色描边`).join(`${targetWord}色描边`);
216
+ out = out.split(`${short}色外发光`).join(`${targetWord}色外发光`);
217
+ if (lang === "en") {
218
+ out = out.split(`${screen} background`).join(targetBackground);
219
+ out = out.split(`clean ${screen}`).join(`clean ${targetScreen}`);
220
+ out = out.split(`the same ${short} background`).join(`the same ${targetShort} background`);
221
+ out = out.split(`${short} background`).join(targetBackground);
222
+ out = out.split(`pure ${short}`).join(`pure ${targetWord}`);
223
+ out = out.split(`${short} outline`).join(`${targetWord} outline`);
224
+ out = out.split(`${short} glow`).join(`${targetWord} glow`);
225
+ }
226
+ }
227
+ // 3) 自定义旧颜色(不是任何内置预设)的整句背景:把 `颜色是 #XXXXXX` 所在句替换成目标句。
228
+ // 只匹配「颜色是 #RRGGBB」到句号,避免误伤其它提到色值的文字。
229
+ if (lang === "zh") {
230
+ out = out.replace(/纯色[^,。\n]*,颜色是 #[0-9A-Fa-f]{6},整幅背景颜色完全均匀一致,不要[^。\n]*。/gu, backgroundClause(target, lang, "image"));
231
+ out = out.replace(/纯色[^,。\n]*,颜色是 #[0-9A-Fa-f]{6},[^。\n]*全程保持[^。\n]*。/gu, backgroundClause(target, lang, "turn"));
232
+ }
233
+ if (lang === "en") {
234
+ out = out.replace(/Solid [^,\n]*#[0-9A-Fa-f]{6}[^,\n]*, the whole background is a completely uniform single color, pure [^.]*\./gu, backgroundClause(target, lang, "turn"));
235
+ out = out.replace(/Solid [^,\n]*#[0-9A-Fa-f]{6}[^,\n]*, the whole background is a completely uniform single color, with no [^.]*\./gu, backgroundClause(target, lang, "image"));
236
+ }
237
+ return out;
238
+ }
239
+ /** 一句短背景描述,给「背景保持原样」这类句中位置用。 */
240
+ export function shortBackground(hex, lang = "zh") {
241
+ const color = normalizeKeyColor(hex);
242
+ if (color === DEFAULT_KEY_COLOR)
243
+ return lang === "en" ? "green screen" : "绿幕";
244
+ return lang === "en" ? keyScreenName(color, "en") : `${keyScreenName(color, "zh")}`;
245
+ }
246
+ /** 一行「当前底色」说明,给界面 / 提示词用。 */
247
+ export function describeKeyColor(hex, lang = "zh") {
248
+ const color = normalizeKeyColor(hex);
249
+ const screen = keyScreenName(color, lang);
250
+ return lang === "en" ? `${screen} (${color})` : `${screen}(${color})`;
251
+ }
package/lib/links.js CHANGED
@@ -56,7 +56,7 @@ export const OPEN_SCALE_MAX = 8;
56
56
  * 深链接里整图占格的取值范围(与 `maptiles.STAMP_MIN_CELLS / STAMP_MAX_CELLS` 同一套)。
57
57
  * 真正的业务上限是**地图大小**,那条由宿主按项目校验;这里只挡明显离谱的值。
58
58
  */
59
- export const OPEN_STAMP_MIN = 2;
59
+ export const OPEN_STAMP_MIN = 1;
60
60
  export const OPEN_STAMP_MAX = 512;
61
61
  /** 深链接里 `dialog` 允许的取值(别的值一律丢掉,别把链接当任意指令用)。 */
62
62
  export const OPEN_DIALOGS = ["add"];