mudlet-map-renderer 0.0.15 → 0.0.16

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.0.16
2
+ - add emoss setting
3
+ - add drag event
4
+
1
5
  # 0.0.15
2
6
  - additional fix for custom exit lines exit
3
7
  # 0.0.14
package/README.md CHANGED
@@ -31,7 +31,7 @@ let reader = new MapReader(mapData, mapColors);
31
31
  const roomId = 1;
32
32
  const scale = 40;
33
33
  let area = reader.getAreaByRoomId(roomId);
34
- let settings = { scale: scale}
34
+ let settings = { scale: scale }
35
35
  let renderer = new Renderer(null, reader, area, reader.getColors(), settings);
36
36
  fs.writeFileSync("mapFull.svg", renderer.exportSvg());
37
37
  fs.writeFileSync("mapFragment.svg", renderer.exportSvg(roomId, 10));
@@ -54,5 +54,6 @@ class Settings {
54
54
  mapBackground = "#000000";
55
55
  linesColor = '#FFFFFF';
56
56
  transparentLabels = false;
57
+ emboss = false;
57
58
  }
58
59
  ```
@@ -80,6 +80,7 @@ class Controls {
80
80
  };
81
81
  toolPan.onMouseDown = () => {
82
82
  this.isDrag = false;
83
+ this.element.dispatchEvent(new CustomEvent("drag", { detail: this.view }));
83
84
  };
84
85
  toolPan.onMouseUp = () => {
85
86
  this.isDrag = false;
@@ -28,6 +28,7 @@ class Settings {
28
28
  this.mapBackground = Colors.DEFAULT_BACKGROUND
29
29
  this.linesColor = Colors.DEFAULT
30
30
  this.transparentLabels = false;
31
+ this.emboss = false;
31
32
  }
32
33
  }
33
34
 
@@ -87,6 +88,7 @@ class Renderer {
87
88
  this.overlayLayer = new paper.Layer();
88
89
  this.exitsRendered = {};
89
90
  this.defualtColor = new paper.Color(this.colors.default[0] / 255, this.colors.default[1] / 255, this.colors.default[2] / 255);
91
+ this.highlights = [];
90
92
  this.render();
91
93
  }
92
94
 
@@ -112,6 +114,7 @@ class Renderer {
112
114
  this.transform();
113
115
  if (this.isVisual) {
114
116
  this.controls = new Controls(this, this.reader, this.element, this.paper);
117
+ this.element.dispatchEvent(new CustomEvent("renderComplete", { detail: this }));
115
118
  }
116
119
  }
117
120
 
@@ -191,6 +194,21 @@ class Renderer {
191
194
  this.renderStub(room, dirNumbers[room.stubs[dir]]);
192
195
  }
193
196
 
197
+ if (this.settings.emboss) {
198
+ this.overlayLayer.activate()
199
+ let emboss
200
+ if (new paper.Color(this.settings.linesColor).lightness > 0.41) {
201
+ emboss= new paper.Path([room.render.bounds.topRight, room.render.bounds.topLeft, room.render.bounds.bottomLeft])
202
+ emboss.strokeColor = '#000000'
203
+ } else {
204
+ emboss = emboss= new paper.Path([room.render.bounds.topRight, room.render.bounds.bottomRight, room.render.bounds.bottomLeft])
205
+ emboss.strokeColor = '#ffffff'
206
+ }
207
+
208
+
209
+ emboss.strokeWidth = this.exitFactor
210
+ }
211
+
194
212
  this.renderChar(room);
195
213
 
196
214
  roomShape.pointerReactor(this.element);
@@ -535,14 +553,15 @@ class Renderer {
535
553
  if (!this.settings.transparentLabels) {
536
554
  background.fillColor = new paper.Color(value.BgColor.r / 255, value.BgColor.g / 255, value.BgColor.b / 255);
537
555
  }
538
- let text = new paper.PointText(background.bounds.center.add(0, 0.15));
556
+ let text = new paper.PointText(background.bounds.center.add(0, 0.15 * 8));
539
557
  text.fillColor = new paper.Color(value.FgColor.r / 255, value.FgColor.g / 255, value.FgColor.b / 255);
540
- text.fontSize = Math.min(0.75, value.Width / (value.Text.length / 2));
558
+ let ratio = Math.min(0.75, value.Width / (value.Text.length / 2));
559
+ text.fontSize = 4
541
560
  text.content = value.Text;
542
561
  text.fontFamily = this.settings.fontFamily;
543
562
  text.justification = "center";
544
563
  text.locked = true;
545
- text.scale(1, -1);
564
+ text.scale(ratio / 4, -ratio / 4);
546
565
  }
547
566
  }
548
567
 
@@ -661,6 +680,28 @@ class Renderer {
661
680
  }
662
681
  }
663
682
 
683
+ renderHighlight(id, color) {
684
+ this.overlayLayer.activate();
685
+ let room = this.area.getRoomById(id);
686
+ let highlight = new paper.Shape.Circle(new paper.Point(room.x + this.roomFactor * 0.5, room.y + this.roomFactor * 0.5), this.roomDiagonal * 0.6);
687
+ highlight.fillColor = new paper.Color(0.5, 0.1, 0.1, 0.2);
688
+ highlight.strokeWidth = this.exitFactor * 4;
689
+ highlight.shadowColor = room.render.fillColor;
690
+ highlight.shadowBlur = 12;
691
+ if (color === undefined) {
692
+ color = [0.4, 0.9, 0.3];
693
+ }
694
+ highlight.strokeColor = new paper.Color(color[0], color[1], color[2]);
695
+ highlight.dashArray = [0.1, 0.1];
696
+ this.highlights.push(highlight)
697
+ }
698
+
699
+ clearHighlight(id) {
700
+ this.highlights.forEach((element) => element.remove());
701
+ this.highlights = [];
702
+ }
703
+
704
+
664
705
  clear() {
665
706
  this.paper.clear();
666
707
  }
@@ -728,4 +769,4 @@ function dirsShortToLong(dir) {
728
769
 
729
770
  function dirLongToShort(dir) {
730
771
  return dirs[dir] !== undefined ? dirs[dir] : dir;
731
- }
772
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mudlet-map-renderer",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "keywords": [
5
5
  "mudlet",
6
6
  "map",