dsh-game-material-master 0.10.2 → 0.11.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/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
  }
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"];
package/lib/mapdoc.js CHANGED
@@ -156,7 +156,20 @@ function normalizeMarkers(raw, cols, rows) {
156
156
  const given = typeof marker?.id === "string" && marker.id !== "" ? marker.id : "";
157
157
  const id = given !== "" && !used.has(given) ? given : nextId();
158
158
  used.add(id);
159
- out.push({ id, r, c, name: typeof marker?.name === "string" ? marker.name : "" });
159
+ const kind = typeof marker?.kind === "string" && marker.kind.trim() !== "" ? marker.kind.trim() : undefined;
160
+ const color = typeof marker?.color === "string" && /^#[0-9a-f]{6}$/i.test(marker.color.trim()) ? marker.color.trim() : undefined;
161
+ const note = typeof marker?.note === "string" && marker.note !== "" ? marker.note : undefined;
162
+ const tags = Array.isArray(marker?.tags) ? marker.tags.filter((tag) => typeof tag === "string" && tag !== "") : undefined;
163
+ out.push({
164
+ id,
165
+ r,
166
+ c,
167
+ name: typeof marker?.name === "string" ? marker.name : "",
168
+ ...(kind === undefined ? {} : { kind }),
169
+ ...(color === undefined ? {} : { color }),
170
+ ...(note === undefined ? {} : { note }),
171
+ ...(tags === undefined || tags.length === 0 ? {} : { tags })
172
+ });
160
173
  }
161
174
  return out;
162
175
  }
@@ -424,6 +437,33 @@ export function applyOps(doc, ops, layout, options = {}) {
424
437
  }
425
438
  return out;
426
439
  };
440
+ /** 一张整图放在目标位置时占的格子;越界 / 规格缺失返回 undefined。 */
441
+ const stampTargetCells = (spec, r, c, rot) => {
442
+ const span = stampSpanOf(spec, rot);
443
+ if (span.cols > doc.cols || span.rows > doc.rows)
444
+ return undefined;
445
+ const out = [];
446
+ for (let dr = 0; dr < span.rows; dr++) {
447
+ for (let dc = 0; dc < span.cols; dc++) {
448
+ const cell = canonical(r + dr, c + dc);
449
+ if (cell === undefined)
450
+ return undefined;
451
+ out.push(cell.r * doc.cols + cell.c);
452
+ }
453
+ }
454
+ return out;
455
+ };
456
+ /** 目标格是否被另一张整图占着(移动 / 旋转不能静默顶掉别的图)。 */
457
+ const stampOccupiedByOther = (targetCells, selfId, layerId) => {
458
+ for (const stamp of doc.stamps) {
459
+ if (stamp.id === selfId || stamp.layerId !== layerId)
460
+ continue;
461
+ const cells = stampCellIndices(stamp);
462
+ if (cells.some((index) => targetCells.includes(index)))
463
+ return true;
464
+ }
465
+ return false;
466
+ };
427
467
  /**
428
468
  * 落笔前把压在这些格子上的整图摘掉(同一图层)。
429
469
  *
@@ -472,6 +512,46 @@ export function applyOps(doc, ops, layout, options = {}) {
472
512
  stampsTouched++;
473
513
  continue;
474
514
  }
515
+ if (op.kind === "stampMove" || op.kind === "stampRotate") {
516
+ const stamp = doc.stamps.find((entry) => entry.id === op.id);
517
+ if (stamp === undefined) {
518
+ skipped.push(`没有这张整图:${String(op.id)}`);
519
+ continue;
520
+ }
521
+ const spec = options.stampSpecOf?.(stamp.tilesetId);
522
+ if (spec === undefined) {
523
+ skipped.push(`整图素材不存在或不是整图:${stamp.tilesetId}`);
524
+ continue;
525
+ }
526
+ const targetR = op.kind === "stampMove" ? Math.round(Number(op.r)) : stamp.r;
527
+ const targetC = op.kind === "stampMove" ? Math.round(Number(op.c)) : stamp.c;
528
+ const targetRot = op.kind === "stampRotate" ? ((Math.round(Number(op.rot)) % 4) + 4) % 4 : stamp.rot;
529
+ if (targetR === stamp.r && targetC === stamp.c && targetRot === stamp.rot)
530
+ continue;
531
+ const targetCells = stampTargetCells(spec, targetR, targetC, targetRot);
532
+ if (targetCells === undefined) {
533
+ skipped.push("整图放不下(目标位置越界或比地图还大)");
534
+ continue;
535
+ }
536
+ if (stampOccupiedByOther(targetCells, stamp.id, stamp.layerId)) {
537
+ skipped.push(`目标位置已经被另一张整图占着:${stamp.id}`);
538
+ continue;
539
+ }
540
+ const oldCells = stampCellIndices(stamp);
541
+ for (const index of oldCells)
542
+ markCell(Math.floor(index / doc.cols), index % doc.cols);
543
+ const before = { r: stamp.r, c: stamp.c, rot: stamp.rot };
544
+ stamp.r = targetR;
545
+ stamp.c = targetC;
546
+ stamp.rot = targetRot;
547
+ for (const index of targetCells)
548
+ markCell(Math.floor(index / doc.cols), index % doc.cols);
549
+ undo.push(op.kind === "stampMove"
550
+ ? { kind: "stampMove", id: stamp.id, r: before.r, c: before.c }
551
+ : { kind: "stampRotate", id: stamp.id, rot: before.rot });
552
+ stampsTouched++;
553
+ continue;
554
+ }
475
555
  if (op.kind === "stampPlace") {
476
556
  if (typeof op.layerId !== "string" || doc.data[op.layerId] === undefined) {
477
557
  skipped.push(`图层不存在:${String(op.layerId)}`);
@@ -648,6 +728,20 @@ export function applyOps(doc, ops, layout, options = {}) {
648
728
  * (宿主每次查询都会回整份标记表,所以只脏一个块也能拉到新号码;但脏哪一块是**宿主**
649
729
  * 算的,不能指望「用户恰好看得见被删的那个」。)
650
730
  */
