mudlet-map-renderer 0.0.25 → 0.1.1-konva
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/dist/ExitRenderer.d.ts +25 -0
- package/dist/PathFinder.d.ts +9 -0
- package/dist/PathRenderer.d.ts +16 -0
- package/dist/Renderer.d.ts +44 -0
- package/dist/directions.d.ts +7 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +1074 -0
- package/dist/index.mjs.map +1 -0
- package/dist/reader/Area.d.ts +20 -0
- package/dist/reader/Exit.d.ts +12 -0
- package/dist/reader/ExplorationArea.d.ts +32 -0
- package/dist/reader/MapReader.d.ts +22 -0
- package/dist/reader/Plane.d.ts +15 -0
- package/dist/types/MapData.d.ts +67 -0
- package/package.json +37 -23
- package/.prettierrc +0 -5
- package/CHANGELOG.md +0 -69
- package/README.md +0 -59
- package/exports.js +0 -5
- package/map-fragment/draw/controls.js +0 -172
- package/map-fragment/draw/renderer.js +0 -819
- package/map-fragment/reader/Area.js +0 -74
- package/map-fragment/reader/MapReader.js +0 -89
- package/map-fragment/reader/PathFinder.js +0 -26
|
@@ -1,819 +0,0 @@
|
|
|
1
|
-
const paper = require("paper");
|
|
2
|
-
const MapReader = require("../reader/MapReader").MapReader;
|
|
3
|
-
const Controls = require("./controls").Controls;
|
|
4
|
-
|
|
5
|
-
const padding = 7;
|
|
6
|
-
const gridSize = 20;
|
|
7
|
-
|
|
8
|
-
const Colors = {
|
|
9
|
-
OPEN_DOOR : new paper.Color(10 / 255, 155 / 255, 10 / 255),
|
|
10
|
-
CLOSED_DOOR : new paper.Color(226 / 255, 205 / 255, 59 / 255),
|
|
11
|
-
LOCKED_DOOR : new paper.Color(155 / 255, 10 / 255, 10 / 255),
|
|
12
|
-
DEFAULT_BACKGROUND : new paper.Color(0, 0, 0),
|
|
13
|
-
DEFAULT : new paper.Color(1, 1, 1),
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
class Settings {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.isRound = false;
|
|
19
|
-
this.scale = 55;
|
|
20
|
-
this.roomSize = 10;
|
|
21
|
-
this.exitsSize = 2;
|
|
22
|
-
this.borders = false;
|
|
23
|
-
this.frameMode = false;
|
|
24
|
-
this.areaName = true;
|
|
25
|
-
this.showLabels = true;
|
|
26
|
-
this.uniformLevelSize = false;
|
|
27
|
-
this.fontFamily = 'sans-serif';
|
|
28
|
-
this.mapBackground = Colors.DEFAULT_BACKGROUND
|
|
29
|
-
this.linesColor = Colors.DEFAULT
|
|
30
|
-
this.transparentLabels = false;
|
|
31
|
-
this.emboss = false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
paper.Item.prototype.registerClick = function (callback) {
|
|
36
|
-
if (typeof document !== "undefined") {
|
|
37
|
-
this.onClick = callback;
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
paper.Item.prototype.pointerReactor = function (element) {
|
|
42
|
-
if (typeof document !== "undefined") {
|
|
43
|
-
this.onMouseEnter = () => (element.style.cursor = "pointer");
|
|
44
|
-
this.onMouseLeave = () => (element.style.cursor = "default");
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
class Renderer {
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* @param {HTMLElement} element
|
|
52
|
-
* @param {MapReader} reader
|
|
53
|
-
* @param {*} area
|
|
54
|
-
* @param {*} colors
|
|
55
|
-
* @param {Settings} settings
|
|
56
|
-
*/
|
|
57
|
-
constructor(element, reader, area, colors, settings) {
|
|
58
|
-
this.settings = new Settings();
|
|
59
|
-
Object.assign(this.settings, settings);
|
|
60
|
-
this.reader = reader;
|
|
61
|
-
this.area = area;
|
|
62
|
-
this.colors = colors;
|
|
63
|
-
this.scale = this.settings.scale;
|
|
64
|
-
this.grideSize = this.settings.gridSize;
|
|
65
|
-
this.roomSize = this.settings.roomSize;
|
|
66
|
-
this.roomFactor = this.roomSize / gridSize;
|
|
67
|
-
this.exitFactor = this.settings.exitsSize * 0.01;
|
|
68
|
-
this.roomDiagonal = this.roomFactor * Math.sqrt(2);
|
|
69
|
-
this.innerExits = ["up", "down", "u", "d", "in", "out", "i", "u"];
|
|
70
|
-
this.paper = new paper.PaperScope();
|
|
71
|
-
this.bounds = this.area.getAreaBounds(this.settings.uniformLevelSize);
|
|
72
|
-
if (element == undefined) {
|
|
73
|
-
element = new paper.Size((this.bounds.width + padding * 2) * this.scale, (this.bounds.height + padding * 2) * this.scale);
|
|
74
|
-
this.isVisual = false;
|
|
75
|
-
} else {
|
|
76
|
-
this.isVisual = true;
|
|
77
|
-
this.emitter = new EventTarget();
|
|
78
|
-
}
|
|
79
|
-
this.paper.setup(element);
|
|
80
|
-
this.element = element;
|
|
81
|
-
this.backgroundLayer = new paper.Layer();
|
|
82
|
-
this.bgLabels = new paper.Layer();
|
|
83
|
-
this.linkLayer = new paper.Layer();
|
|
84
|
-
this.roomLayer = new paper.Layer();
|
|
85
|
-
this.rasterLayer = new paper.Layer();
|
|
86
|
-
this.labelsLayer = new paper.Layer();
|
|
87
|
-
this.specialLinkLayer = new paper.Layer();
|
|
88
|
-
this.charsLayer = new paper.Layer();
|
|
89
|
-
this.overlayLayer = new paper.Layer();
|
|
90
|
-
this.exitsRendered = {};
|
|
91
|
-
this.defualtColor = new paper.Color(this.colors.default[0] / 255, this.colors.default[1] / 255, this.colors.default[2] / 255);
|
|
92
|
-
this.highlights = new paper.Group();
|
|
93
|
-
this.highlights.locked = true;
|
|
94
|
-
this.path = [];
|
|
95
|
-
this.render();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
render(pngRender = false) {
|
|
99
|
-
this.pngRender = pngRender;
|
|
100
|
-
this.renderBackground(this.bounds.minX - padding, this.bounds.minY - padding, this.bounds.maxX + padding, this.bounds.maxY + padding);
|
|
101
|
-
this.renderHeader(this.bounds.minX - padding / 2, this.bounds.maxY + padding / 2);
|
|
102
|
-
this.area.rooms
|
|
103
|
-
.filter((room) => room.z == this.area.zIndex)
|
|
104
|
-
.forEach((room) => {
|
|
105
|
-
this.renderRoom(room);
|
|
106
|
-
});
|
|
107
|
-
if (this.area.labels !== undefined && this.settings.showLabels) {
|
|
108
|
-
this.bgLabels.activate();
|
|
109
|
-
this.area.labels
|
|
110
|
-
.filter((label) => label.Z == this.area.zIndex)
|
|
111
|
-
.forEach((value) => this.renderLabel(value), this);
|
|
112
|
-
}
|
|
113
|
-
this.matrix = new paper.Matrix(1, 0, 0, -1, -this.bounds.minX + padding, this.bounds.maxY + padding).scale(
|
|
114
|
-
this.scale,
|
|
115
|
-
new paper.Point(this.bounds.minX, this.bounds.maxY)
|
|
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
|
-
}
|
|
123
|
-
this.transform();
|
|
124
|
-
if (this.isVisual) {
|
|
125
|
-
this.controls = new Controls(this, this.reader, this.element, this.paper);
|
|
126
|
-
this.element.dispatchEvent(new CustomEvent("renderComplete", { detail: this }));
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
transform() {
|
|
131
|
-
let padding = 1 * this.scale;
|
|
132
|
-
this.paper.project.layers.forEach((layer) => {
|
|
133
|
-
layer.applyMatrix = false;
|
|
134
|
-
layer.matrix = new paper.Matrix(1, 0, 0, -1, -this.bounds.minX + padding, this.bounds.maxY + padding).scale(
|
|
135
|
-
this.scale,
|
|
136
|
-
new paper.Point(this.bounds.minX, this.bounds.maxY)
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
renderBackground(x1, y1, x2, y2) {
|
|
142
|
-
this.backgroundLayer.activate();
|
|
143
|
-
let background = new paper.Path.Rectangle(new paper.Point(x1, y1), new paper.Point(x2, y2));
|
|
144
|
-
background.fillColor = new paper.Color(this.settings.mapBackground);
|
|
145
|
-
background.registerClick(() => {
|
|
146
|
-
this.emitter.dispatchEvent(new CustomEvent("backgroundClick"));
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
renderHeader(x, y) {
|
|
151
|
-
if (this.settings.areaName) {
|
|
152
|
-
this.backgroundLayer.activate();
|
|
153
|
-
let header = new paper.PointText(x, y);
|
|
154
|
-
header.fillColor = new paper.Color(1, 1, 1, 1);
|
|
155
|
-
header.fontSize = 2.5;
|
|
156
|
-
header.fontFamily = this.settings.fontFamily;
|
|
157
|
-
header.content = this.area.areaName;
|
|
158
|
-
header.scale(1, -1);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
renderRoom(room) {
|
|
163
|
-
this.roomLayer.activate();
|
|
164
|
-
let roomShape;
|
|
165
|
-
if (!this.settings.isRound) {
|
|
166
|
-
roomShape = new paper.Path.Rectangle(new paper.Point(room.x, room.y), new paper.Size(this.roomFactor, this.roomFactor));
|
|
167
|
-
} else {
|
|
168
|
-
roomShape = new paper.Path.Circle(new paper.Point(room.x + this.roomFactor / 2, room.y + this.roomFactor / 2), this.roomFactor / 2);
|
|
169
|
-
}
|
|
170
|
-
let color = this.colors[room.env];
|
|
171
|
-
if (color === undefined) {
|
|
172
|
-
color = [114, 1, 0];
|
|
173
|
-
}
|
|
174
|
-
let roomColor = new paper.Color(color[0] / 255, color[1] / 255, color[2] / 255, 1);
|
|
175
|
-
roomShape.fillColor = !this.settings.frameMode ? roomColor : new paper.Color(this.settings.mapBackground);
|
|
176
|
-
roomShape.strokeWidth = this.exitFactor;
|
|
177
|
-
roomShape.strokeColor = !this.settings.borders || this.settings.frameMode ? roomColor : this.settings.linesColor;
|
|
178
|
-
|
|
179
|
-
room.render = roomShape;
|
|
180
|
-
|
|
181
|
-
room.exitsRenders = room.exitsRenders != undefined ? room.exitsRenders : [];
|
|
182
|
-
for (let dir in room.exits) {
|
|
183
|
-
if (this.innerExits.indexOf(dir) <= -1) {
|
|
184
|
-
if (room.exits.hasOwnProperty(dir) && !room.customLines.hasOwnProperty(dirLongToShort(dir))) {
|
|
185
|
-
this.renderLink(room, room.exits[dir], dir);
|
|
186
|
-
}
|
|
187
|
-
} else {
|
|
188
|
-
this.renderInnerExit(room, dir);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
for (let dir in room.specialExits) {
|
|
193
|
-
if (room.specialExits.hasOwnProperty(dir) && !room.customLines.hasOwnProperty(dir)) {
|
|
194
|
-
this.renderSpecialLink(room, room.specialExits[dir], dir);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
for (let dir in room.customLines) {
|
|
199
|
-
this.renderCustomLine(room, dir, room.exits[dirsShortToLong(dir)] ?? room.specialExits[dirsShortToLong(dir)]);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
for (let dir in room.stubs) {
|
|
203
|
-
this.renderStub(room, dirNumbers[room.stubs[dir]]);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (this.settings.emboss) {
|
|
207
|
-
this.overlayLayer.activate()
|
|
208
|
-
let emboss
|
|
209
|
-
if (new paper.Color(this.settings.linesColor).lightness > 0.41) {
|
|
210
|
-
emboss= new paper.Path([room.render.bounds.topLeft, room.render.bounds.topRight, room.render.bounds.bottomRight])
|
|
211
|
-
emboss.strokeColor = '#000000'
|
|
212
|
-
} else {
|
|
213
|
-
emboss = emboss= new paper.Path([room.render.bounds.topLeft, room.render.bounds.bottomLeft, room.render.bounds.bottomRight])
|
|
214
|
-
emboss.strokeColor = '#ffffff'
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
emboss.strokeWidth = this.exitFactor
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
this.renderChar(room);
|
|
222
|
-
|
|
223
|
-
roomShape.pointerReactor(this.element);
|
|
224
|
-
roomShape.registerClick(() => {
|
|
225
|
-
this.emitter.dispatchEvent(new CustomEvent("roomClick", { detail: room }));
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
renderLink(room, targetId, dir) {
|
|
230
|
-
let exitKey = new Array(room.id, targetId).sort().join("#");
|
|
231
|
-
if (this.exitsRendered[exitKey] && room.doors[dirLongToShort(dir)] === undefined) {
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
this.linkLayer.activate();
|
|
235
|
-
let targetRoom = this.area.getRoomById(targetId);
|
|
236
|
-
let exitPoint = new paper.Point(this.getExitX(room.x, dir), this.getExitY(room.y, dir));
|
|
237
|
-
let path = new paper.Path();
|
|
238
|
-
let secondPoint;
|
|
239
|
-
if (targetRoom) {
|
|
240
|
-
let connectedDir = getKeyByValue(targetRoom.exits, room.id);
|
|
241
|
-
let isOneWay = connectedDir == undefined;
|
|
242
|
-
secondPoint = new paper.Point(this.getExitX(targetRoom.x, connectedDir), this.getExitY(targetRoom.y, connectedDir));
|
|
243
|
-
if (!isOneWay) {
|
|
244
|
-
path.moveTo(exitPoint);
|
|
245
|
-
path.lineTo(secondPoint);
|
|
246
|
-
path.strokeWidth = this.exitFactor;
|
|
247
|
-
path.strokeColor = this.settings.linesColor;
|
|
248
|
-
} else {
|
|
249
|
-
this.renderArrow(exitPoint, secondPoint, this.settings.linesColor, [], this.exitFactor, this.settings.linesColor, true);
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
secondPoint = new paper.Point(room.x + this.roomFactor / 2, room.y + this.roomFactor / 2);
|
|
253
|
-
let color = this.colors[this.reader.getRoomById(targetId).env];
|
|
254
|
-
if (color === undefined) {
|
|
255
|
-
color = [114, 1, 0];
|
|
256
|
-
}
|
|
257
|
-
path = this.renderArrow(exitPoint, secondPoint, new paper.Color(color[0] / 255, color[1] / 255, color[2] / 255), [], this.exitFactor);
|
|
258
|
-
path.rotate(180, exitPoint);
|
|
259
|
-
path.scale(2);
|
|
260
|
-
path.pointerReactor(this.element);
|
|
261
|
-
path.registerClick(() => this.emitter.dispatchEvent(new CustomEvent("areaArrowClick", { detail: targetId })));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (room.doors[dirLongToShort(dir)] !== undefined) {
|
|
265
|
-
this.renderDoors(exitPoint, secondPoint, room.doors[dirLongToShort(dir)]);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
this.exitsRendered[exitKey] = true;
|
|
269
|
-
room.exitsRenders.push(path);
|
|
270
|
-
if (targetRoom) {
|
|
271
|
-
targetRoom.exitsRenders = targetRoom.exitsRenders != undefined ? targetRoom.exitsRenders : [];
|
|
272
|
-
targetRoom.exitsRenders.push(path);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return path;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
renderSpecialLink(room, targetId, dir) {
|
|
279
|
-
this.linkLayer.activate();
|
|
280
|
-
|
|
281
|
-
let path;
|
|
282
|
-
let exitPoint = new paper.Point(room.x + this.roomFactor / 2, room.y + this.roomFactor / 2);
|
|
283
|
-
let targetRoom = this.area.getRoomById(targetId);
|
|
284
|
-
let secondPoint;
|
|
285
|
-
|
|
286
|
-
if (targetRoom && Object.entries(targetRoom.specialExits).filter(item => item[1] == room.id).filter(item => Object.keys(targetRoom.specialExits).indexOf(item[0] != -1)).length == 0) {
|
|
287
|
-
path = new paper.Path();
|
|
288
|
-
path.moveTo(exitPoint);
|
|
289
|
-
let connectedDir = getKeyByValue(targetRoom.exits, room.id);
|
|
290
|
-
secondPoint = new paper.Point(this.getExitX(targetRoom.x, connectedDir), this.getExitY(targetRoom.y, connectedDir));
|
|
291
|
-
path.lineTo(secondPoint);
|
|
292
|
-
path.strokeColor = this.settings.linesColor;
|
|
293
|
-
path.strokeWidth = this.exitFactor;
|
|
294
|
-
} else {
|
|
295
|
-
secondPoint = new paper.Point(room.x + this.roomFactor / 2, room.y + this.roomFactor / 2);
|
|
296
|
-
path = this.renderArrow(exitPoint, secondPoint, this.defualtColor, [], this.exitFactor);
|
|
297
|
-
path.strokeColor = this.settings.linesColor;
|
|
298
|
-
path.scale(1, exitPoint);
|
|
299
|
-
path.rotate(180, exitPoint);
|
|
300
|
-
path.registerClick(() => this.emitter.dispatchEvent(new CustomEvent("areaArrowClick", { detail: targetId })));
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
room.exitsRenders.push(path);
|
|
304
|
-
if (targetRoom) {
|
|
305
|
-
targetRoom.exitsRenders = targetRoom.exitsRenders ?? [];
|
|
306
|
-
targetRoom.exitsRenders.push(path);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return path;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
renderCustomLine(room, dir, targetId) {
|
|
313
|
-
if (room.customLines[dir].points !== undefined && room.customLines[dir].points.length === 0) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
this.linkLayer.activate();
|
|
318
|
-
|
|
319
|
-
let customLine = new paper.Group();
|
|
320
|
-
|
|
321
|
-
let path = new paper.Path();
|
|
322
|
-
let style = room.customLines[dir].attributes.style;
|
|
323
|
-
if (style === "dot line") {
|
|
324
|
-
path.dashArray = [0.05, 0.05];
|
|
325
|
-
path.dashOffset = 0.1;
|
|
326
|
-
} else if (style === "dash line") {
|
|
327
|
-
path.dashArray = [0.4, 0.2];
|
|
328
|
-
} else if (style === "solid line") {
|
|
329
|
-
} else {
|
|
330
|
-
console.log("Brak opisu stylu: " + style);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (room.customLines[dir].attributes.color !== undefined) {
|
|
334
|
-
let color = room.customLines[dir].attributes.color;
|
|
335
|
-
path.strokeColor = new paper.Color(color.r / 255, color.g / 255, color.b / 255);
|
|
336
|
-
} else {
|
|
337
|
-
path.strokeColor = this.defualtColor;
|
|
338
|
-
}
|
|
339
|
-
let lastPoint = new paper.Point(room.x + this.roomFactor / 2, room.y + this.roomFactor / 2);
|
|
340
|
-
path.moveTo(lastPoint);
|
|
341
|
-
|
|
342
|
-
if (room.customLines[dir].points !== undefined) {
|
|
343
|
-
let points = [];
|
|
344
|
-
|
|
345
|
-
room.customLines[dir].points.forEach((value) => points.push(value));
|
|
346
|
-
|
|
347
|
-
for (let point in points) {
|
|
348
|
-
let customPoint = points[point];
|
|
349
|
-
let pointCoords = new paper.Point(customPoint.x + this.roomFactor / 2, customPoint.y + this.roomFactor / 2);
|
|
350
|
-
lastPoint = new paper.Point(pointCoords);
|
|
351
|
-
path.lineTo(lastPoint);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
customLine.addChild(path);
|
|
356
|
-
|
|
357
|
-
if (room.customLines[dir].attributes.arrow && path.segments.length > 1) {
|
|
358
|
-
let arrow = this.renderArrow(
|
|
359
|
-
path.segments[path.segments.length - 2].point,
|
|
360
|
-
path.segments[path.segments.length - 1].point,
|
|
361
|
-
path.strokeColor,
|
|
362
|
-
path.dashArray,
|
|
363
|
-
this.exitFactor
|
|
364
|
-
);
|
|
365
|
-
customLine.addChild(arrow);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
path.strokeWidth = this.exitFactor;
|
|
369
|
-
path.orgStrokeColor = path.strokeColor;
|
|
370
|
-
|
|
371
|
-
let targetRoom = this.area.getRoomById(targetId);
|
|
372
|
-
if (!targetRoom) {
|
|
373
|
-
customLine.registerClick(() => this.emitter.dispatchEvent(new CustomEvent("areaArrowClick", { detail: targetId })));
|
|
374
|
-
customLine.pointerReactor(this.element);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
room.exitsRenders.push(customLine);
|
|
379
|
-
|
|
380
|
-
return customLine;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
renderArrow(lineStart, lineEnd, color, dashArray, strokeWidth, strokeColor, isOneWay) {
|
|
384
|
-
let arrowPoint = lineEnd;
|
|
385
|
-
let arrow = new paper.Path.RegularPolygon(arrowPoint, 3, this.roomDiagonal / 6);
|
|
386
|
-
arrow.position = arrow.position.add(arrow.bounds.topCenter.subtract(arrow.bounds.center));
|
|
387
|
-
arrow.rotate(lineEnd.subtract(lineStart).getAngle() + 90, lineEnd);
|
|
388
|
-
let tailLine = new paper.Path.Line(lineStart, arrow.bounds.center);
|
|
389
|
-
let path = new paper.Group([tailLine, arrow]);
|
|
390
|
-
path.closed = true;
|
|
391
|
-
arrow.fillColor = color;
|
|
392
|
-
arrow.strokeColor = color;
|
|
393
|
-
arrow.strokeWidth = this.exitFactor;
|
|
394
|
-
tailLine.fillColor = strokeColor ? strokeColor : color;
|
|
395
|
-
tailLine.strokeColor = strokeColor ? strokeColor : color;
|
|
396
|
-
tailLine.dashArray = dashArray;
|
|
397
|
-
tailLine.strokeWidth = this.exitFactor;
|
|
398
|
-
|
|
399
|
-
if (isOneWay) {
|
|
400
|
-
arrow.position = new paper.Point(lineEnd.x + (lineStart.x - lineEnd.x) / 2, lineEnd.y + (lineStart.y - lineEnd.y) / 2);
|
|
401
|
-
tailLine.dashArray = [0.1, 0.1];
|
|
402
|
-
path.fillColor = new paper.Color(1, 0, 0);
|
|
403
|
-
arrow.scale(1.5);
|
|
404
|
-
} else {
|
|
405
|
-
tailLine.strokeWidth = strokeWidth;
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
return path;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
renderStub(room, dir) {
|
|
412
|
-
this.linkLayer.activate();
|
|
413
|
-
let path;
|
|
414
|
-
if (this.innerExits.indexOf(dir) > -1) {
|
|
415
|
-
path = this.renderInnerExit(room, dir, true);
|
|
416
|
-
} else {
|
|
417
|
-
let startPoint = new paper.Point(room.x + this.roomFactor * 0.5, room.y + this.roomFactor * 0.5);
|
|
418
|
-
let exitPoint = new paper.Point(this.getExitX(room.x, dir), this.getExitY(room.y, dir));
|
|
419
|
-
path = new paper.Path();
|
|
420
|
-
path.moveTo(startPoint);
|
|
421
|
-
path.lineTo(exitPoint);
|
|
422
|
-
path.pivot = startPoint;
|
|
423
|
-
path.scale(2);
|
|
424
|
-
path.position = exitPoint;
|
|
425
|
-
path.strokeWidth = this.exitFactor;
|
|
426
|
-
path.strokeColor = this.settings.linesColor;
|
|
427
|
-
}
|
|
428
|
-
return path;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
renderInnerExit(room, direction, stub = false) {
|
|
432
|
-
this.labelsLayer.activate();
|
|
433
|
-
|
|
434
|
-
let group = new paper.Group();
|
|
435
|
-
|
|
436
|
-
if (direction === "down" || direction == "d") {
|
|
437
|
-
group.addChild(this.renderInnerTriangle(room, direction, stub));
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
if (direction === "up" || direction === "u") {
|
|
441
|
-
group.addChild(this.renderInnerTriangle(room, direction, stub));
|
|
442
|
-
group.rotate(180, room.render.bounds.center);
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
if (direction === "in" || direction === "i") {
|
|
446
|
-
let left = this.renderInnerTriangle(room, direction, stub);
|
|
447
|
-
left.rotate(90, room.render.bounds.center);
|
|
448
|
-
left.scale(0.4, room.render.bounds.center);
|
|
449
|
-
left.position.x -= 0.01;
|
|
450
|
-
let right = this.renderInnerTriangle(room, direction, stub);
|
|
451
|
-
right.scale(0.4, room.render.bounds.center);
|
|
452
|
-
right.rotate(270, room.render.bounds.center);
|
|
453
|
-
right.position.x += 0.01;
|
|
454
|
-
group.addChild(left);
|
|
455
|
-
group.addChild(right);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
if (direction === "out" || direction === "o") {
|
|
459
|
-
let left = this.renderInnerTriangle(room, direction, stub);
|
|
460
|
-
left.rotate(270, room.render.bounds.center);
|
|
461
|
-
left.scale(0.5, room.render.bounds.rightCenter);
|
|
462
|
-
left.rotate(180);
|
|
463
|
-
left.position.x -= 0.01;
|
|
464
|
-
let right = this.renderInnerTriangle(room, direction, stub);
|
|
465
|
-
right.rotate(90, room.render.bounds.center);
|
|
466
|
-
right.scale(0.5, room.render.bounds.leftCenter);
|
|
467
|
-
right.rotate(180);
|
|
468
|
-
right.position.x += 0.01;
|
|
469
|
-
group.addChild(left);
|
|
470
|
-
group.addChild(right);
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
if (this.settings.isRound) {
|
|
474
|
-
group.scale(0.8, 0.8, new paper.Point(room.render.bounds.center));
|
|
475
|
-
}
|
|
476
|
-
group.locked = true;
|
|
477
|
-
|
|
478
|
-
return group;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
renderInnerTriangle(room, direction, stub) {
|
|
482
|
-
let triangle = new paper.Path.RegularPolygon(
|
|
483
|
-
new paper.Point(room.render.bounds.bottomCenter).subtract(new paper.Point(0, 0.2 * this.roomFactor)),
|
|
484
|
-
3,
|
|
485
|
-
0.3 * this.roomFactor
|
|
486
|
-
);
|
|
487
|
-
triangle.scale(1.2, 0.75);
|
|
488
|
-
let baseColor = this.lightnessDependantColor(room);
|
|
489
|
-
triangle.strokeWidth = this.exitFactor;
|
|
490
|
-
if (!stub) {
|
|
491
|
-
triangle.fillColor = new paper.Color(baseColor, baseColor, baseColor, 0.75);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
triangle.strokeColor = new paper.Color(baseColor, baseColor, baseColor);
|
|
495
|
-
|
|
496
|
-
let doorType = room.doors[dirsShortToLong(direction)];
|
|
497
|
-
if (doorType !== undefined) {
|
|
498
|
-
switch (doorType) {
|
|
499
|
-
case 1:
|
|
500
|
-
triangle.strokeColor = Colors.OPEN_DOOR;
|
|
501
|
-
break;
|
|
502
|
-
case 2:
|
|
503
|
-
triangle.strokeColor = Colors.CLOSED_DOOR;
|
|
504
|
-
break;
|
|
505
|
-
default:
|
|
506
|
-
triangle.strokeColor = Colors.LOCKED_DOOR;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
triangle.bringToFront();
|
|
511
|
-
return triangle;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
renderChar(room) {
|
|
515
|
-
this.charsLayer.activate();
|
|
516
|
-
if (room.roomChar) {
|
|
517
|
-
let size = 0.85 * this.roomFactor / room.roomChar.length;
|
|
518
|
-
let x = this.pngRender ? room.render.position.x - 0.1 : room.render.position.x;
|
|
519
|
-
let text = new paper.PointText(x, room.render.position.y + size / 4);
|
|
520
|
-
if (!room.userData || room.userData["system.fallback_symbol_color"] === undefined) {
|
|
521
|
-
text.fillColor = this.lightnessDependantColor(room);
|
|
522
|
-
} else {
|
|
523
|
-
text.fillColor = room.userData["system.fallback_symbol_color"];
|
|
524
|
-
}
|
|
525
|
-
text.fontSize = size;
|
|
526
|
-
text.content = room.roomChar;
|
|
527
|
-
text.justification = "center";
|
|
528
|
-
text.locked = true;
|
|
529
|
-
text.scale(1, -1);
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
renderDoors(firstPoint, secondPoint, type) {
|
|
534
|
-
this.specialLinkLayer.activate();
|
|
535
|
-
let x = (firstPoint.x + secondPoint.x) / 2;
|
|
536
|
-
let y = (firstPoint.y + secondPoint.y) / 2;
|
|
537
|
-
let door = new paper.Path.Rectangle(x - 0.5, y - 0.5, 1, 1);
|
|
538
|
-
door.scale(this.roomFactor * 0.5, door.center);
|
|
539
|
-
switch (type) {
|
|
540
|
-
case 1:
|
|
541
|
-
door.strokeColor = Colors.OPEN_DOOR;
|
|
542
|
-
break;
|
|
543
|
-
case 2:
|
|
544
|
-
door.strokeColor = Colors.CLOSED_DOOR;
|
|
545
|
-
break;
|
|
546
|
-
default:
|
|
547
|
-
door.strokeColor = Colors.LOCKED_DOOR;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
door.strokeWidth = this.exitFactor;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
renderLabel(value) {
|
|
554
|
-
if (false && value.pixMap) {
|
|
555
|
-
//TODO Not really sure how to deal with pixMap labels here so they are ok both in .svg and browser
|
|
556
|
-
let label = new paper.Raster("data:image/png;base64," + value.pixMap);
|
|
557
|
-
label._size.width = value.Width;
|
|
558
|
-
label._size.height = value.Height;
|
|
559
|
-
label.position = new paper.Point(value.X + value.Width / 2, value.Y);
|
|
560
|
-
label.scale(this.roomFactor * 0.08, -this.roomFactor * 0.08);
|
|
561
|
-
} else {
|
|
562
|
-
let background = new paper.Path.Rectangle(new paper.Point(value.X, value.Y - value.Height), new paper.Size(value.Width, value.Height));
|
|
563
|
-
if (!this.settings.transparentLabels) {
|
|
564
|
-
background.fillColor = new paper.Color(value.BgColor.r / 255, value.BgColor.g / 255, value.BgColor.b / 255);
|
|
565
|
-
}
|
|
566
|
-
let text = new paper.PointText(background.bounds.center.add(0, 0.15 * 8));
|
|
567
|
-
text.fillColor = new paper.Color(value.FgColor.r / 255, value.FgColor.g / 255, value.FgColor.b / 255);
|
|
568
|
-
let ratio = Math.min(0.75, value.Width / (value.Text.length / 2));
|
|
569
|
-
text.fontSize = 4
|
|
570
|
-
text.content = value.Text;
|
|
571
|
-
text.fontFamily = this.settings.fontFamily;
|
|
572
|
-
text.justification = "center";
|
|
573
|
-
text.locked = true;
|
|
574
|
-
text.scale(ratio / 4, -ratio / 4);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
lightnessDependantColor(room) {
|
|
579
|
-
if (room.render.fillColor.lightness > 0.41) {
|
|
580
|
-
return 0.1;
|
|
581
|
-
} else {
|
|
582
|
-
return 0.9;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
getXMid(x) {
|
|
587
|
-
return x + this.roomFactor / 2;
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
getYMid(y) {
|
|
591
|
-
return y + this.roomFactor / 2;
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
getExitX(x, dir) {
|
|
595
|
-
if (this.settings.isRound) {
|
|
596
|
-
return x + 0.5 * this.roomFactor;
|
|
597
|
-
}
|
|
598
|
-
switch (dir) {
|
|
599
|
-
case "west":
|
|
600
|
-
case "w":
|
|
601
|
-
case "northwest":
|
|
602
|
-
case "nw":
|
|
603
|
-
case "southwest":
|
|
604
|
-
case "sw":
|
|
605
|
-
return x;
|
|
606
|
-
case "east":
|
|
607
|
-
case "e":
|
|
608
|
-
case "northeast":
|
|
609
|
-
case "ne":
|
|
610
|
-
case "southeast":
|
|
611
|
-
case "se":
|
|
612
|
-
return x + this.roomFactor;
|
|
613
|
-
default:
|
|
614
|
-
return x + 0.5 * this.roomFactor;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
getExitY(y, dir) {
|
|
619
|
-
if (this.settings.isRound) {
|
|
620
|
-
return y + 0.5 * this.roomFactor;
|
|
621
|
-
}
|
|
622
|
-
switch (dir) {
|
|
623
|
-
case "north":
|
|
624
|
-
case "n":
|
|
625
|
-
case "northwest":
|
|
626
|
-
case "nw":
|
|
627
|
-
case "northeast":
|
|
628
|
-
case "ne":
|
|
629
|
-
return y + this.roomFactor;
|
|
630
|
-
case "south":
|
|
631
|
-
case "s":
|
|
632
|
-
case "southwest":
|
|
633
|
-
case "sw":
|
|
634
|
-
case "southeast":
|
|
635
|
-
case "se":
|
|
636
|
-
return y;
|
|
637
|
-
default:
|
|
638
|
-
return y + 0.5 * this.roomFactor;
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
getRealPoint(x, y) {
|
|
643
|
-
return this.matrix.transform(new paper.Point(x, y));
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
getBounds() {
|
|
647
|
-
return this.backgroundLayer.getBounds();
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
renderPosition(id, color) {
|
|
651
|
-
this.clearPosition();
|
|
652
|
-
this.overlayLayer.activate();
|
|
653
|
-
let room = this.area.getRoomById(id);
|
|
654
|
-
let circle = new paper.Shape.Circle(new paper.Point(room.x + this.roomFactor * 0.5, room.y + this.roomFactor * 0.5), this.roomDiagonal * 0.6);
|
|
655
|
-
circle.fillColor = new paper.Color(0.5, 0.1, 0.1, 0.2);
|
|
656
|
-
circle.strokeWidth = this.exitFactor * 5;
|
|
657
|
-
circle.shadowColor = new paper.Color(1, 1, 1);
|
|
658
|
-
circle.shadowBlur = 12;
|
|
659
|
-
if (color === undefined) {
|
|
660
|
-
color = [0, 0.9, 0.7];
|
|
661
|
-
}
|
|
662
|
-
circle.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
663
|
-
circle.dashArray = [0.05, 0.05];
|
|
664
|
-
this.position = circle;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
clearPosition() {
|
|
668
|
-
if (this.position !== undefined) {
|
|
669
|
-
this.position.remove();
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
renderSelection(id, color) {
|
|
674
|
-
this.clearSelection();
|
|
675
|
-
this.overlayLayer.activate();
|
|
676
|
-
let room = this.area.getRoomById(id);
|
|
677
|
-
let selection = new paper.Path.Rectangle(new paper.Point(room.x - 0.05, room.y - 0.05), new paper.Size(this.roomFactor + 0.1, this.roomFactor + 0.1));
|
|
678
|
-
selection.fillColor = new paper.Color(1, 1, 1, 0);
|
|
679
|
-
selection.strokeWidth = this.exitFactor;
|
|
680
|
-
if (color === undefined) {
|
|
681
|
-
color = [0, 0.9, 0.7];
|
|
682
|
-
}
|
|
683
|
-
selection.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
684
|
-
this.selection = selection;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
clearSelection() {
|
|
688
|
-
if (this.selection !== undefined) {
|
|
689
|
-
this.selection.remove();
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
renderHighlight(id, color) {
|
|
694
|
-
this.overlayLayer.activate();
|
|
695
|
-
let room = this.area.getRoomById(id);
|
|
696
|
-
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);
|
|
697
|
-
highlight.fillColor = new paper.Color(0.5, 0.1, 0.1, 0.2);
|
|
698
|
-
highlight.strokeWidth = this.exitFactor * 4;
|
|
699
|
-
highlight.shadowColor = room.render.fillColor;
|
|
700
|
-
highlight.shadowBlur = 12;
|
|
701
|
-
if (color === undefined) {
|
|
702
|
-
color = [0.4, 0.9, 0.3];
|
|
703
|
-
}
|
|
704
|
-
highlight.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
705
|
-
highlight.dashArray = [0.1, 0.1];
|
|
706
|
-
highlight.locked = true;
|
|
707
|
-
this.highlights.addChild(highlight)
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
clearHighlight() {
|
|
711
|
-
this.highlights.removeChildren()
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
renderPath(locations, color) {
|
|
715
|
-
this.overlayLayer.activate();
|
|
716
|
-
let group = new paper.Group();
|
|
717
|
-
locations.forEach(id => {
|
|
718
|
-
let room = this.area.getRoomById(id);
|
|
719
|
-
if (!room || room.z !== this.area.zIndex) {
|
|
720
|
-
return
|
|
721
|
-
}
|
|
722
|
-
let startPoint = new paper.Point(room.x + this.roomFactor * 0.5, room.y + this.roomFactor * 0.5)
|
|
723
|
-
let exits = Object.values(room.exits).concat(Object.values(room.specialExits))
|
|
724
|
-
exits.forEach(exitRoomId => {
|
|
725
|
-
if (locations.indexOf(exitRoomId) > -1) {
|
|
726
|
-
let exitRoom = this.area.getRoomById(exitRoomId);
|
|
727
|
-
if (!exitRoom || exitRoom.z !== this.area.zIndex) {
|
|
728
|
-
return
|
|
729
|
-
}
|
|
730
|
-
let endPoint = new paper.Point(exitRoom.x + this.roomFactor * 0.5, exitRoom.y + this.roomFactor * 0.5)
|
|
731
|
-
let line = new paper.Path.Line(startPoint, endPoint)
|
|
732
|
-
line.strokeWidth = this.exitFactor * 4;
|
|
733
|
-
if (color === undefined) {
|
|
734
|
-
color = [0.4, 0.9, 0.3];
|
|
735
|
-
}
|
|
736
|
-
this.path.push(line);
|
|
737
|
-
group.addChild(line);
|
|
738
|
-
}
|
|
739
|
-
})
|
|
740
|
-
})
|
|
741
|
-
group.strokeColor = new paper.Color(color[0], color[1], color[2]);
|
|
742
|
-
group.locked = true;
|
|
743
|
-
return group;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
clearPath() {
|
|
747
|
-
this.path.forEach((element) => element.remove());
|
|
748
|
-
this.path = [];
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
clear() {
|
|
753
|
-
this.paper.clear();
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
exportSvg(roomId, padding) {
|
|
757
|
-
let bounds = 'content';
|
|
758
|
-
if (roomId !== undefined) {
|
|
759
|
-
let room = this.reader.roomIndex[roomId]
|
|
760
|
-
if (room === undefined) {
|
|
761
|
-
throw new Error(`Room ${roomId} not found.`)
|
|
762
|
-
}
|
|
763
|
-
bounds = new paper.Rectangle(this.getRealPoint(new paper.Point(room.x, room.y)).subtract(padding * this.scale), padding * 2 * this.scale, padding * 2 * this.scale);
|
|
764
|
-
}
|
|
765
|
-
return this.paper.project.exportSVG({ asString: true, bounds: bounds });
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
module.exports = {
|
|
770
|
-
Renderer: Renderer,
|
|
771
|
-
Settings: Settings,
|
|
772
|
-
};
|
|
773
|
-
|
|
774
|
-
function getKeyByValue(obj, val) {
|
|
775
|
-
for (let k in obj) {
|
|
776
|
-
if (obj.hasOwnProperty(k) && obj[k] === val) {
|
|
777
|
-
return k;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
let dirs = {
|
|
783
|
-
north: "n",
|
|
784
|
-
south: "s",
|
|
785
|
-
east: "e",
|
|
786
|
-
west: "w",
|
|
787
|
-
northeast: "ne",
|
|
788
|
-
northwest: "nw",
|
|
789
|
-
southeast: "se",
|
|
790
|
-
southwest: "sw",
|
|
791
|
-
up: "u",
|
|
792
|
-
down: "d",
|
|
793
|
-
in: "i",
|
|
794
|
-
out: "o",
|
|
795
|
-
};
|
|
796
|
-
|
|
797
|
-
let dirNumbers = {
|
|
798
|
-
1: "n",
|
|
799
|
-
2: "ne",
|
|
800
|
-
3: "nw",
|
|
801
|
-
4: "e",
|
|
802
|
-
5: "w",
|
|
803
|
-
6: "s",
|
|
804
|
-
7: "se",
|
|
805
|
-
8: "sw",
|
|
806
|
-
9: "u",
|
|
807
|
-
10: "d",
|
|
808
|
-
11: "i",
|
|
809
|
-
12: "o",
|
|
810
|
-
};
|
|
811
|
-
|
|
812
|
-
function dirsShortToLong(dir) {
|
|
813
|
-
let result = getKeyByValue(dirs, dir);
|
|
814
|
-
return result !== undefined ? result : dir;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
function dirLongToShort(dir) {
|
|
818
|
-
return dirs[dir] !== undefined ? dirs[dir] : dir;
|
|
819
|
-
}
|