Skip to content

Commit 656420c

Browse files
committed
Bulk Create, Neighbor Support, and Path Calculation
1 parent 173f98b commit 656420c

5 files changed

Lines changed: 234 additions & 44 deletions

File tree

src/public/component/component.js

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ let selectedNode = null;
1616
let selectedNodeIndex = -1;
1717

1818
let changeName = false;
19+
let bulkcreate = 0;
20+
let createNeighbor = false;
21+
22+
let start = null;
23+
let end = null;
1924

2025
function Main()
2126
{
@@ -25,6 +30,7 @@ function Main()
2530
window.addEventListener("_event_navigation_select_", _event_onNavigationSelect);
2631
window.addEventListener("_event_modal_ok_", _event_modal_onOk);
2732
window.addEventListener("_event_modal_delete_", _event_modal_onDelete);
33+
window.addEventListener("_event_modal_createneighbor_", _event_modal_onCreateNeighbor);
2834
RC2.addEventListener("mousedown", _event_onMouseDown);
2935
RC2.addEventListener("touchstart", _event_onTouchDown);
3036
RC2.addEventListener("mouseup", _event_onMouseUp);
@@ -48,6 +54,7 @@ function Main()
4854
function UpdateURL()
4955
{
5056
let url = "@" + round(ME.Camera.Location.X, 2) + "," + round(ME.Camera.Location.Y, 2) + "," + round(ME.Camera.Location.Z, 2) + "z" + ((RenderedFloor / 2) + 1);
57+
window.dispatchEvent(new CustomEvent("_event_onURLChange", { detail: { camera: round(ME.Camera.Location.X, 2) + ", " + round(ME.Camera.Location.Y, 2) + ", " + round(ME.Camera.Location.Z, 2)}}));
5158
window.history.replaceState({ "html": url }, "", url)
5259
}
5360
function round(num, p)
@@ -142,7 +149,6 @@ function Initialize()
142149
}
143150
function _event_onKeyPress(event)
144151
{
145-
console.log(event);
146152
if (selectedNode)
147153
{
148154
if (!changeName)
@@ -188,6 +194,15 @@ function _event_onNodeSelect(event, nIndex)
188194
selectedNode.Selected = true;
189195
selectedNodeIndex = nIndex;
190196
}
197+
if (createNeighbor)
198+
{
199+
if (event != selectedNode)
200+
{
201+
selectedNode.CreatePathTo(event, true);
202+
createNeighbor = false;
203+
window.dispatchEvent(new CustomEvent("_event_onSignalNeighbor", { detail: {} }));
204+
}
205+
}
191206
}
192207
function _event_onNavigationSelect(event)
193208
{
@@ -200,19 +215,34 @@ function _event_onNavigationSelect(event)
200215
{
201216
let N = new Node("New Node", new Vertex(0, 0, 0));
202217
graph.RegisterNode(N);
218+
if (selectedNode != null)
219+
{
220+
selectedNode.Selected = false;
221+
}
222+
selectedNode = null;
223+
selectedNodeIndex = -1;
203224
_event_onNodeSelect(graph.Nodes[graph.Nodes.length - 1], graph.Nodes.length - 1);
204225
window.dispatchEvent(new CustomEvent("_event_onSignalProperties", { detail: { node: selectedNode } }));
205226
changeName = true;
206227
}
228+
else if (navigation === "_navigation_node_bulkcreate")
229+
{
230+
bulkcreate = event.detail.number;
231+
if (bulkcreate > 0)
232+
{
233+
_event_onNavigationSelect({ detail: { key: "_navigation_node_create" } });
234+
bulkcreate--;
235+
}
236+
}
207237
else if (navigation === "_navigation_node_inspect")
208238
{
209239
window.dispatchEvent(new CustomEvent("_event_onSignalProperties", { detail: { node: selectedNode } }));
210240
changeName = true;
211-
}
241+
}
212242
else if (navigation === "_navigation_node_remove")
213243
{
214244
_event_modal_onDelete();
215-
}
245+
}
216246
else if (navigation === "_navigation_view_zoomin")
217247
{
218248
ME.Camera.Location.Z -= 1;
@@ -228,6 +258,27 @@ function _event_onNavigationSelect(event)
228258
ME.Camera.Location = new Vertex(0, 0, 5);
229259
UpdateURL();
230260
}
261+
else if (navigation === "_navigation_path_start")
262+
{
263+
if (selectedNode)
264+
{
265+
start = selectedNode;
266+
}
267+
}
268+
else if (navigation === "_navigation_path_end")
269+
{
270+
if (selectedNode)
271+
{
272+
end = selectedNode;
273+
}
274+
}
275+
else if (navigation === "_navigation_path_calc")
276+
{
277+
if (start && end)
278+
{
279+
graph.GetPath(start, end);
280+
}
281+
}
231282
}
232283
function _event_onMouseDown(event)
233284
{
@@ -244,8 +295,11 @@ function _event_onMouseUp(event)
244295
MouseButton = 0;
245296
UpdateURL();
246297
RC2.style.cursor = "Default";
247-
selectedNode = null;
248-
selectedNodeIndex = -1;
298+
if (!createNeighbor)
299+
{
300+
selectedNode = null;
301+
selectedNodeIndex = -1;
302+
}
249303
for (let i = 0; i < graph.Nodes.length; i++)
250304
{
251305
let child = graph.Nodes[i];
@@ -255,7 +309,10 @@ function _event_onMouseUp(event)
255309
}
256310
else
257311
{
258-
child.Selected = false;
312+
if (!createNeighbor)
313+
{
314+
child.Selected = false;
315+
}
259316
}
260317
}
261318
}
@@ -294,11 +351,29 @@ function _event_onMouseWheel(event)
294351
function _event_modal_onOk(event)
295352
{
296353
changeName = false;
354+
if (bulkcreate > 0)
355+
{
356+
setTimeout(() =>
357+
{
358+
_event_onNavigationSelect({ detail: { key: "_navigation_node_bulkcreate", number: bulkcreate-- } });
359+
}, 1);
360+
}
297361
}
298362
function _event_modal_onDelete(event)
299363
{
300364
graph.Nodes.splice(selectedNodeIndex, 1);
301365
changeName = false;
366+
if (bulkcreate > 0)
367+
{
368+
setTimeout(() =>
369+
{
370+
_event_onNavigationSelect({ detail: { key: "_navigation_node_bulkcreate", number: bulkcreate-- } });
371+
}, 1);
372+
}
373+
}
374+
function _event_modal_onCreateNeighbor(event)
375+
{
376+
createNeighbor = true;
302377
}
303378
function MainLoop()
304379
{
@@ -334,5 +409,13 @@ function Render()
334409
ME.Device2D.stroke();
335410
ME.Device2D.lineWidth = 0.3;
336411
graph.Render(ME, 0);
412+
if (createNeighbor && selectedNode)
413+
{
414+
let p = ME.ProjectVertex(selectedNode.Location, 0);
415+
ME.Device2D.beginPath();
416+
ME.Device2D.moveTo(p.X, p.Y);
417+
ME.Device2D.lineTo(MousePosition.X, MousePosition.Y);
418+
ME.Device2D.stroke();
419+
}
337420
//g.Render(ME, 0);
338421
}