731
+ /** 标记的语义字段(新增 / 更新共用;空串视为清空)。 */
732
+ function markerMeta(input, includeKind = true) {
733
+ const rawKind = input.markerKind !== undefined ? input.markerKind : includeKind ? input.kind : undefined;
734
+ const kind = typeof rawKind === "string" && rawKind.trim() !== "" ? rawKind.trim() : undefined;
735
+ const color = typeof input.color === "string" && /^#[0-9a-f]{6}$/i.test(input.color.trim()) ? input.color.trim() : undefined;
736
+ const note = typeof input.note === "string" && input.note !== "" ? input.note : undefined;
737
+ const tags = Array.isArray(input.tags) ? input.tags.filter((tag) => typeof tag === "string" && tag !== "") : undefined;
738
+ return {
739
+ ...(kind === undefined ? {} : { kind }),
740
+ ...(color === undefined ? {} : { color }),
741
+ ...(note === undefined ? {} : { note }),
742
+ ...(tags === undefined || tags.length === 0 ? {} : { tags })
743
+ };
744
+ }
651
745
  function applyMarkerOp(doc, op, env, skipped, undo) {
652
746
  const indexOf = (id) => (typeof id === "string" ? doc.markers.findIndex((marker) => marker.id === id) : -1);
653
747
  const occupiedAt = (r, c) => doc.markers.findIndex((marker) => marker.r === r && marker.c === c);
@@ -670,7 +764,13 @@ function applyMarkerOp(doc, op, env, skipped, undo) {
670
764
  }
671
765
  const id = given !== "" ? given : nextMarkerId(doc);
672
766
  const at = Number.isInteger(op.at) ? Math.min(doc.markers.length, Math.max(0, Number(op.at))) : doc.markers.length;
673
- doc.markers.splice(at, 0, { id, r: target.r, c: target.c, name: typeof op.name === "string" ? op.name : "" });
767
+ doc.markers.splice(at, 0, {
768
+ id,
769
+ r: target.r,
770
+ c: target.c,
771
+ name: typeof op.name === "string" ? op.name : "",
772
+ ...markerMeta(op, false)
773
+ });
674
774
  env.markCell(target.r, target.c);
675
775
  env.markNumberingFrom(at);
676
776
  undo.push({ kind: "marker", op: "remove", id });
@@ -687,7 +787,20 @@ function applyMarkerOp(doc, op, env, skipped, undo) {
687
787
  env.markCell(marker.r, marker.c);
688
788
  env.markNumberingFrom(index);
689
789
  // 逆操作**插回原位置**:插到末尾的话,撤销之后编号顺序就变了。
690
- undo.push({ kind: "marker", op: "add", id: marker.id, r: marker.r, c: marker.c, name: marker.name, at: index });
790
+ const saved = markerMeta(marker);
791
+ undo.push({
792
+ kind: "marker",
793
+ op: "add",
794
+ id: marker.id,
795
+ r: marker.r,
796
+ c: marker.c,
797
+ name: marker.name,
798
+ at: index,
799
+ ...(saved.kind === undefined ? {} : { markerKind: saved.kind }),
800
+ ...(saved.color === undefined ? {} : { color: saved.color }),
801
+ ...(saved.note === undefined ? {} : { note: saved.note }),
802
+ ...(saved.tags === undefined ? {} : { tags: saved.tags })
803
+ });
691
804
  return true;
692
805
  }
693
806
  if (op.op === "move") {
@@ -711,6 +824,52 @@ function applyMarkerOp(doc, op, env, skipped, undo) {
711
824
  undo.push({ kind: "marker", op: "move", id: marker.id, r: from.r, c: from.c });
712
825
  return true;
713
826
  }
827
+ if (op.op === "update") {
828
+ const patch = op.patch ?? {};
829
+ const before = { ...marker };
830
+ if (typeof patch.name === "string")
831
+ marker.name = patch.name;
832
+ if (patch.kind !== undefined) {
833
+ if (patch.kind.trim() === "")
834
+ delete marker.kind;
835
+ else
836
+ marker.kind = patch.kind.trim();
837
+ }
838
+ if (patch.color !== undefined) {
839
+ if (patch.color.trim() === "")
840
+ delete marker.color;
841
+ else if (/^#[0-9a-f]{6}$/i.test(patch.color.trim()))
842
+ marker.color = patch.color.trim();
843
+ }
844
+ if (patch.note !== undefined) {
845
+ if (patch.note === "")
846
+ delete marker.note;
847
+ else
848
+ marker.note = patch.note;
849
+ }
850
+ if (patch.tags !== undefined) {
851
+ const tags = patch.tags.filter((tag) => typeof tag === "string" && tag !== "");
852
+ if (tags.length === 0)
853
+ delete marker.tags;
854
+ else
855
+ marker.tags = tags;
856
+ }
857
+ if (JSON.stringify(before) === JSON.stringify(marker))
858
+ return false;
859
+ undo.push({
860
+ kind: "marker",
861
+ op: "update",
862
+ id: marker.id,
863
+ patch: {
864
+ name: before.name,
865
+ kind: before.kind ?? "",
866
+ color: before.color ?? "",
867
+ note: before.note ?? "",
868
+ tags: before.tags ?? []
869
+ }
870
+ });
871
+ return true;
872
+ }
714
873
  const name = typeof op.name === "string" ? op.name : "";
715
874
  if (marker.name === name)
716
875
  return false;
package/lib/mapexport.js CHANGED
@@ -48,6 +48,8 @@ import { zipEntries } from "./zip.js";
48
48
  * - `@4`:顶层多了 `stamps`(整图:占 N×M 格的多格印花 + 每格通行性)。
49
49
  */
50
50
  export const OWN_JSON_FORMAT = "dsh-gem-map@4";
51
+ /** 带标记语义字段 / 区域时使用;没有新字段的老文档仍然写 @4。 */
52
+ export const OWN_JSON_FORMAT_META = "dsh-gem-map@5";
51
53
  /** 文件名安全化:名字直接进目录会踩到 `/`、`:` 与超长名。 */
52
54
  export function safeFileName(input, fallback = "map") {
53
55
  const cleaned = (input ?? "")
@@ -85,8 +87,9 @@ export function safeFileName(input, fallback = "map") {
85
87
  */
86
88
  export function buildOwnJson(context, doc, project) {
87
89
  void project;
90
+ const hasMarkerMeta = doc.markers.some((marker) => marker.kind !== undefined || marker.color !== undefined || marker.note !== undefined || marker.tags !== undefined);
88
91
  return {
89
- format: OWN_JSON_FORMAT,
92
+ format: hasMarkerMeta ? OWN_JSON_FORMAT_META : OWN_JSON_FORMAT,
90
93
  grid: { tileWidth: context.grid.tileWidth, tileHeight: context.grid.tileHeight, wrap: context.grid.wrap },
91
94
  cols: doc.cols,
92
95
  rows: doc.rows,
@@ -101,7 +104,16 @@ export function buildOwnJson(context, doc, project) {
101
104
  })),
102
105
  legend: flatTiles(context.tilesets).map((flat) => ({ index: flat.index, tilesetId: flat.tilesetId, rect: flat.tile.rect })),
103
106
  layers: doc.layers.map((layer) => ({ name: layer.name, data: [...(doc.data[layer.id] ?? [])] })),
104
- markers: doc.markers.map((marker, index) => ({ n: index + 1, name: marker.name, r: marker.r, c: marker.c })),
107
+ markers: doc.markers.map((marker, index) => ({
108
+ n: index + 1,
109
+ name: marker.name,
110
+ r: marker.r,
111
+ c: marker.c,
112
+ ...(marker.kind === undefined ? {} : { kind: marker.kind }),
113
+ ...(marker.color === undefined ? {} : { color: marker.color }),
114
+ ...(marker.note === undefined ? {} : { note: marker.note }),
115
+ ...(marker.tags === undefined ? {} : { tags: marker.tags })
116
+ })),
105
117
  stamps: doc.stamps.map((stamp) => {
106
118
  const tileset = context.tilesets.find((entry) => entry.id === stamp.tilesetId);
107
119
  const spec = tileset?.stamp;