mudlet-map-editor 0.6.0 → 0.6.2

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.md CHANGED
@@ -74,4 +74,6 @@ Binary .dat file
74
74
  → MapRenderer (Konva canvas) + LiveEffect overlays
75
75
  ```
76
76
 
77
- All map mutations go through a command system (`applyCommand`) that records operations for undo/redo. State is managed in a single centralized store.
77
+ All map mutations go through a command system (`applyCommand`) that records operations for undo/redo. State is managed in a single centralized store.
78
+
79
+ Bulk operations (multi-room delete, move rooms to area, undo/redo of the above) go through optimized paths in `EditorMapReader` that perform a single `rebuildPlanes`/`rebuildExits` per affected area rather than one per room, keeping large selections responsive.
@@ -75,6 +75,7 @@ export declare class EditorArea {
75
75
  getLinkExits(zIndex: number): EditorExit[];
76
76
  setLabels(labels: any[]): void;
77
77
  addRoomLive(room: LiveRoom): void;
78
+ addRoomsLive(newRooms: LiveRoom[]): void;
78
79
  removeRoomById(id: number): void;
79
80
  removeRoomsById(ids: Set<number>): void;
80
81
  rebuildPlanes(): void;
@@ -121,6 +122,11 @@ export declare class EditorMapReader {
121
122
  setUserDataEntry(id: number, key: string, value: string | null): void;
122
123
  /** Add a raw room (expected `raw.rooms[id]` already set or not, we set it). */
123
124
  addRoom(id: number, rawRoom: MudletRoom): void;
125
+ /** Bulk-add many rooms. Does one rebuildPlanes/rebuildExits per affected area. */
126
+ addRooms(rooms: Array<{
127
+ id: number;
128
+ room: MudletRoom;
129
+ }>): void;
124
130
  setSpecialExit(roomId: number, name: string, toId: number): void;
125
131
  removeSpecialExit(roomId: number, name: string): void;
126
132
  setDoor(roomId: number, dir: Direction, value: number): void;
package/dist-lib/index.js CHANGED
@@ -2684,6 +2684,22 @@ function Ee(e, t, n) {
2684
2684
  }
2685
2685
  return { structural: !1 };
2686
2686
  case "batch": {
2687
+ if (n?.reader && t.cmds.length > 1 && t.cmds.every((e) => e.kind === "deleteRoom")) {
2688
+ let r = t.cmds;
2689
+ for (let t of r) {
2690
+ e.rooms[t.id] = { ...t.room };
2691
+ let n = e.areas[t.areaId];
2692
+ n && !n.rooms.includes(t.id) && n.rooms.push(t.id);
2693
+ }
2694
+ for (let t of r) for (let n of t.neighborEdits) {
2695
+ let t = e.rooms[n.roomId];
2696
+ t && (t[n.dir] = n.was);
2697
+ }
2698
+ return n.reader.addRooms(r.map((t) => ({
2699
+ id: t.id,
2700
+ room: e.rooms[t.id]
2701
+ }))), { structural: !0 };
2702
+ }
2687
2703
  let r = !1;
2688
2704
  for (let i of [...t.cmds].reverse()) Ee(e, i, n).structural && (r = !0);
2689
2705
  return { structural: r };
@@ -8317,6 +8333,27 @@ function mn({ sceneRef: e }) {
8317
8333
  }, x = () => {
8318
8334
  let t = D.getState();
8319
8335
  if (!t.map) return p();
8336
+ if (y) {
8337
+ let n = je(t.map, y);
8338
+ Y({
8339
+ kind: "batch",
8340
+ cmds: y.map((e) => {
8341
+ let r = t.map.rooms[e];
8342
+ return {
8343
+ kind: "deleteRoom",
8344
+ id: e,
8345
+ room: { ...r },
8346
+ areaId: r.area,
8347
+ neighborEdits: n.get(e) ?? []
8348
+ };
8349
+ })
8350
+ }, e.current), e.current?.refresh(), D.bumpStructure(), D.setState({
8351
+ selection: null,
8352
+ status: `Deleted ${y.length} rooms`,
8353
+ contextMenu: null
8354
+ });
8355
+ return;
8356
+ }
8320
8357
  let r = t.map.rooms[n.roomId];
8321
8358
  if (!r) return p();
8322
8359
  let i = { ...r }, a = Ae(t.map, n.roomId);
@@ -9483,7 +9520,7 @@ function Nn({ sceneRef: e }) {
9483
9520
  let e = r.getRenderRoom(a.anchorRoomId);
9484
9521
  c = e ? e.x : i.reduce((e, t) => e + t.rx, 0) / i.length, l = e ? e.y : i.reduce((e, t) => e + t.ry, 0) / i.length;
9485
9522
  } else c = i.reduce((e, t) => e + t.rx, 0) / i.length, l = i.reduce((e, t) => e + t.ry, 0) / i.length;
9486
- let u = t.snapToGrid ? (e) => Math.round(e / t.gridStep) * t.gridStep : Math.round, d = [];
9523
+ let u = t.snapToGrid ? (e) => Math.round(e / t.gridStep) * t.gridStep : (e) => e, d = [];
9487
9524
  for (let { id: e, rx: n, ry: r } of i) {
9488
9525
  let i = u(c + (n - c) * s), a = u(l + (r - l) * s), o = t.map.rooms[e];
9489
9526
  if (!o) continue;
@@ -9841,6 +9878,9 @@ var Hn = class {
9841
9878
  addRoomLive(e) {
9842
9879
  this.rooms.push(e), this.rebuildPlanes(), this.rebuildExits(), this.markDirty();
9843
9880
  }
9881
+ addRoomsLive(e) {
9882
+ this.rooms.push(...e), this.rebuildPlanes(), this.rebuildExits(), this.markDirty();
9883
+ }
9844
9884
  removeRoomById(e) {
9845
9885
  this.rooms = this.rooms.filter((t) => t.id !== e), this.rebuildPlanes(), this.rebuildExits(), this.markDirty();
9846
9886
  }
@@ -10006,6 +10046,21 @@ var Gn = {
10006
10046
  let r = Fn(e, t);
10007
10047
  this.rooms[e] = r, this.areas[t.area]?.addRoomLive(r);
10008
10048
  }
10049
+ addRooms(e) {
10050
+ let t = /* @__PURE__ */ new Map();
10051
+ for (let { id: n, room: r } of e) {
10052
+ this.raw.rooms[n] = r;
10053
+ let e = this.raw.areas[r.area];
10054
+ e && !e.rooms.includes(n) && e.rooms.push(n);
10055
+ let i = Fn(n, r);
10056
+ this.rooms[n] = i;
10057
+ let a = t.get(r.area);
10058
+ a || (a = [], t.set(r.area, a)), a.push(i);
10059
+ }
10060
+ let n = new Set(t.keys());
10061
+ for (let [e, n] of t) this.areas[e]?.addRoomsLive(n);
10062
+ for (let e of this.getAreas()) n.has(e.getAreaId()) || (e.rebuildExits(), e.markDirty());
10063
+ }
10009
10064
  setSpecialExit(e, t, n) {
10010
10065
  let r = this.raw.rooms[e];
10011
10066
  r && (r.mSpecialExits[t] = n, this.areas[r.area]?.markDirty());
@@ -10105,22 +10160,18 @@ var Gn = {
10105
10160
  delete this.raw.areas[e], delete this.raw.areaNames[e], delete this.areas[e];
10106
10161
  }
10107
10162
  moveRoomsToArea(e, t, n) {
10108
- let r = this.areas[t], i = this.areas[n], a = [...e];
10109
- for (let e of a) {
10110
- let a = this.raw.rooms[e];
10111
- if (!a) continue;
10112
- a.area = n;
10113
- let o = this.raw.areas[t];
10114
- if (o) {
10115
- let t = o.rooms.indexOf(e);
10116
- t !== -1 && o.rooms.splice(t, 1);
10117
- }
10118
- let s = this.raw.areas[n];
10119
- s && !s.rooms.includes(e) && s.rooms.push(e);
10120
- let c = this.rooms[e];
10121
- c && (r?.removeRoomById(e), i?.addRoomLive(c));
10122
- }
10123
- r?.markDirty();
10163
+ let r = this.areas[t], i = this.areas[n], a = new Set(e), o = [];
10164
+ for (let t of e) {
10165
+ let e = this.raw.rooms[t];
10166
+ if (!e) continue;
10167
+ e.area = n;
10168
+ let r = this.raw.areas[n];
10169
+ r && !r.rooms.includes(t) && r.rooms.push(t);
10170
+ let i = this.rooms[t];
10171
+ i && o.push(i);
10172
+ }
10173
+ let s = this.raw.areas[t];
10174
+ s && (s.rooms = s.rooms.filter((e) => !a.has(e))), r && r.removeRoomsById(a), i && i.addRoomsLive(o), r?.markDirty();
10124
10175
  }
10125
10176
  renameArea(e, t) {
10126
10177
  this.raw.areaNames[e] = t;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mudlet-map-editor",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "description": "Mudlet Map Editor",
6
6
  "keywords": [