mudlet-map-renderer 0.0.18 → 0.0.20
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/.prettierrc +0 -1
- package/CHANGELOG.md +3 -0
- package/git +0 -0
- package/map-fragment/draw/controls.js +25 -1
- package/map-fragment/draw/renderer.js +52 -6
- package/map-fragment/reader/MapReader.js +1 -1
- package/map-fragment/reader/pathFind.js +26 -0
- package/package.json +2 -1
package/.prettierrc
CHANGED
package/CHANGELOG.md
CHANGED
package/git
ADDED
|
File without changes
|
|
@@ -73,6 +73,7 @@ class Controls {
|
|
|
73
73
|
let toolPan = new paper.Tool();
|
|
74
74
|
toolPan.activate();
|
|
75
75
|
toolPan.onMouseDrag = (event) => {
|
|
76
|
+
this.toggleOptimizedDrag(true)
|
|
76
77
|
this.element.style.cursor = "all-scroll";
|
|
77
78
|
let delta = event.downPoint.subtract(event.point);
|
|
78
79
|
this.view.translate(delta.negate());
|
|
@@ -86,9 +87,27 @@ class Controls {
|
|
|
86
87
|
toolPan.onMouseUp = () => {
|
|
87
88
|
this.isDrag = false;
|
|
88
89
|
this.element.style.cursor = "default";
|
|
90
|
+
this.toggleOptimizedDrag(false)
|
|
89
91
|
};
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
toggleOptimizedDrag(state) {
|
|
95
|
+
if (!this.renderer.settings.optimizeDrag) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if(state) {
|
|
99
|
+
if (!this.isDrag) {
|
|
100
|
+
this.renderer.linkLayer.visible = false
|
|
101
|
+
this.renderer.roomLayer.visible = false
|
|
102
|
+
this.renderer.rasterLayer.visible = true
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
this.renderer.linkLayer.visible = true
|
|
106
|
+
this.renderer.roomLayer.visible = true
|
|
107
|
+
this.renderer.rasterLayer.visible = false
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
92
111
|
selectRoom(room) {
|
|
93
112
|
if (this.isDrag) {
|
|
94
113
|
return false;
|
|
@@ -107,6 +126,7 @@ class Controls {
|
|
|
107
126
|
return false;
|
|
108
127
|
}
|
|
109
128
|
this.renderer.clearPosition();
|
|
129
|
+
this.renderer.clearHighlight();
|
|
110
130
|
if (this.selected !== undefined) {
|
|
111
131
|
this.selected.render.select();
|
|
112
132
|
this.selected.exitsRenders.forEach((render) => render.select());
|
|
@@ -118,10 +138,14 @@ class Controls {
|
|
|
118
138
|
centerRoom(id) {
|
|
119
139
|
let room = this.renderer.area.getRoomById(id);
|
|
120
140
|
if (room !== undefined) {
|
|
121
|
-
this.
|
|
141
|
+
this.centerOnItem(room.render);
|
|
122
142
|
this.selectRoom(room);
|
|
123
143
|
}
|
|
124
144
|
}
|
|
145
|
+
|
|
146
|
+
centerOnItem(item) {
|
|
147
|
+
this.view.center = item.localToGlobal(item.position);
|
|
148
|
+
}
|
|
125
149
|
|
|
126
150
|
goToRoomArea(id) {
|
|
127
151
|
let destRoom = this.reader.getRoomById(id);
|
|
@@ -82,17 +82,20 @@ class Renderer {
|
|
|
82
82
|
this.bgLabels = new paper.Layer();
|
|
83
83
|
this.linkLayer = new paper.Layer();
|
|
84
84
|
this.roomLayer = new paper.Layer();
|
|
85
|
+
this.rasterLayer = new paper.Layer();
|
|
85
86
|
this.labelsLayer = new paper.Layer();
|
|
86
87
|
this.specialLinkLayer = new paper.Layer();
|
|
87
88
|
this.charsLayer = new paper.Layer();
|
|
88
89
|
this.overlayLayer = new paper.Layer();
|
|
89
90
|
this.exitsRendered = {};
|
|
90
91
|
this.defualtColor = new paper.Color(this.colors.default[0] / 255, this.colors.default[1] / 255, this.colors.default[2] / 255);
|
|
91
|
-
this.highlights =
|
|
92
|
+
this.highlights = new paper.Group();
|
|
93
|
+
this.highlights.locked = true;
|
|
94
|
+
this.path = [];
|
|
92
95
|
this.render();
|
|
93
96
|
}
|
|
94
97
|
|
|
95
|
-
render(pngRender = false) {
|
|
98
|
+
render(pngRender = false) {
|
|
96
99
|
this.pngRender = pngRender;
|
|
97
100
|
this.renderBackground(this.bounds.minX - padding, this.bounds.minY - padding, this.bounds.maxX + padding, this.bounds.maxY + padding);
|
|
98
101
|
this.renderHeader(this.bounds.minX - padding / 2, this.bounds.maxY + padding / 2);
|
|
@@ -111,6 +114,12 @@ class Renderer {
|
|
|
111
114
|
this.scale,
|
|
112
115
|
new paper.Point(this.bounds.minX, this.bounds.maxY)
|
|
113
116
|
);
|
|
117
|
+
if (this.settings.optimizeDrag) {
|
|
118
|
+
this.rasterLayer.activate();
|
|
119
|
+
this.linkRaster = this.linkLayer.rasterize({resolution: 2000});
|
|
120
|
+
this.roomRaster = this.roomLayer.rasterize({resolution: 2000});
|
|
121
|
+
this.rasterLayer.visible = false;
|
|
122
|
+
}
|
|
114
123
|
this.transform();
|
|
115
124
|
if (this.isVisual) {
|
|
116
125
|
this.controls = new Controls(this, this.reader, this.element, this.paper);
|
|
@@ -693,12 +702,49 @@ class Renderer {
|
|
|
693
702
|
}
|
|
694
703
|
highlight.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
695
704
|
highlight.dashArray = [0.1, 0.1];
|
|
696
|
-
|
|
705
|
+
highlight.locked = true;
|
|
706
|
+
this.highlights.addChild(highlight)
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
clearHighlight() {
|
|
710
|
+
this.highlights.removeChildren()
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
renderPath(locations, color) {
|
|
714
|
+
this.overlayLayer.activate();
|
|
715
|
+
let group = new paper.Group();
|
|
716
|
+
locations.forEach(id => {
|
|
717
|
+
let room = this.area.getRoomById(id);
|
|
718
|
+
if (!room) {
|
|
719
|
+
return
|
|
720
|
+
}
|
|
721
|
+
let startPoint = new paper.Point(room.x + this.roomFactor * 0.5, room.y + this.roomFactor * 0.5)
|
|
722
|
+
let exits = Object.values(room.exits).concat(Object.values(room.specialExits))
|
|
723
|
+
exits.forEach(exitRoomId => {
|
|
724
|
+
if (locations.indexOf(exitRoomId) > -1) {
|
|
725
|
+
let exitRoom = this.area.getRoomById(exitRoomId);
|
|
726
|
+
if (!exitRoom) {
|
|
727
|
+
return
|
|
728
|
+
}
|
|
729
|
+
let endPoint = new paper.Point(exitRoom.x + this.roomFactor * 0.5, exitRoom.y + this.roomFactor * 0.5)
|
|
730
|
+
let line = new paper.Path.Line(startPoint, endPoint)
|
|
731
|
+
line.strokeWidth = this.exitFactor * 4;
|
|
732
|
+
if (color === undefined) {
|
|
733
|
+
color = [0.4, 0.9, 0.3];
|
|
734
|
+
}
|
|
735
|
+
line.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
736
|
+
this.path.push(line);
|
|
737
|
+
group.addChild(line);
|
|
738
|
+
}
|
|
739
|
+
})
|
|
740
|
+
})
|
|
741
|
+
group.locked = true;
|
|
742
|
+
return group;
|
|
697
743
|
}
|
|
698
744
|
|
|
699
|
-
|
|
700
|
-
this.
|
|
701
|
-
this.
|
|
745
|
+
clearPath() {
|
|
746
|
+
this.path.forEach((element) => element.remove());
|
|
747
|
+
this.path = [];
|
|
702
748
|
}
|
|
703
749
|
|
|
704
750
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { MapReader } = require("./MapReader");
|
|
2
|
+
const Graph = require("node-dijkstra")
|
|
3
|
+
|
|
4
|
+
class PathFinder {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {MapReader} reader
|
|
9
|
+
*/
|
|
10
|
+
constructor(reader) {
|
|
11
|
+
this.route = new Graph();
|
|
12
|
+
reader.getAreas().forEach(area => area.rooms.forEach(room => {
|
|
13
|
+
let exits = Object.values(room.exits).concat(Object.values(room.specialExits)).map(item => [item, 1]);
|
|
14
|
+
this.route.addNode(room.id.toString(), Object.fromEntries(exits))
|
|
15
|
+
}))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
path(from, to) {
|
|
19
|
+
return this.route.path(from.toString(), to.toString())
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = {
|
|
25
|
+
PathFinder
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mudlet-map-renderer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"mudlet",
|
|
6
6
|
"map",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"homepage": "https://github.com/Delwing/js-mudlet-map-renderer#readme",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"node-dijkstra": "^2.5.0",
|
|
18
19
|
"paper-jsdom": "^0.12.15"
|
|
19
20
|
},
|
|
20
21
|
"main": "./exports.js"
|