mudlet-map-renderer 0.0.19 → 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/git +0 -0
- package/map-fragment/draw/controls.js +25 -1
- package/map-fragment/draw/renderer.js +24 -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/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,18 +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;
|
|
92
94
|
this.path = [];
|
|
93
95
|
this.render();
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
render(pngRender = false) {
|
|
98
|
+
render(pngRender = false) {
|
|
97
99
|
this.pngRender = pngRender;
|
|
98
100
|
this.renderBackground(this.bounds.minX - padding, this.bounds.minY - padding, this.bounds.maxX + padding, this.bounds.maxY + padding);
|
|
99
101
|
this.renderHeader(this.bounds.minX - padding / 2, this.bounds.maxY + padding / 2);
|
|
@@ -112,6 +114,12 @@ class Renderer {
|
|
|
112
114
|
this.scale,
|
|
113
115
|
new paper.Point(this.bounds.minX, this.bounds.maxY)
|
|
114
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
|
+
}
|
|
115
123
|
this.transform();
|
|
116
124
|
if (this.isVisual) {
|
|
117
125
|
this.controls = new Controls(this, this.reader, this.element, this.paper);
|
|
@@ -694,23 +702,30 @@ class Renderer {
|
|
|
694
702
|
}
|
|
695
703
|
highlight.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
696
704
|
highlight.dashArray = [0.1, 0.1];
|
|
697
|
-
|
|
705
|
+
highlight.locked = true;
|
|
706
|
+
this.highlights.addChild(highlight)
|
|
698
707
|
}
|
|
699
708
|
|
|
700
709
|
clearHighlight() {
|
|
701
|
-
this.highlights.
|
|
702
|
-
this.highlights = [];
|
|
710
|
+
this.highlights.removeChildren()
|
|
703
711
|
}
|
|
704
712
|
|
|
705
713
|
renderPath(locations, color) {
|
|
706
714
|
this.overlayLayer.activate();
|
|
715
|
+
let group = new paper.Group();
|
|
707
716
|
locations.forEach(id => {
|
|
708
717
|
let room = this.area.getRoomById(id);
|
|
718
|
+
if (!room) {
|
|
719
|
+
return
|
|
720
|
+
}
|
|
709
721
|
let startPoint = new paper.Point(room.x + this.roomFactor * 0.5, room.y + this.roomFactor * 0.5)
|
|
710
722
|
let exits = Object.values(room.exits).concat(Object.values(room.specialExits))
|
|
711
723
|
exits.forEach(exitRoomId => {
|
|
712
724
|
if (locations.indexOf(exitRoomId) > -1) {
|
|
713
725
|
let exitRoom = this.area.getRoomById(exitRoomId);
|
|
726
|
+
if (!exitRoom) {
|
|
727
|
+
return
|
|
728
|
+
}
|
|
714
729
|
let endPoint = new paper.Point(exitRoom.x + this.roomFactor * 0.5, exitRoom.y + this.roomFactor * 0.5)
|
|
715
730
|
let line = new paper.Path.Line(startPoint, endPoint)
|
|
716
731
|
line.strokeWidth = this.exitFactor * 4;
|
|
@@ -718,10 +733,13 @@ class Renderer {
|
|
|
718
733
|
color = [0.4, 0.9, 0.3];
|
|
719
734
|
}
|
|
720
735
|
line.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
721
|
-
this.path.push(line)
|
|
736
|
+
this.path.push(line);
|
|
737
|
+
group.addChild(line);
|
|
722
738
|
}
|
|
723
739
|
})
|
|
724
740
|
})
|
|
741
|
+
group.locked = true;
|
|
742
|
+
return group;
|
|
725
743
|
}
|
|
726
744
|
|
|
727
745
|
clearPath() {
|
|
@@ -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"
|