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/README.en.md +27 -3
- package/README.md +23 -3
- package/lib/chroma.js +74 -15
- package/lib/client.js +535 -156
- package/lib/config.js +6 -3
- package/lib/customimage.js +43 -0
- package/lib/directions.js +69 -8
- package/lib/imagedraw.js +185 -0
- package/lib/imagegen.js +17 -5
- package/lib/imageprovider.js +7 -2
- package/lib/index.js +128 -19
- package/lib/isocompose.js +26 -17
- package/lib/isodoc.js +153 -4
- package/lib/isoexport.js +14 -2
- package/lib/isogen.js +413 -22
- package/lib/isorender.js +215 -0
- package/lib/keycolor.js +251 -0
- package/lib/links.js +1 -1
- package/lib/mapdoc.js +162 -3
- package/lib/mapexport.js +14 -2
- package/lib/mapgen.js +432 -29
- package/lib/maprender.js +169 -0
- package/lib/maptiles.js +7 -2
- package/lib/pipeline.js +10 -3
- package/lib/riggen.js +4 -4
- package/lib/seqgen.js +7 -0
- package/lib/store.js +23 -12
- package/lib/toolguides.js +63 -18
- package/lib/tools.js +35 -7
- package/lib/wire.js +103 -13
- package/package.json +1 -1
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
|
-
|
|
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, {
|
|
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
|
-
|
|
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) => ({
|
|
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;
|