src/public/component/element.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let Graph = class Graph
109109
selected = true;
110110
}
111111
}
112-
}
112+
}
113113
for (let j = 0; j < this.Nodes[i].Neighbors.length; j++)
114114
{
115115
ME.Device2D.beginPath();
@@ -154,7 +154,7 @@ let Graph = class Graph
154154
break;
155155
}
156156
}
157-
}
157+
}
158158
let sel = false;
159159
if (this.Nodes[i].Selected == true)
160160
{
@@ -175,7 +175,7 @@ let Graph = class Graph
175175
{
176176
ME.Device2D.strokeStyle = style;
177177
ME.Device2D.stroke();
178-
}
178+
}
179179
ME.Device2D.textAlign = "center";
180180
let x = new Number(this.Nodes[i].Location.X).toFixed(1);
181181
let y = new Number(this.Nodes[i].Location.Y).toFixed(1);

src/public/component/engine.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var Engine = class Engine
9090
{
9191
/**
9292
* Creates and initializes a new rendering window for OpenGL
93-
* @param {Element} canvas
93+
* @param {Element} canvas
9494
*/
9595
constructor(canvas2D, canvas)
9696
{
@@ -151,7 +151,7 @@ var Engine = class Engine
151151
}
152152
/**
153153
* Reads a shader file and loads it into a shader object for later use
154-
* @param {String} file
154+
* @param {String} file
155155
*/
156156
LoadShaderFile(file)
157157
{
@@ -197,7 +197,7 @@ var Engine = class Engine
197197
var WorldMatrix = m4.translate(this.ViewProjectionMatrix, 0, 0, 0);
198198
WorldMatrix = m4.xRotate(WorldMatrix, degToRad(this.Camera.Rotation.X));
199199
WorldMatrix = m4.yRotate(WorldMatrix, degToRad(this.Camera.Rotation.Y));
200-
WorldMatrix = m4.zRotate(WorldMatrix, degToRad(this.Camera.Rotation.Z));
200+
WorldMatrix = m4.zRotate(WorldMatrix, degToRad(this.Camera.Rotation.Z));
201201
WorldMatrix = m4.translate(WorldMatrix, Location.X - this.Camera.Location.X, Location.Y - this.Camera.Location.Y, Location.Z - this.Camera.Location.Z);
202202
var ClipSpace = m4.transformVector(WorldMatrix, [0, 0, 0, 1]);
203203
ClipSpace[0] /= ClipSpace[3];
@@ -211,10 +211,10 @@ var Engine = class Engine
211211
var WorldMatrix = m4.translate(this.ViewProjectionMatrix, 0, 0, 0);
212212
WorldMatrix = m4.xRotate(WorldMatrix, degToRad(this.Camera.Rotation.X));
213213
WorldMatrix = m4.yRotate(WorldMatrix, degToRad(this.Camera.Rotation.Y));
214-
WorldMatrix = m4.zRotate(WorldMatrix, degToRad(this.Camera.Rotation.Z));
215-
WorldMatrix = m4.translate(WorldMatrix, -this.Camera.Location.X, -this.Camera.Location.Y, -this.Camera.Location.Z);
216-
WorldMatrix = m4.zRotate(WorldMatrix, degToRad(z_rotation));
217-
WorldMatrix = m4.translate(WorldMatrix, Location.X, Location.Y, Location.Z);
214+
WorldMatrix = m4.zRotate(WorldMatrix, degToRad(this.Camera.Rotation.Z));
215+
WorldMatrix = m4.translate(WorldMatrix, -this.Camera.Location.X, -this.Camera.Location.Y, -this.Camera.Location.Z);
216+
WorldMatrix = m4.zRotate(WorldMatrix, degToRad(z_rotation));
217+
WorldMatrix = m4.translate(WorldMatrix, Location.X, Location.Y, Location.Z);
218218
var ClipSpace = m4.transformVector(WorldMatrix, [0, 0, 0, 1]);
219219
ClipSpace[0] /= ClipSpace[3];
220220
ClipSpace[1] /= ClipSpace[3];
@@ -264,7 +264,7 @@ var Object3D = class Object3D
264264
this.vertices[vertexLocation + 1] = vert[i].Y;
265265
this.vertices[vertexLocation + 2] = vert[i].Z;
266266
vertexLocation = vertexLocation + 3
267-
267+
268268
this.colors[colorLocation + 0] = vert[i].R;
269269
this.colors[colorLocation + 1] = vert[i].G;
270270
this.colors[colorLocation + 2] = vert[i].B;
@@ -362,7 +362,7 @@ var Object3D = class Object3D
362362
this.WorldMatrix = m4.translate(this.WorldMatrix, this.Location.X - engine.Camera.Location.X, this.Location.Y - engine.Camera.Location.Y, this.Location.Z - engine.Camera.Location.Z);
363363
this.WorldMatrix = m4.xRotate(this.WorldMatrix, degToRad(this.Revolution.X));
364364
this.WorldMatrix = m4.yRotate(this.WorldMatrix, degToRad(this.Revolution.Y));
365-
this.WorldMatrix = m4.zRotate(this.WorldMatrix, degToRad(this.Revolution.Z));
365+
this.WorldMatrix = m4.zRotate(this.WorldMatrix, degToRad(this.Revolution.Z));
366366
this.WorldMatrix = m4.translate(this.WorldMatrix, this.RevolutionRadius.X, this.RevolutionRadius.Y, this.RevolutionRadius.Z);
367367
this.WorldMatrix = m4.xRotate(this.WorldMatrix, degToRad(this.Rotation.X));
368368
this.WorldMatrix = m4.yRotate(this.WorldMatrix, degToRad(this.Rotation.Y));

0 commit comments

Comments
 (0)