@textadventures/quest-viva-wasmplayer 6.0.0-beta.59 → 6.0.0-beta.61
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/WasmPlayer.runtimeconfig.json +1 -1
- package/_framework/Common.wasm +0 -0
- package/_framework/Engine.wasm +0 -0
- package/_framework/Legacy.wasm +0 -0
- package/_framework/Microsoft.CSharp.wasm +0 -0
- package/_framework/Microsoft.VisualBasic.Core.wasm +0 -0
- package/_framework/Microsoft.VisualBasic.wasm +0 -0
- package/_framework/Microsoft.Win32.Primitives.wasm +0 -0
- package/_framework/Microsoft.Win32.Registry.wasm +0 -0
- package/_framework/PlayerCore.wasm +0 -0
- package/_framework/System.AppContext.wasm +0 -0
- package/_framework/System.Buffers.wasm +0 -0
- package/_framework/System.Collections.Concurrent.wasm +0 -0
- package/_framework/System.Collections.Immutable.wasm +0 -0
- package/_framework/System.Collections.NonGeneric.wasm +0 -0
- package/_framework/System.Collections.Specialized.wasm +0 -0
- package/_framework/System.Collections.wasm +0 -0
- package/_framework/System.ComponentModel.Annotations.wasm +0 -0
- package/_framework/System.ComponentModel.DataAnnotations.wasm +0 -0
- package/_framework/System.ComponentModel.EventBasedAsync.wasm +0 -0
- package/_framework/System.ComponentModel.Primitives.wasm +0 -0
- package/_framework/System.ComponentModel.TypeConverter.wasm +0 -0
- package/_framework/System.ComponentModel.wasm +0 -0
- package/_framework/System.Configuration.wasm +0 -0
- package/_framework/System.Console.wasm +0 -0
- package/_framework/System.Core.wasm +0 -0
- package/_framework/System.Data.Common.wasm +0 -0
- package/_framework/System.Data.DataSetExtensions.wasm +0 -0
- package/_framework/System.Data.wasm +0 -0
- package/_framework/System.Diagnostics.Contracts.wasm +0 -0
- package/_framework/System.Diagnostics.Debug.wasm +0 -0
- package/_framework/System.Diagnostics.DiagnosticSource.wasm +0 -0
- package/_framework/System.Diagnostics.FileVersionInfo.wasm +0 -0
- package/_framework/System.Diagnostics.Process.wasm +0 -0
- package/_framework/System.Diagnostics.StackTrace.wasm +0 -0
- package/_framework/System.Diagnostics.TextWriterTraceListener.wasm +0 -0
- package/_framework/System.Diagnostics.Tools.wasm +0 -0
- package/_framework/System.Diagnostics.TraceSource.wasm +0 -0
- package/_framework/System.Diagnostics.Tracing.wasm +0 -0
- package/_framework/System.Drawing.Primitives.wasm +0 -0
- package/_framework/System.Drawing.wasm +0 -0
- package/_framework/System.Dynamic.Runtime.wasm +0 -0
- package/_framework/System.Formats.Asn1.wasm +0 -0
- package/_framework/System.Formats.Tar.wasm +0 -0
- package/_framework/System.Globalization.Calendars.wasm +0 -0
- package/_framework/System.Globalization.Extensions.wasm +0 -0
- package/_framework/System.Globalization.wasm +0 -0
- package/_framework/System.IO.Compression.Brotli.wasm +0 -0
- package/_framework/System.IO.Compression.FileSystem.wasm +0 -0
- package/_framework/System.IO.Compression.ZipFile.wasm +0 -0
- package/_framework/System.IO.Compression.wasm +0 -0
- package/_framework/System.IO.FileSystem.AccessControl.wasm +0 -0
- package/_framework/System.IO.FileSystem.DriveInfo.wasm +0 -0
- package/_framework/System.IO.FileSystem.Primitives.wasm +0 -0
- package/_framework/System.IO.FileSystem.Watcher.wasm +0 -0
- package/_framework/System.IO.FileSystem.wasm +0 -0
- package/_framework/System.IO.IsolatedStorage.wasm +0 -0
- package/_framework/System.IO.MemoryMappedFiles.wasm +0 -0
- package/_framework/System.IO.Pipelines.wasm +0 -0
- package/_framework/System.IO.Pipes.AccessControl.wasm +0 -0
- package/_framework/System.IO.Pipes.wasm +0 -0
- package/_framework/System.IO.UnmanagedMemoryStream.wasm +0 -0
- package/_framework/System.IO.wasm +0 -0
- package/_framework/System.Linq.AsyncEnumerable.wasm +0 -0
- package/_framework/System.Linq.Expressions.wasm +0 -0
- package/_framework/System.Linq.Parallel.wasm +0 -0
- package/_framework/System.Linq.Queryable.wasm +0 -0
- package/_framework/System.Linq.wasm +0 -0
- package/_framework/System.Memory.wasm +0 -0
- package/_framework/System.Net.Http.Json.wasm +0 -0
- package/_framework/System.Net.Http.wasm +0 -0
- package/_framework/System.Net.HttpListener.wasm +0 -0
- package/_framework/System.Net.Mail.wasm +0 -0
- package/_framework/System.Net.NameResolution.wasm +0 -0
- package/_framework/System.Net.NetworkInformation.wasm +0 -0
- package/_framework/System.Net.Ping.wasm +0 -0
- package/_framework/System.Net.Primitives.wasm +0 -0
- package/_framework/System.Net.Quic.wasm +0 -0
- package/_framework/System.Net.Requests.wasm +0 -0
- package/_framework/System.Net.Security.wasm +0 -0
- package/_framework/System.Net.ServerSentEvents.wasm +0 -0
- package/_framework/System.Net.ServicePoint.wasm +0 -0
- package/_framework/System.Net.Sockets.wasm +0 -0
- package/_framework/System.Net.WebClient.wasm +0 -0
- package/_framework/System.Net.WebHeaderCollection.wasm +0 -0
- package/_framework/System.Net.WebProxy.wasm +0 -0
- package/_framework/System.Net.WebSockets.Client.wasm +0 -0
- package/_framework/System.Net.WebSockets.wasm +0 -0
- package/_framework/System.Net.wasm +0 -0
- package/_framework/System.Numerics.Vectors.wasm +0 -0
- package/_framework/System.Numerics.wasm +0 -0
- package/_framework/System.ObjectModel.wasm +0 -0
- package/_framework/System.Private.CoreLib.wasm +0 -0
- package/_framework/System.Private.DataContractSerialization.wasm +0 -0
- package/_framework/System.Private.Uri.wasm +0 -0
- package/_framework/System.Private.Xml.Linq.wasm +0 -0
- package/_framework/System.Private.Xml.wasm +0 -0
- package/_framework/System.Reflection.DispatchProxy.wasm +0 -0
- package/_framework/System.Reflection.Emit.ILGeneration.wasm +0 -0
- package/_framework/System.Reflection.Emit.Lightweight.wasm +0 -0
- package/_framework/System.Reflection.Emit.wasm +0 -0
- package/_framework/System.Reflection.Extensions.wasm +0 -0
- package/_framework/System.Reflection.Metadata.wasm +0 -0
- package/_framework/System.Reflection.Primitives.wasm +0 -0
- package/_framework/System.Reflection.TypeExtensions.wasm +0 -0
- package/_framework/System.Reflection.wasm +0 -0
- package/_framework/System.Resources.Reader.wasm +0 -0
- package/_framework/System.Resources.ResourceManager.wasm +0 -0
- package/_framework/System.Resources.Writer.wasm +0 -0
- package/_framework/System.Runtime.CompilerServices.Unsafe.wasm +0 -0
- package/_framework/System.Runtime.CompilerServices.VisualC.wasm +0 -0
- package/_framework/System.Runtime.Extensions.wasm +0 -0
- package/_framework/System.Runtime.Handles.wasm +0 -0
- package/_framework/System.Runtime.InteropServices.JavaScript.wasm +0 -0
- package/_framework/System.Runtime.InteropServices.RuntimeInformation.wasm +0 -0
- package/_framework/System.Runtime.InteropServices.wasm +0 -0
- package/_framework/System.Runtime.Intrinsics.wasm +0 -0
- package/_framework/System.Runtime.Loader.wasm +0 -0
- package/_framework/System.Runtime.Numerics.wasm +0 -0
- package/_framework/System.Runtime.Serialization.Formatters.wasm +0 -0
- package/_framework/System.Runtime.Serialization.Json.wasm +0 -0
- package/_framework/System.Runtime.Serialization.Primitives.wasm +0 -0
- package/_framework/System.Runtime.Serialization.Xml.wasm +0 -0
- package/_framework/System.Runtime.Serialization.wasm +0 -0
- package/_framework/System.Runtime.wasm +0 -0
- package/_framework/System.Security.AccessControl.wasm +0 -0
- package/_framework/System.Security.Claims.wasm +0 -0
- package/_framework/System.Security.Cryptography.Algorithms.wasm +0 -0
- package/_framework/System.Security.Cryptography.Cng.wasm +0 -0
- package/_framework/System.Security.Cryptography.Csp.wasm +0 -0
- package/_framework/System.Security.Cryptography.Encoding.wasm +0 -0
- package/_framework/System.Security.Cryptography.OpenSsl.wasm +0 -0
- package/_framework/System.Security.Cryptography.Primitives.wasm +0 -0
- package/_framework/System.Security.Cryptography.X509Certificates.wasm +0 -0
- package/_framework/System.Security.Cryptography.wasm +0 -0
- package/_framework/System.Security.Principal.Windows.wasm +0 -0
- package/_framework/System.Security.Principal.wasm +0 -0
- package/_framework/System.Security.SecureString.wasm +0 -0
- package/_framework/System.Security.wasm +0 -0
- package/_framework/System.ServiceModel.Web.wasm +0 -0
- package/_framework/System.ServiceProcess.wasm +0 -0
- package/_framework/System.Text.Encoding.CodePages.wasm +0 -0
- package/_framework/System.Text.Encoding.Extensions.wasm +0 -0
- package/_framework/System.Text.Encoding.wasm +0 -0
- package/_framework/System.Text.Encodings.Web.wasm +0 -0
- package/_framework/System.Text.Json.wasm +0 -0
- package/_framework/System.Text.RegularExpressions.wasm +0 -0
- package/_framework/System.Threading.AccessControl.wasm +0 -0
- package/_framework/System.Threading.Channels.wasm +0 -0
- package/_framework/System.Threading.Overlapped.wasm +0 -0
- package/_framework/System.Threading.Tasks.Dataflow.wasm +0 -0
- package/_framework/System.Threading.Tasks.Extensions.wasm +0 -0
- package/_framework/System.Threading.Tasks.Parallel.wasm +0 -0
- package/_framework/System.Threading.Tasks.wasm +0 -0
- package/_framework/System.Threading.Thread.wasm +0 -0
- package/_framework/System.Threading.ThreadPool.wasm +0 -0
- package/_framework/System.Threading.Timer.wasm +0 -0
- package/_framework/System.Threading.wasm +0 -0
- package/_framework/System.Transactions.Local.wasm +0 -0
- package/_framework/System.Transactions.wasm +0 -0
- package/_framework/System.ValueTuple.wasm +0 -0
- package/_framework/System.Web.HttpUtility.wasm +0 -0
- package/_framework/System.Web.wasm +0 -0
- package/_framework/System.Windows.wasm +0 -0
- package/_framework/System.Xml.Linq.wasm +0 -0
- package/_framework/System.Xml.ReaderWriter.wasm +0 -0
- package/_framework/System.Xml.Serialization.wasm +0 -0
- package/_framework/System.Xml.XDocument.wasm +0 -0
- package/_framework/System.Xml.XPath.XDocument.wasm +0 -0
- package/_framework/System.Xml.XPath.wasm +0 -0
- package/_framework/System.Xml.XmlDocument.wasm +0 -0
- package/_framework/System.Xml.XmlSerializer.wasm +0 -0
- package/_framework/System.Xml.wasm +0 -0
- package/_framework/System.wasm +0 -0
- package/_framework/WasmPlayer.wasm +0 -0
- package/_framework/WindowsBase.wasm +0 -0
- package/_framework/dotnet.boot.js +179 -179
- package/_framework/dotnet.js +1 -1
- package/_framework/dotnet.native.js +3 -3
- package/_framework/dotnet.native.wasm +0 -0
- package/_framework/dotnet.runtime.js +1 -1
- package/_framework/mscorlib.wasm +0 -0
- package/_framework/netstandard.wasm +0 -0
- package/export-manifest.json +1 -0
- package/grid.js +446 -446
- package/index.html +15 -15
- package/lib/jquery.multi-open-accordion-1.5.3.js +261 -261
- package/package.json +1 -1
- package/playercore.css +505 -505
- package/playercore.htm +212 -212
- package/playercore.js +2973 -2962
package/grid.js
CHANGED
|
@@ -1,446 +1,446 @@
|
|
|
1
|
-
var scale, gridX, gridY, player,
|
|
2
|
-
playerVector, playerDestination,
|
|
3
|
-
offsetVector, offsetDestination,
|
|
4
|
-
allPaths = [],
|
|
5
|
-
customLayerPaths = [],
|
|
6
|
-
customLayerObjects = {},
|
|
7
|
-
customLayerSvg = {},
|
|
8
|
-
customLayerImages = {},
|
|
9
|
-
layers = [],
|
|
10
|
-
maxLayer = 7,
|
|
11
|
-
currentLayer = 0,
|
|
12
|
-
offset = new Point(0, 0),
|
|
13
|
-
symbols = {},
|
|
14
|
-
newShapePoints = [];
|
|
15
|
-
|
|
16
|
-
for (var i = -maxLayer; i <= maxLayer; i++) {
|
|
17
|
-
var layer = new Layer();
|
|
18
|
-
layers.push(project.activeLayer);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
var customLayer = new Layer(),
|
|
22
|
-
customLayerOffset = new Point(0, 0);
|
|
23
|
-
|
|
24
|
-
customLayer.visible = false;
|
|
25
|
-
|
|
26
|
-
function activateLayer(index) {
|
|
27
|
-
showCustomLayer(false);
|
|
28
|
-
layers[getLayerIndex(index)].activate();
|
|
29
|
-
layers[getLayerIndex(index)].opacity = 1;
|
|
30
|
-
if (currentLayer != index) {
|
|
31
|
-
layers[getLayerIndex(currentLayer)].opacity = 0.2;
|
|
32
|
-
currentLayer = index;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getLayerIndex(index) {
|
|
37
|
-
if (index < -maxLayer || index > maxLayer) {
|
|
38
|
-
alert("Layer out of bounds. Current layer range: -" + maxLayer + " to " + maxLayer);
|
|
39
|
-
}
|
|
40
|
-
// layers array represents z-indexes from -maxLayer to maxLayer
|
|
41
|
-
return index + maxLayer;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
activateLayer(currentLayer);
|
|
45
|
-
|
|
46
|
-
gridApi.setScale = function (newScale) {
|
|
47
|
-
scale = newScale;
|
|
48
|
-
gridX = new Point(scale, 0);
|
|
49
|
-
gridY = new Point(0, scale);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
gridApi.setZoom = function (zoom) {
|
|
53
|
-
paper.view.zoom = zoom;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
gridApi.zoomIn = function (amount) {
|
|
57
|
-
zoom = paper.view.zoom * (Math.pow(1.1, amount));
|
|
58
|
-
if (zoom > 0.0001) {
|
|
59
|
-
paper.view.zoom = zoom;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
function onMouseDrag(event) {
|
|
64
|
-
updateOffset(event.delta);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
function onMouseUp(event) {
|
|
69
|
-
if (_respondToGridClicks) {
|
|
70
|
-
var x = getGridSquareX(event.point);
|
|
71
|
-
var y = getGridSquareY(event.point);
|
|
72
|
-
ASLEvent("JS_GridSquareClick", x + ";" + y);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function updateOffset(delta) {
|
|
77
|
-
setOffset(getOffset() + delta);
|
|
78
|
-
var paths;
|
|
79
|
-
if (project.activeLayer == customLayer) {
|
|
80
|
-
paths = customLayerPaths;
|
|
81
|
-
} else {
|
|
82
|
-
paths = allPaths;
|
|
83
|
-
}
|
|
84
|
-
for (var i = 0; i < paths.length; i++) {
|
|
85
|
-
paths[i].position += delta;
|
|
86
|
-
}
|
|
87
|
-
if (playerDestination && project.activeLayer != customLayer) {
|
|
88
|
-
playerDestination += delta;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function getOffset() {
|
|
93
|
-
if (project.activeLayer == customLayer) {
|
|
94
|
-
return customLayerOffset;
|
|
95
|
-
}
|
|
96
|
-
return offset;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function setOffset(value) {
|
|
100
|
-
if (project.activeLayer == customLayer) {
|
|
101
|
-
customLayerOffset = value;
|
|
102
|
-
} else {
|
|
103
|
-
offset = value;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function onFrame(event) {
|
|
108
|
-
if (playerVector) {
|
|
109
|
-
var distance = player.position - playerDestination;
|
|
110
|
-
if (distance.length > playerVector.length) {
|
|
111
|
-
player.position += playerVector;
|
|
112
|
-
} else {
|
|
113
|
-
player.position = playerDestination;
|
|
114
|
-
playerVector = null;
|
|
115
|
-
playerDestination = null;
|
|
116
|
-
|
|
117
|
-
var playerPositionAbsolute = player.position - offset;
|
|
118
|
-
offsetDestination = paper.view.center - playerPositionAbsolute;
|
|
119
|
-
|
|
120
|
-
offsetVector = (offsetDestination - offset) / 10;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
if (offsetVector) {
|
|
124
|
-
var distance = offset - offsetDestination;
|
|
125
|
-
if (distance.length > offsetVector.length) {
|
|
126
|
-
updateOffset(offsetVector);
|
|
127
|
-
} else {
|
|
128
|
-
updateOffset(offsetDestination - offset);
|
|
129
|
-
offsetVector = null;
|
|
130
|
-
offsetDestination = null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
gridApi.drawGrid = function (minX, minY, maxX, maxY, border) {
|
|
136
|
-
|
|
137
|
-
function gridLine(start, end) {
|
|
138
|
-
var path = new Path();
|
|
139
|
-
path.strokeColor = border;
|
|
140
|
-
path.add(start, end);
|
|
141
|
-
addPathToCurrentLayerList(path);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// draw the vertical lines
|
|
145
|
-
for (var x = minX; x <= maxX; x++) {
|
|
146
|
-
var start = gridPoint(x, minY);
|
|
147
|
-
var end = gridPoint(x, maxY);
|
|
148
|
-
gridLine(start, end);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// draw the horizontal lines
|
|
152
|
-
for (var y = minY; y <= maxY; y++) {
|
|
153
|
-
var start = gridPoint(minX, y);
|
|
154
|
-
var end = gridPoint(maxX, y);
|
|
155
|
-
gridLine(start, end);
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
function gridPoint(x, y) {
|
|
160
|
-
return (gridX * x) + (gridY * y) + getOffset();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function getGridSquareX(point) {
|
|
164
|
-
return Math.floor(((point - getOffset()) / gridX).x);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
function getGridSquareY(point) {
|
|
168
|
-
return Math.floor(((point - getOffset()) / gridY).y);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function gridPointNudge(x, y, nudgeX, nudgeY) {
|
|
172
|
-
var result = gridPoint(x, y);
|
|
173
|
-
result.x += nudgeX;
|
|
174
|
-
result.y += nudgeY;
|
|
175
|
-
return result;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
var firstBox = true;
|
|
179
|
-
|
|
180
|
-
gridApi.drawBox = function (x, y, z, width, height, border, borderWidth, fill, sides) {
|
|
181
|
-
activateLayer(z);
|
|
182
|
-
// if this is the very first room, centre the canvas by updating the offset
|
|
183
|
-
if (firstBox) {
|
|
184
|
-
var centrePoint = gridPoint(x + width / 2, y + height / 2);
|
|
185
|
-
var offsetX = paper.view.center.x - centrePoint.x;
|
|
186
|
-
var offsetY = paper.view.center.y - centrePoint.y;
|
|
187
|
-
updateOffset(new Point(offsetX, offsetY));
|
|
188
|
-
firstBox = false;
|
|
189
|
-
}
|
|
190
|
-
var path = null;
|
|
191
|
-
var points = [gridPoint(x, y), gridPoint(x + width, y), gridPoint(x + width, y + height), gridPoint(x, y + height)];
|
|
192
|
-
// sides is encoded with bits to represent NESW
|
|
193
|
-
var draw = [sides & 8, sides & 4, sides & 2, sides & 1];
|
|
194
|
-
for (var i = 0; i < 4; i++) {
|
|
195
|
-
var next = (i + 1) % 4;
|
|
196
|
-
if (draw[i]) {
|
|
197
|
-
if (path == null) {
|
|
198
|
-
path = new Path();
|
|
199
|
-
allPaths.push(path);
|
|
200
|
-
if (borderWidth > 0) {
|
|
201
|
-
path.strokeColor = border;
|
|
202
|
-
path.strokeWidth = borderWidth;
|
|
203
|
-
}
|
|
204
|
-
path.add(points[i]);
|
|
205
|
-
}
|
|
206
|
-
path.add(points[next]);
|
|
207
|
-
} else {
|
|
208
|
-
path = null;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
var fillPath;
|
|
212
|
-
if (sides == 15) {
|
|
213
|
-
fillPath = path;
|
|
214
|
-
} else {
|
|
215
|
-
fillPath = new Path();
|
|
216
|
-
fillPath.add(points[0], points[1], points[2], points[3]);
|
|
217
|
-
allPaths.push(fillPath);
|
|
218
|
-
}
|
|
219
|
-
fillPath.fillColor = fill;
|
|
220
|
-
fillPath.closed = true;
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
gridApi.drawLine = function (x1, y1, x2, y2, border, borderWidth) {
|
|
224
|
-
var path = new Path;
|
|
225
|
-
path.strokeColor = border;
|
|
226
|
-
path.strokeWidth = borderWidth;
|
|
227
|
-
path.add(gridPoint(x1, y1));
|
|
228
|
-
path.add(gridPoint(x2, y2));
|
|
229
|
-
addPathToCurrentLayerList(path);
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
gridApi.drawArrow = function (id, x1, y1, x2, y2, border, borderWidth) {
|
|
233
|
-
clearExistingObject(id);
|
|
234
|
-
|
|
235
|
-
var linePath = new Path;
|
|
236
|
-
var start = gridPoint(x1, y1);
|
|
237
|
-
var end = gridPoint(x2, y2);
|
|
238
|
-
linePath.strokeColor = border;
|
|
239
|
-
linePath.strokeWidth = borderWidth;
|
|
240
|
-
linePath.add(start);
|
|
241
|
-
linePath.add(end);
|
|
242
|
-
addPathToCurrentLayerList(linePath);
|
|
243
|
-
|
|
244
|
-
var vector = end - start;
|
|
245
|
-
var arrowVector = vector.normalize(10);
|
|
246
|
-
var arrowheadPath = new Path([
|
|
247
|
-
end + arrowVector.rotate(150),
|
|
248
|
-
end,
|
|
249
|
-
end + arrowVector.rotate(-150)
|
|
250
|
-
]);
|
|
251
|
-
arrowheadPath.strokeColor = border;
|
|
252
|
-
arrowheadPath.strokeWidth = borderWidth;
|
|
253
|
-
addPathToCurrentLayerList(arrowheadPath);
|
|
254
|
-
|
|
255
|
-
customLayerObjects[id] = [linePath, arrowheadPath];
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
function addPathToCurrentLayerList(path) {
|
|
259
|
-
if (project.activeLayer == customLayer) {
|
|
260
|
-
customLayerPaths.push(path);
|
|
261
|
-
} else {
|
|
262
|
-
allPaths.push(path);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
gridApi.drawPlayer = function (x, y, z, radius, border, borderWidth, fill) {
|
|
267
|
-
activateLayer(z);
|
|
268
|
-
if (!player) {
|
|
269
|
-
player = new Path.Circle(gridPoint(x, y), radius);
|
|
270
|
-
player.strokeColor = border;
|
|
271
|
-
player.strokeWidth = borderWidth;
|
|
272
|
-
player.fillColor = fill;
|
|
273
|
-
player.fillColor = fill;
|
|
274
|
-
allPaths.push(player);
|
|
275
|
-
|
|
276
|
-
var playerPositionAbsolute = player.position - offset;
|
|
277
|
-
var offsetDestinationX = paper.view.center.x - playerPositionAbsolute.x;
|
|
278
|
-
var offsetDestinationY = paper.view.center.y - playerPositionAbsolute.y;
|
|
279
|
-
|
|
280
|
-
offsetDestination = new Point(offsetDestinationX, offsetDestinationY);
|
|
281
|
-
offsetVector = (offsetDestination - offset);
|
|
282
|
-
} else {
|
|
283
|
-
playerDestination = gridPoint(x, y);
|
|
284
|
-
playerVector = (playerDestination - player.position) / 10;
|
|
285
|
-
// move player to the end of the activeLayer so it gets drawn on top
|
|
286
|
-
project.activeLayer.addChild(player);
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
gridApi.drawLabel = function (x, y, z, text, col) {
|
|
292
|
-
if (col === undefined) col = "black";
|
|
293
|
-
activateLayer(z);
|
|
294
|
-
var pointText = new PointText(gridPoint(x, y));
|
|
295
|
-
pointText.justification = "center";
|
|
296
|
-
pointText.fillColor = col;
|
|
297
|
-
pointText.content = text;
|
|
298
|
-
allPaths.push(pointText);
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
function showCustomLayer(visible) {
|
|
302
|
-
if (visible != customLayer.visible) {
|
|
303
|
-
customLayer.visible = visible;
|
|
304
|
-
for (var idx = 0; idx < layers.length; idx++) {
|
|
305
|
-
layers[idx].visible = !visible;
|
|
306
|
-
}
|
|
307
|
-
if (visible) {
|
|
308
|
-
customLayer.activate();
|
|
309
|
-
} else {
|
|
310
|
-
layers[getLayerIndex(currentLayer)].activate();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
gridApi.showCustomLayer = function (visible) {
|
|
316
|
-
showCustomLayer(visible);
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
gridApi.clearCustomLayer = function () {
|
|
320
|
-
customLayer.removeChildren();
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
gridApi.clearAllLayers = function () {
|
|
324
|
-
player = null;
|
|
325
|
-
playerVector = null;
|
|
326
|
-
playerDestination = null;
|
|
327
|
-
offsetVector = null;
|
|
328
|
-
offsetDestination = null;
|
|
329
|
-
$.each(layers, function (idx, layer) {
|
|
330
|
-
layer.removeChildren();
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
gridApi.setCentre = function (x, y) {
|
|
335
|
-
var centrePoint = gridPoint(x, y);
|
|
336
|
-
var offsetX = paper.view.center.x - centrePoint.x;
|
|
337
|
-
var offsetY = paper.view.center.y - centrePoint.y;
|
|
338
|
-
var curOffset = getOffset();
|
|
339
|
-
updateOffset(new Point(offsetX, offsetY));
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
gridApi.drawCustomLayerSquare = function (id, x, y, width, height, text, fill) {
|
|
343
|
-
var points = [];
|
|
344
|
-
points.push(gridPointNudge(x, y, 1, 1));
|
|
345
|
-
points.push(gridPointNudge(x + width, y, -1, 1));
|
|
346
|
-
points.push(gridPointNudge(x + width, y + height, -1, -1));
|
|
347
|
-
points.push(gridPointNudge(x, y + height, 1, -1));
|
|
348
|
-
|
|
349
|
-
var textPoint = gridPoint(x + width / 2, y + height / 2);
|
|
350
|
-
gridApi.drawCustomLayerObject(id, points, text, textPoint, fill, fill);
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
function clearExistingObject(id) {
|
|
354
|
-
var existing = customLayerObjects[id];
|
|
355
|
-
if (existing) {
|
|
356
|
-
for (var idx in existing) {
|
|
357
|
-
var path = existing[idx];
|
|
358
|
-
// TO DO: Should remove path from layer and layerlist array
|
|
359
|
-
path.visible = false;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
gridApi.drawCustomLayerObject = function (id, points, text, textPoint, border, fill, opacity) {
|
|
365
|
-
clearExistingObject(id);
|
|
366
|
-
|
|
367
|
-
var paths = new Array();
|
|
368
|
-
path = new Path();
|
|
369
|
-
path.strokeColor = border;
|
|
370
|
-
$.each(points, function (index, value) {
|
|
371
|
-
path.add(value);
|
|
372
|
-
});
|
|
373
|
-
path.fillColor = fill;
|
|
374
|
-
path.closed = true;
|
|
375
|
-
if (typeof opacity != "undefined") {
|
|
376
|
-
path.opacity = opacity;
|
|
377
|
-
}
|
|
378
|
-
addPathToCurrentLayerList(path);
|
|
379
|
-
paths.push(path);
|
|
380
|
-
|
|
381
|
-
if (text) {
|
|
382
|
-
var pointText = new PointText(textPoint);
|
|
383
|
-
pointText.justification = "center";
|
|
384
|
-
pointText.fillColor = "black";
|
|
385
|
-
pointText.content = text;
|
|
386
|
-
if (typeof opacity != "undefined") {
|
|
387
|
-
pointText.opacity = opacity;
|
|
388
|
-
}
|
|
389
|
-
addPathToCurrentLayerList(pointText);
|
|
390
|
-
paths.push(pointText);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
customLayerObjects[id] = paths;
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
gridApi.loadSvg = function (data, id) {
|
|
397
|
-
var svg = paper.project.importSVG(data);
|
|
398
|
-
if (svg) {
|
|
399
|
-
symbols[id] = new Symbol(svg);
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
gridApi.drawCustomLayerSvg = function (id, symbolId, x, y, width, height) {
|
|
404
|
-
if (symbolId in symbols) {
|
|
405
|
-
var existing = customLayerSvg[id];
|
|
406
|
-
var placedSymbol = existing ? existing : symbols[symbolId].place();
|
|
407
|
-
placedSymbol.scale(gridX.x * width / placedSymbol.bounds.width, gridY.y * height / placedSymbol.bounds.height);
|
|
408
|
-
placedSymbol.position = gridPoint(x, y) + placedSymbol.bounds.size / 2;
|
|
409
|
-
if (!existing) addPathToCurrentLayerList(placedSymbol);
|
|
410
|
-
customLayerSvg[id] = placedSymbol;
|
|
411
|
-
} else {
|
|
412
|
-
console.log("No symbol loaded with id '" + symbolId + "'");
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
gridApi.drawCustomLayerImage = function (id, url, x, y, width, height) {
|
|
417
|
-
var existing = customLayerImages[id];
|
|
418
|
-
var raster = existing ? existing : new Raster(url);
|
|
419
|
-
var resizeRaster = function () {
|
|
420
|
-
raster.scale(gridX.x * width / raster.bounds.width, gridY.y * height / raster.bounds.height);
|
|
421
|
-
raster.position = gridPoint(x, y) + raster.bounds.size / 2;
|
|
422
|
-
};
|
|
423
|
-
if (existing) {
|
|
424
|
-
resizeRaster();
|
|
425
|
-
} else {
|
|
426
|
-
raster.onLoad = resizeRaster;
|
|
427
|
-
addPathToCurrentLayerList(raster);
|
|
428
|
-
customLayerImages[id] = raster;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
gridApi.addNewShapePoint = function (x, y) {
|
|
433
|
-
newShapePoints.push([x, y]);
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
gridApi.drawShape = function (id, border, fill, opacity) {
|
|
437
|
-
var points = [];
|
|
438
|
-
for (var idx in newShapePoints) {
|
|
439
|
-
var xy = newShapePoints[idx];
|
|
440
|
-
points.push(gridPoint(xy[0], xy[1]));
|
|
441
|
-
}
|
|
442
|
-
gridApi.drawCustomLayerObject(id, points, null, null, border, fill, opacity);
|
|
443
|
-
newShapePoints = [];
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
gridApi.onLoad();
|
|
1
|
+
var scale, gridX, gridY, player,
|
|
2
|
+
playerVector, playerDestination,
|
|
3
|
+
offsetVector, offsetDestination,
|
|
4
|
+
allPaths = [],
|
|
5
|
+
customLayerPaths = [],
|
|
6
|
+
customLayerObjects = {},
|
|
7
|
+
customLayerSvg = {},
|
|
8
|
+
customLayerImages = {},
|
|
9
|
+
layers = [],
|
|
10
|
+
maxLayer = 7,
|
|
11
|
+
currentLayer = 0,
|
|
12
|
+
offset = new Point(0, 0),
|
|
13
|
+
symbols = {},
|
|
14
|
+
newShapePoints = [];
|
|
15
|
+
|
|
16
|
+
for (var i = -maxLayer; i <= maxLayer; i++) {
|
|
17
|
+
var layer = new Layer();
|
|
18
|
+
layers.push(project.activeLayer);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
var customLayer = new Layer(),
|
|
22
|
+
customLayerOffset = new Point(0, 0);
|
|
23
|
+
|
|
24
|
+
customLayer.visible = false;
|
|
25
|
+
|
|
26
|
+
function activateLayer(index) {
|
|
27
|
+
showCustomLayer(false);
|
|
28
|
+
layers[getLayerIndex(index)].activate();
|
|
29
|
+
layers[getLayerIndex(index)].opacity = 1;
|
|
30
|
+
if (currentLayer != index) {
|
|
31
|
+
layers[getLayerIndex(currentLayer)].opacity = 0.2;
|
|
32
|
+
currentLayer = index;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getLayerIndex(index) {
|
|
37
|
+
if (index < -maxLayer || index > maxLayer) {
|
|
38
|
+
alert("Layer out of bounds. Current layer range: -" + maxLayer + " to " + maxLayer);
|
|
39
|
+
}
|
|
40
|
+
// layers array represents z-indexes from -maxLayer to maxLayer
|
|
41
|
+
return index + maxLayer;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
activateLayer(currentLayer);
|
|
45
|
+
|
|
46
|
+
gridApi.setScale = function (newScale) {
|
|
47
|
+
scale = newScale;
|
|
48
|
+
gridX = new Point(scale, 0);
|
|
49
|
+
gridY = new Point(0, scale);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
gridApi.setZoom = function (zoom) {
|
|
53
|
+
paper.view.zoom = zoom;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
gridApi.zoomIn = function (amount) {
|
|
57
|
+
zoom = paper.view.zoom * (Math.pow(1.1, amount));
|
|
58
|
+
if (zoom > 0.0001) {
|
|
59
|
+
paper.view.zoom = zoom;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function onMouseDrag(event) {
|
|
64
|
+
updateOffset(event.delta);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function onMouseUp(event) {
|
|
69
|
+
if (_respondToGridClicks) {
|
|
70
|
+
var x = getGridSquareX(event.point);
|
|
71
|
+
var y = getGridSquareY(event.point);
|
|
72
|
+
ASLEvent("JS_GridSquareClick", x + ";" + y);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function updateOffset(delta) {
|
|
77
|
+
setOffset(getOffset() + delta);
|
|
78
|
+
var paths;
|
|
79
|
+
if (project.activeLayer == customLayer) {
|
|
80
|
+
paths = customLayerPaths;
|
|
81
|
+
} else {
|
|
82
|
+
paths = allPaths;
|
|
83
|
+
}
|
|
84
|
+
for (var i = 0; i < paths.length; i++) {
|
|
85
|
+
paths[i].position += delta;
|
|
86
|
+
}
|
|
87
|
+
if (playerDestination && project.activeLayer != customLayer) {
|
|
88
|
+
playerDestination += delta;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getOffset() {
|
|
93
|
+
if (project.activeLayer == customLayer) {
|
|
94
|
+
return customLayerOffset;
|
|
95
|
+
}
|
|
96
|
+
return offset;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function setOffset(value) {
|
|
100
|
+
if (project.activeLayer == customLayer) {
|
|
101
|
+
customLayerOffset = value;
|
|
102
|
+
} else {
|
|
103
|
+
offset = value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function onFrame(event) {
|
|
108
|
+
if (playerVector) {
|
|
109
|
+
var distance = player.position - playerDestination;
|
|
110
|
+
if (distance.length > playerVector.length) {
|
|
111
|
+
player.position += playerVector;
|
|
112
|
+
} else {
|
|
113
|
+
player.position = playerDestination;
|
|
114
|
+
playerVector = null;
|
|
115
|
+
playerDestination = null;
|
|
116
|
+
|
|
117
|
+
var playerPositionAbsolute = player.position - offset;
|
|
118
|
+
offsetDestination = paper.view.center - playerPositionAbsolute;
|
|
119
|
+
|
|
120
|
+
offsetVector = (offsetDestination - offset) / 10;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (offsetVector) {
|
|
124
|
+
var distance = offset - offsetDestination;
|
|
125
|
+
if (distance.length > offsetVector.length) {
|
|
126
|
+
updateOffset(offsetVector);
|
|
127
|
+
} else {
|
|
128
|
+
updateOffset(offsetDestination - offset);
|
|
129
|
+
offsetVector = null;
|
|
130
|
+
offsetDestination = null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
gridApi.drawGrid = function (minX, minY, maxX, maxY, border) {
|
|
136
|
+
|
|
137
|
+
function gridLine(start, end) {
|
|
138
|
+
var path = new Path();
|
|
139
|
+
path.strokeColor = border;
|
|
140
|
+
path.add(start, end);
|
|
141
|
+
addPathToCurrentLayerList(path);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// draw the vertical lines
|
|
145
|
+
for (var x = minX; x <= maxX; x++) {
|
|
146
|
+
var start = gridPoint(x, minY);
|
|
147
|
+
var end = gridPoint(x, maxY);
|
|
148
|
+
gridLine(start, end);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// draw the horizontal lines
|
|
152
|
+
for (var y = minY; y <= maxY; y++) {
|
|
153
|
+
var start = gridPoint(minX, y);
|
|
154
|
+
var end = gridPoint(maxX, y);
|
|
155
|
+
gridLine(start, end);
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
function gridPoint(x, y) {
|
|
160
|
+
return (gridX * x) + (gridY * y) + getOffset();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function getGridSquareX(point) {
|
|
164
|
+
return Math.floor(((point - getOffset()) / gridX).x);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function getGridSquareY(point) {
|
|
168
|
+
return Math.floor(((point - getOffset()) / gridY).y);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function gridPointNudge(x, y, nudgeX, nudgeY) {
|
|
172
|
+
var result = gridPoint(x, y);
|
|
173
|
+
result.x += nudgeX;
|
|
174
|
+
result.y += nudgeY;
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
var firstBox = true;
|
|
179
|
+
|
|
180
|
+
gridApi.drawBox = function (x, y, z, width, height, border, borderWidth, fill, sides) {
|
|
181
|
+
activateLayer(z);
|
|
182
|
+
// if this is the very first room, centre the canvas by updating the offset
|
|
183
|
+
if (firstBox) {
|
|
184
|
+
var centrePoint = gridPoint(x + width / 2, y + height / 2);
|
|
185
|
+
var offsetX = paper.view.center.x - centrePoint.x;
|
|
186
|
+
var offsetY = paper.view.center.y - centrePoint.y;
|
|
187
|
+
updateOffset(new Point(offsetX, offsetY));
|
|
188
|
+
firstBox = false;
|
|
189
|
+
}
|
|
190
|
+
var path = null;
|
|
191
|
+
var points = [gridPoint(x, y), gridPoint(x + width, y), gridPoint(x + width, y + height), gridPoint(x, y + height)];
|
|
192
|
+
// sides is encoded with bits to represent NESW
|
|
193
|
+
var draw = [sides & 8, sides & 4, sides & 2, sides & 1];
|
|
194
|
+
for (var i = 0; i < 4; i++) {
|
|
195
|
+
var next = (i + 1) % 4;
|
|
196
|
+
if (draw[i]) {
|
|
197
|
+
if (path == null) {
|
|
198
|
+
path = new Path();
|
|
199
|
+
allPaths.push(path);
|
|
200
|
+
if (borderWidth > 0) {
|
|
201
|
+
path.strokeColor = border;
|
|
202
|
+
path.strokeWidth = borderWidth;
|
|
203
|
+
}
|
|
204
|
+
path.add(points[i]);
|
|
205
|
+
}
|
|
206
|
+
path.add(points[next]);
|
|
207
|
+
} else {
|
|
208
|
+
path = null;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
var fillPath;
|
|
212
|
+
if (sides == 15) {
|
|
213
|
+
fillPath = path;
|
|
214
|
+
} else {
|
|
215
|
+
fillPath = new Path();
|
|
216
|
+
fillPath.add(points[0], points[1], points[2], points[3]);
|
|
217
|
+
allPaths.push(fillPath);
|
|
218
|
+
}
|
|
219
|
+
fillPath.fillColor = fill;
|
|
220
|
+
fillPath.closed = true;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
gridApi.drawLine = function (x1, y1, x2, y2, border, borderWidth) {
|
|
224
|
+
var path = new Path;
|
|
225
|
+
path.strokeColor = border;
|
|
226
|
+
path.strokeWidth = borderWidth;
|
|
227
|
+
path.add(gridPoint(x1, y1));
|
|
228
|
+
path.add(gridPoint(x2, y2));
|
|
229
|
+
addPathToCurrentLayerList(path);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
gridApi.drawArrow = function (id, x1, y1, x2, y2, border, borderWidth) {
|
|
233
|
+
clearExistingObject(id);
|
|
234
|
+
|
|
235
|
+
var linePath = new Path;
|
|
236
|
+
var start = gridPoint(x1, y1);
|
|
237
|
+
var end = gridPoint(x2, y2);
|
|
238
|
+
linePath.strokeColor = border;
|
|
239
|
+
linePath.strokeWidth = borderWidth;
|
|
240
|
+
linePath.add(start);
|
|
241
|
+
linePath.add(end);
|
|
242
|
+
addPathToCurrentLayerList(linePath);
|
|
243
|
+
|
|
244
|
+
var vector = end - start;
|
|
245
|
+
var arrowVector = vector.normalize(10);
|
|
246
|
+
var arrowheadPath = new Path([
|
|
247
|
+
end + arrowVector.rotate(150),
|
|
248
|
+
end,
|
|
249
|
+
end + arrowVector.rotate(-150)
|
|
250
|
+
]);
|
|
251
|
+
arrowheadPath.strokeColor = border;
|
|
252
|
+
arrowheadPath.strokeWidth = borderWidth;
|
|
253
|
+
addPathToCurrentLayerList(arrowheadPath);
|
|
254
|
+
|
|
255
|
+
customLayerObjects[id] = [linePath, arrowheadPath];
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
function addPathToCurrentLayerList(path) {
|
|
259
|
+
if (project.activeLayer == customLayer) {
|
|
260
|
+
customLayerPaths.push(path);
|
|
261
|
+
} else {
|
|
262
|
+
allPaths.push(path);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
gridApi.drawPlayer = function (x, y, z, radius, border, borderWidth, fill) {
|
|
267
|
+
activateLayer(z);
|
|
268
|
+
if (!player) {
|
|
269
|
+
player = new Path.Circle(gridPoint(x, y), radius);
|
|
270
|
+
player.strokeColor = border;
|
|
271
|
+
player.strokeWidth = borderWidth;
|
|
272
|
+
player.fillColor = fill;
|
|
273
|
+
player.fillColor = fill;
|
|
274
|
+
allPaths.push(player);
|
|
275
|
+
|
|
276
|
+
var playerPositionAbsolute = player.position - offset;
|
|
277
|
+
var offsetDestinationX = paper.view.center.x - playerPositionAbsolute.x;
|
|
278
|
+
var offsetDestinationY = paper.view.center.y - playerPositionAbsolute.y;
|
|
279
|
+
|
|
280
|
+
offsetDestination = new Point(offsetDestinationX, offsetDestinationY);
|
|
281
|
+
offsetVector = (offsetDestination - offset);
|
|
282
|
+
} else {
|
|
283
|
+
playerDestination = gridPoint(x, y);
|
|
284
|
+
playerVector = (playerDestination - player.position) / 10;
|
|
285
|
+
// move player to the end of the activeLayer so it gets drawn on top
|
|
286
|
+
project.activeLayer.addChild(player);
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
gridApi.drawLabel = function (x, y, z, text, col) {
|
|
292
|
+
if (col === undefined) col = "black";
|
|
293
|
+
activateLayer(z);
|
|
294
|
+
var pointText = new PointText(gridPoint(x, y));
|
|
295
|
+
pointText.justification = "center";
|
|
296
|
+
pointText.fillColor = col;
|
|
297
|
+
pointText.content = text;
|
|
298
|
+
allPaths.push(pointText);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
function showCustomLayer(visible) {
|
|
302
|
+
if (visible != customLayer.visible) {
|
|
303
|
+
customLayer.visible = visible;
|
|
304
|
+
for (var idx = 0; idx < layers.length; idx++) {
|
|
305
|
+
layers[idx].visible = !visible;
|
|
306
|
+
}
|
|
307
|
+
if (visible) {
|
|
308
|
+
customLayer.activate();
|
|
309
|
+
} else {
|
|
310
|
+
layers[getLayerIndex(currentLayer)].activate();
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
gridApi.showCustomLayer = function (visible) {
|
|
316
|
+
showCustomLayer(visible);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
gridApi.clearCustomLayer = function () {
|
|
320
|
+
customLayer.removeChildren();
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
gridApi.clearAllLayers = function () {
|
|
324
|
+
player = null;
|
|
325
|
+
playerVector = null;
|
|
326
|
+
playerDestination = null;
|
|
327
|
+
offsetVector = null;
|
|
328
|
+
offsetDestination = null;
|
|
329
|
+
$.each(layers, function (idx, layer) {
|
|
330
|
+
layer.removeChildren();
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
gridApi.setCentre = function (x, y) {
|
|
335
|
+
var centrePoint = gridPoint(x, y);
|
|
336
|
+
var offsetX = paper.view.center.x - centrePoint.x;
|
|
337
|
+
var offsetY = paper.view.center.y - centrePoint.y;
|
|
338
|
+
var curOffset = getOffset();
|
|
339
|
+
updateOffset(new Point(offsetX, offsetY));
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
gridApi.drawCustomLayerSquare = function (id, x, y, width, height, text, fill) {
|
|
343
|
+
var points = [];
|
|
344
|
+
points.push(gridPointNudge(x, y, 1, 1));
|
|
345
|
+
points.push(gridPointNudge(x + width, y, -1, 1));
|
|
346
|
+
points.push(gridPointNudge(x + width, y + height, -1, -1));
|
|
347
|
+
points.push(gridPointNudge(x, y + height, 1, -1));
|
|
348
|
+
|
|
349
|
+
var textPoint = gridPoint(x + width / 2, y + height / 2);
|
|
350
|
+
gridApi.drawCustomLayerObject(id, points, text, textPoint, fill, fill);
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
function clearExistingObject(id) {
|
|
354
|
+
var existing = customLayerObjects[id];
|
|
355
|
+
if (existing) {
|
|
356
|
+
for (var idx in existing) {
|
|
357
|
+
var path = existing[idx];
|
|
358
|
+
// TO DO: Should remove path from layer and layerlist array
|
|
359
|
+
path.visible = false;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
gridApi.drawCustomLayerObject = function (id, points, text, textPoint, border, fill, opacity) {
|
|
365
|
+
clearExistingObject(id);
|
|
366
|
+
|
|
367
|
+
var paths = new Array();
|
|
368
|
+
path = new Path();
|
|
369
|
+
path.strokeColor = border;
|
|
370
|
+
$.each(points, function (index, value) {
|
|
371
|
+
path.add(value);
|
|
372
|
+
});
|
|
373
|
+
path.fillColor = fill;
|
|
374
|
+
path.closed = true;
|
|
375
|
+
if (typeof opacity != "undefined") {
|
|
376
|
+
path.opacity = opacity;
|
|
377
|
+
}
|
|
378
|
+
addPathToCurrentLayerList(path);
|
|
379
|
+
paths.push(path);
|
|
380
|
+
|
|
381
|
+
if (text) {
|
|
382
|
+
var pointText = new PointText(textPoint);
|
|
383
|
+
pointText.justification = "center";
|
|
384
|
+
pointText.fillColor = "black";
|
|
385
|
+
pointText.content = text;
|
|
386
|
+
if (typeof opacity != "undefined") {
|
|
387
|
+
pointText.opacity = opacity;
|
|
388
|
+
}
|
|
389
|
+
addPathToCurrentLayerList(pointText);
|
|
390
|
+
paths.push(pointText);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
customLayerObjects[id] = paths;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
gridApi.loadSvg = function (data, id) {
|
|
397
|
+
var svg = paper.project.importSVG(data);
|
|
398
|
+
if (svg) {
|
|
399
|
+
symbols[id] = new Symbol(svg);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
gridApi.drawCustomLayerSvg = function (id, symbolId, x, y, width, height) {
|
|
404
|
+
if (symbolId in symbols) {
|
|
405
|
+
var existing = customLayerSvg[id];
|
|
406
|
+
var placedSymbol = existing ? existing : symbols[symbolId].place();
|
|
407
|
+
placedSymbol.scale(gridX.x * width / placedSymbol.bounds.width, gridY.y * height / placedSymbol.bounds.height);
|
|
408
|
+
placedSymbol.position = gridPoint(x, y) + placedSymbol.bounds.size / 2;
|
|
409
|
+
if (!existing) addPathToCurrentLayerList(placedSymbol);
|
|
410
|
+
customLayerSvg[id] = placedSymbol;
|
|
411
|
+
} else {
|
|
412
|
+
console.log("No symbol loaded with id '" + symbolId + "'");
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
gridApi.drawCustomLayerImage = function (id, url, x, y, width, height) {
|
|
417
|
+
var existing = customLayerImages[id];
|
|
418
|
+
var raster = existing ? existing : new Raster(url);
|
|
419
|
+
var resizeRaster = function () {
|
|
420
|
+
raster.scale(gridX.x * width / raster.bounds.width, gridY.y * height / raster.bounds.height);
|
|
421
|
+
raster.position = gridPoint(x, y) + raster.bounds.size / 2;
|
|
422
|
+
};
|
|
423
|
+
if (existing) {
|
|
424
|
+
resizeRaster();
|
|
425
|
+
} else {
|
|
426
|
+
raster.onLoad = resizeRaster;
|
|
427
|
+
addPathToCurrentLayerList(raster);
|
|
428
|
+
customLayerImages[id] = raster;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
gridApi.addNewShapePoint = function (x, y) {
|
|
433
|
+
newShapePoints.push([x, y]);
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
gridApi.drawShape = function (id, border, fill, opacity) {
|
|
437
|
+
var points = [];
|
|
438
|
+
for (var idx in newShapePoints) {
|
|
439
|
+
var xy = newShapePoints[idx];
|
|
440
|
+
points.push(gridPoint(xy[0], xy[1]));
|
|
441
|
+
}
|
|
442
|
+
gridApi.drawCustomLayerObject(id, points, null, null, border, fill, opacity);
|
|
443
|
+
newShapePoints = [];
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
gridApi.onLoad();
|