Debian Codegraph @

terps/frankendrift/FrankenDrift.Adrift/clsMap.vb

raw
1 Imports Point = FrankenDrift.Glue.Point2D
2 Imports DashStyle = FrankenDrift.Glue.ConceptualDashStyle
3 Imports DashStyles = FrankenDrift.Glue.ConceptualDashStyle
4
5 Public Class Point3D
6 Public X As Integer
7 Public Y As Integer
8 Public Z As Integer
9
10 Public Sub New(ByVal X As Integer, ByVal Y As Integer, ByVal Z As Integer)
11 Me.X = X
12 Me.Y = Y
13 Me.Z = Z
14 End Sub
15 Public Sub New()
16 End Sub
17
18 Public Shadows ReadOnly Property ToString() As String
19 Get
20 Return String.Format("X:{0}, Y:{1}, Z:{2}", X, Y, Z)
21 End Get
22 End Property
23 End Class
24
25
26
27 Public Class MapNode
28 Implements ICloneable
29 Implements IComparable(Of MapNode)
30
31 Public Key As String
32 Public Text As String
33 Public Location As New Point3D
34 Public Height As Integer = 4
35 Public Width As Integer = 6
36 Public Page As Integer
37 Public Pinned As Boolean = False
38 Public Anchors As New Dictionary(Of DirectionsEnum, Anchor)
39 Public Links As New Generic.Dictionary(Of DirectionsEnum, MapLink)
40 Private bOverlapping As Boolean = False
41 Private bSeen As Boolean = False
42 Public eInEdge, eOutEdge As DirectionsEnum
43 Public ptIn, ptOut As Point
44 Public bHasUp, bHasDown, bHasIn, bHasOut As Boolean
45 Public bDrawIn, bDrawOut As Boolean
46
47 Public Property Overlapping() As Boolean
48 Get
49 Return bOverlapping
50 End Get
51 Set(ByVal value As Boolean)
52 If value <> bOverlapping Then
53 bOverlapping = value
54 If Adventure.Map IsNot Nothing Then
55 For Each p As MapPage In Adventure.Map.Pages.Values
56 For Each n As MapNode In p.Nodes
57 If n.Overlapping Then
58 Adventure.Map.FirstOverlapPage = p.iKey
59 Exit Property
60 End If
61 Next
62 Next
63 End If
64 Adventure.Map.FirstOverlapPage = -1
65 End If
66 End Set
67 End Property
68
69
70 Public Property Seen() As Boolean
71 Get
72 Return bSeen
73 End Get
74 Set(ByVal value As Boolean)
75 If value <> bSeen Then
76 bSeen = value
77 If bSeen Then
78 Adventure.Map.Pages(Page).Seen = True
79 Else
80 Adventure.Map.Pages(Page).RecalculateSeen()
81 End If
82 End If
83 End Set
84 End Property
85
86 ' The translated points
87 Public Points() As Point = {New Point(0, 0), New Point(0, 0), New Point(0, 0), New Point(0, 0)}
88 Public ptUp As Point
89 Public ptDown As Point
90
91 Private Function Clone() As Object Implements System.ICloneable.Clone
92 Return Me.MemberwiseClone
93 End Function
94 Public Function CloneMe() As MapNode
95 Return CType(Clone(), MapNode)
96 End Function
97
98 Public Function CompareTo(ByVal other As MapNode) As Integer Implements System.IComparable(Of MapNode).CompareTo
99 'Return other.Z.CompareTo(Me.Z)
100 If Location.Z <> other.Location.Z Then Return other.Location.Z.CompareTo(Location.Z)
101 If Location.Y <> other.Location.Y Then Return Location.Y.CompareTo(other.Location.Y) ' other.Y.CompareTo(Me.Y)
102 Return Location.X.CompareTo(other.Location.X)
103 End Function
104
105 Public Sub New(Optional ByVal bCreateAnchors As Boolean = True)
106 If bCreateAnchors Then
107 For Each d As DirectionsEnum In New DirectionsEnum() {DirectionsEnum.NorthWest, DirectionsEnum.North, DirectionsEnum.NorthEast, DirectionsEnum.East, DirectionsEnum.SouthEast, DirectionsEnum.South, DirectionsEnum.SouthWest, DirectionsEnum.West}
108 Dim anchor As New Anchor
109 anchor.Direction = d
110 anchor.Parent = Me
111 Anchors.Add(d, anchor)
112 Next
113 End If
114 End Sub
115
116 End Class
117
118
119
120 Public Class MapLink
121 Public Style As DashStyle
122 Public Duplex As Boolean
123 Public sSource As String
124 Public eSourceLinkPoint As DirectionsEnum
125 Public sDestination As String
126 Public eDestinationLinkPoint As DirectionsEnum
127 Public OrigMidPoints() As Point3D = {} ' In case user wishes to enhance link
128 Public Points() As Point
129 Public ptStartB As Point
130 Public ptEndB As Point
131 Friend Anchors As New Generic.List(Of Anchor)
132 End Class
133
134
135 Public Class Anchor
136 Public Points() As Point = {New Point(0, 0), New Point(0, 0), New Point(0, 0), New Point(0, 0)}
137 Friend Direction As DirectionsEnum
138 Public Parent As Object
139 Public bVisible As Boolean
140
141 Public Property Visible() As Boolean
142 Get
143 Return bVisible
144 End Get
145 Set(ByVal value As Boolean)
146 If value <> bVisible Then
147 bVisible = value
148 End If
149 End Set
150 End Property
151 Public HasLink As Boolean = False
152
153 Public ReadOnly Property GetApproxPoint3D() As Point3D
154 Get
155 If TypeOf Parent Is MapNode Then
156 Dim nodParent As MapNode = CType(Parent, MapNode)
157 With nodParent.Location
158 Select Case Direction
159 Case DirectionsEnum.NorthWest
160 Return nodParent.Location
161 Case DirectionsEnum.North
162 Return New Point3D(.X + CInt(nodParent.Width / 2), .Y, .Z)
163 Case DirectionsEnum.NorthEast
164 Return New Point3D(.X + nodParent.Width, .Y, .Z)
165 Case DirectionsEnum.East
166 Return New Point3D(.X + nodParent.Width, .Y + CInt(nodParent.Height / 2), .Z)
167 Case DirectionsEnum.SouthEast
168 Return New Point3D(.X + nodParent.Width, .Y + nodParent.Height, .Z)
169 Case DirectionsEnum.South
170 Return New Point3D(.X + CInt(nodParent.Width / 2), .Y + nodParent.Height, .Z)
171 Case DirectionsEnum.SouthWest
172 Return New Point3D(.X, .Y + nodParent.Height, .Z)
173 Case DirectionsEnum.West
174 Return New Point3D(.X, .Y + CInt(nodParent.Height / 2), .Z)
175 Case Else
176 Return New Point3D(0, 0, 0)
177 End Select
178 End With
179 Else
180 Return New Point3D(0, 0, 0)
181 End If
182 End Get
183 End Property
184
185 End Class
186
187
188 Public Class MapPage
189
190 Public iKey As Integer
191
192 Private bSeen As Boolean
193 Public Property Seen() As Boolean
194 Get
195 Return bSeen
196 End Get
197 Set(ByVal value As Boolean)
198 If value <> bSeen Then
199 bSeen = value
200 End If
201 End Set
202 End Property
203
204
205 Friend Sub RecalculateSeen()
206 Dim lbSeen As Boolean = False
207 For Each n As MapNode In Nodes
208 If n.Seen Then
209 lbSeen = True
210 Exit For
211 End If
212 Next
213 Seen = lbSeen
214 End Sub
215
216
217 Public Sub New(ByVal iKey As Integer)
218 Me.iKey = iKey
219 Label = "Page " & iKey + 1
220 End Sub
221
222
223 Public Label As String
224 Public Nodes As New Generic.List(Of MapNode)
225
226
227 Public Function GetNode(ByVal sKey As String) As MapNode
228 For Each node As MapNode In Nodes
229 If node.Key = sKey Then Return node
230 Next
231 Return Nothing
232 End Function
233 Public Sub AddNode(ByVal node As MapNode)
234 Nodes.Add(node)
235 End Sub
236 Public Sub RemoveNode(ByVal node As MapNode)
237 Nodes.Remove(node)
238 End Sub
239
240
241 Public Sub SortNodes()
242 Nodes.Sort()
243 End Sub
244
245
246 ''' <summary>
247 ''' Checks to see if any nodes overlap
248 ''' </summary>
249 ''' <returns>True, if any overlap</returns>
250 ''' <remarks></remarks>
251 Public Function CheckForOverlaps() As Boolean
252
253 For Each node As MapNode In Nodes
254 node.Overlapping = False
255 Next
256
257 For i As Integer = 0 To Nodes.Count - 1
258 For j As Integer = i + 1 To Nodes.Count - 1
259 If Nodes(i).Location.Z = Nodes(j).Location.Z Then
260 Dim AX1 As Integer = Nodes(i).Location.X
261 Dim AX2 As Integer = Nodes(i).Location.X + Nodes(i).Width
262 Dim AY1 As Integer = Nodes(i).Location.Y
263 Dim AY2 As Integer = Nodes(i).Location.Y + Nodes(i).Height
264 Dim BX1 As Integer = Nodes(j).Location.X
265 Dim BX2 As Integer = Nodes(j).Location.X + Nodes(j).Width
266 Dim BY1 As Integer = Nodes(j).Location.Y
267 Dim BY2 As Integer = Nodes(j).Location.Y + Nodes(j).Height
268
269 If AX1 < BX2 AndAlso AX2 > BX1 AndAlso AY1 < BY2 AndAlso AY2 > BY1 Then
270 Nodes(i).Overlapping = True
271 Nodes(j).Overlapping = True
272 CheckForOverlaps = True
273 End If
274 End If
275 Next
276 Next
277
278 End Function
279
280 End Class
281
282
283 Public Class clsMap
284
285 Public Pages As New Generic.Dictionary(Of Integer, MapPage)
286 Public SelectedPage As String
287 Private iFirstOverlapPage As Integer = -1
288
289 Public Property FirstOverlapPage() As Integer
290 Get
291 Return iFirstOverlapPage
292 End Get
293 Set(ByVal value As Integer)
294 If iFirstOverlapPage <> value Then
295 End If
296 End Set
297 End Property
298
299 Public Sub RecalculateLayout()
300 Pages.Clear()
301
302 For Each sLocKey As String In Adventure.htblLocations.Keys
303 AddNode(sLocKey)
304 Next
305
306 For Each page As MapPage In Pages.Values
307 page.SortNodes()
308 Next
309
310 CheckForOverlaps()
311 If Pages.Count = 0 Then Pages.Add(0, New MapPage(0))
312 End Sub
313
314
315 Public Sub CheckForOverlaps()
316 For Each page As MapPage In Pages.Values
317 page.CheckForOverlaps()
318 Next
319 End Sub
320
321
322 Public Sub DeleteNode(ByVal sKey As String)
323 Dim node As MapNode = FindNode(sKey)
324 If node IsNot Nothing Then
325 Pages(node.Page).RemoveNode(node)
326 End If
327 End Sub
328
329
330 Public Sub RefreshNode(ByVal sKey As String)
331 If Not Adventure.htblLocations.ContainsKey(sKey) Then Exit Sub
332
333 Dim loc As clsLocation = Adventure.htblLocations(sKey)
334 Dim node As MapNode = FindNode(sKey)
335
336 If node Is Nothing Then Exit Sub
337
338 ' Add any links out to other locations
339 For d As DirectionsEnum = DirectionsEnum.North To DirectionsEnum.NorthWest
340 If loc.arlDirections(d).LocationKey IsNot Nothing Then
341 Select Case d
342 Case DirectionsEnum.Up
343 node.bHasUp = True
344 Case DirectionsEnum.Down
345 node.bHasDown = True
346 Case DirectionsEnum.In
347 node.bHasIn = True
348 Case DirectionsEnum.Out
349 node.bHasOut = True
350 End Select
351 End If
352 Next
353 End Sub
354
355
356 Public Sub UpdateMap(ByVal loc As clsLocation)
357 Dim node As MapNode = FindNode(loc.Key)
358
359 If node Is Nothing Then
360 node = AddNode(loc.Key)
361 Else
362 node.Text = loc.ShortDescriptionSafe
363 For Each d As DirectionsEnum In [Enum].GetValues(GetType(DirectionsEnum))
364 If loc.arlDirections(d).LocationKey <> "" Then
365 Dim nodDest As MapNode = FindNode(loc.arlDirections(d).LocationKey)
366 If nodDest IsNot Nothing Then
367 If node.Page <> nodDest.Page AndAlso d <> DirectionsEnum.In AndAlso d <> DirectionsEnum.Out Then
368 ' Display arrows, since the location is on a different page
369 If Not node.Links.ContainsKey(d) Then
370 Dim l As New MapLink
371 node.Links.Add(d, l)
372 End If
373 With node.Links(d)
374 .sSource = node.Key
375 .sDestination = node.Key
376 .eSourceLinkPoint = d
377 .eDestinationLinkPoint = OppositeDirection(d)
378 .Duplex = False
379 End With
380
381 ' Assuming the location on the other page actually points back at us, update it too
382 Dim locDest As clsLocation = Adventure.htblLocations(loc.arlDirections(d).LocationKey)
383 If locDest.arlDirections(OppositeDirection(d)).LocationKey = node.Key Then
384 If Not nodDest.Links.ContainsKey(OppositeDirection(d)) OrElse nodDest.Links(OppositeDirection(d)).sDestination <> nodDest.Key Then
385 ' Update the destination node to make sure that it points back here
386 UpdateMap(locDest)
387 End If
388 End If
389
390 Else
391 If node.Links.ContainsKey(d) Then
392 With node.Links(d)
393 If .sDestination = loc.arlDirections(d).LocationKey Then
394 ' Nothing to do
395 Else
396 ' If the old destination still points here, create a non-duplex link
397 If .Duplex AndAlso Adventure.htblLocations(.sDestination).arlDirections(.eDestinationLinkPoint).LocationKey = node.Key Then
398 Dim nodeOldDest As MapNode = FindNode(.sDestination)
399 Dim l As New MapLink
400 l.sSource = nodeOldDest.Key
401 l.sDestination = node.Key
402 l.eSourceLinkPoint = .eDestinationLinkPoint
403 l.eDestinationLinkPoint = .eSourceLinkPoint
404 l.Duplex = False
405 nodeOldDest.Links.Add(l.eSourceLinkPoint, l)
406 End If
407 ' If the destination points at itself, then delete that link and make us a Duplex (we may have just moved back to it's page)
408 If nodDest.Links.ContainsKey(OppositeDirection(d)) AndAlso nodDest.Links(OppositeDirection(d)).sDestination = nodDest.Key Then
409 nodDest.Links.Remove(OppositeDirection(d))
410 node.Links(d).Duplex = True
411 End If
412 ' Then create our new link
413 .sDestination = loc.arlDirections(d).LocationKey
414 If Adventure.htblLocations(.sDestination).arlDirections(.eDestinationLinkPoint).LocationKey = node.Key Then .Duplex = True
415 End If
416 If .eSourceLinkPoint = DirectionsEnum.In Then node.bHasIn = True
417 If .eSourceLinkPoint = DirectionsEnum.Out Then node.bHasOut = True
418 If .eDestinationLinkPoint = DirectionsEnum.In Then nodDest.bHasIn = True
419 If .eDestinationLinkPoint = DirectionsEnum.Out Then nodDest.bHasOut = True
420 End With
421 Else
422 ' See if the destination node already links to us, non-duplex
423 Dim bFound As Boolean = False
424 For Each lDest As MapLink In nodDest.Links.Values
425 If lDest.sDestination = node.Key AndAlso lDest.eDestinationLinkPoint = d Then
426 bFound = True
427 lDest.Duplex = True
428 End If
429 Next
430 If Not bFound Then
431 Dim l As New MapLink
432 l.sSource = node.Key
433 l.sDestination = loc.arlDirections(d).LocationKey
434 l.eSourceLinkPoint = d
435 l.eDestinationLinkPoint = OppositeDirection(d)
436 If Adventure.htblLocations(l.sDestination).arlDirections(l.eDestinationLinkPoint).LocationKey = node.Key Then l.Duplex = True
437 node.Links.Add(d, l)
438 If l.eSourceLinkPoint = DirectionsEnum.In Then node.bHasIn = True
439 If l.eSourceLinkPoint = DirectionsEnum.Out Then node.bHasOut = True
440 If l.eDestinationLinkPoint = DirectionsEnum.In Then nodDest.bHasIn = True
441 If l.eDestinationLinkPoint = DirectionsEnum.Out Then nodDest.bHasOut = True
442 End If
443 End If
444 End If
445 End If
446 Else
447 ' See if we've removed a link
448 If node.Links.ContainsKey(d) Then
449 ' Ok, need to remove the link, or make it a non-duplex link from other end
450 With node.Links(d)
451 If .Duplex Then
452 ' Ok, create new non-duplex link
453 Dim nodeOldDest As MapNode = FindNode(.sDestination)
454 Dim l As New MapLink
455 l.sSource = nodeOldDest.Key
456 l.sDestination = node.Key
457 l.eSourceLinkPoint = .eDestinationLinkPoint
458 l.eDestinationLinkPoint = .eSourceLinkPoint
459 l.Duplex = False
460 nodeOldDest.Links.Add(l.eSourceLinkPoint, l)
461 End If
462 End With
463 node.Links.Remove(d)
464 End If
465 ' Need to see if any node has a link that terminates here
466 For Each n As MapNode In Pages(node.Page).Nodes
467 For Each l As MapLink In n.Links.Values
468 If l.sDestination = node.Key AndAlso l.eDestinationLinkPoint = d Then
469 l.Duplex = False
470 End If
471 Next
472 Next
473 End If
474 Next
475 End If
476 End Sub
477
478
479 Private Function GetNewLocation(ByVal node As MapNode, ByVal nodeFrom As MapNode, ByVal dirFrom As DirectionsEnum) As Point3D
480 Dim ptLocation As New Point3D
481 ptLocation.X = nodeFrom.Location.X
482 ptLocation.Y = nodeFrom.Location.Y
483 ptLocation.Z = nodeFrom.Location.Z
484
485 Select Case dirFrom
486 Case DirectionsEnum.North
487 ptLocation.Y = nodeFrom.Location.Y + nodeFrom.Height + 2
488 Case DirectionsEnum.NorthEast
489 ptLocation.X = nodeFrom.Location.X - node.Width - 3
490 ptLocation.Y = nodeFrom.Location.Y + nodeFrom.Height + 2
491 Case DirectionsEnum.East
492 ptLocation.X = nodeFrom.Location.X - node.Width - 3
493 Case DirectionsEnum.SouthEast
494 ptLocation.X = nodeFrom.Location.X - node.Width - 3
495 ptLocation.Y = nodeFrom.Location.Y - node.Height - 2
496 Case DirectionsEnum.South
497 ptLocation.Y = nodeFrom.Location.Y - node.Height - 2
498 Case DirectionsEnum.SouthWest
499 ptLocation.X = nodeFrom.Location.X + nodeFrom.Width + 3
500 ptLocation.Y = nodeFrom.Location.Y - node.Height - 2
501 Case DirectionsEnum.West
502 ptLocation.X = nodeFrom.Location.X + nodeFrom.Width + 3
503 Case DirectionsEnum.NorthWest
504 ptLocation.X = nodeFrom.Location.X + nodeFrom.Width + 3
505 ptLocation.Y = nodeFrom.Location.Y + nodeFrom.Height + 2
506 Case DirectionsEnum.Up
507 ptLocation.Z += 6
508 Case DirectionsEnum.Down
509 ptLocation.Z -= 6
510 End Select
511
512 Return ptLocation
513 End Function
514
515
516 Private Function AddNode(ByVal sLocKey As String, Optional ByVal nodeFrom As MapNode = Nothing, Optional ByVal dirFrom As DirectionsEnum = Nothing) As MapNode
517 Dim loc As clsLocation = Adventure.htblLocations(sLocKey)
518 Dim node As MapNode = FindNode(loc.Key)
519
520 If node Is Nothing Then
521 node = New MapNode
522
523 node.Key = sLocKey
524 node.Text = loc.ShortDescriptionSafe
525 If nodeFrom Is Nothing Then
526 node.Page = GetNewPage()
527 node.Location.X = 0
528 node.Location.Y = 0
529 node.Location.Z = 0
530 Else
531 node.Page = nodeFrom.Page
532 node.Location = GetNewLocation(node, nodeFrom, dirFrom)
533 If dirFrom = DirectionsEnum.In OrElse dirFrom = DirectionsEnum.Out Then node.Page = GetNewPage()
534 End If
535
536 If Not Pages.ContainsKey(node.Page) Then Pages.Add(node.Page, New MapPage(node.Page))
537 Pages(node.Page).AddNode(node)
538
539 ' Add any links out to other locations
540 For d As DirectionsEnum = DirectionsEnum.North To DirectionsEnum.NorthWest
541 If loc.arlDirections(d).LocationKey IsNot Nothing AndAlso loc.arlDirections(d).LocationKey <> "" Then
542 Select Case d
543 Case DirectionsEnum.Up
544 node.bHasUp = True
545 Case DirectionsEnum.Down
546 node.bHasDown = True
547 Case DirectionsEnum.In
548 node.bHasIn = True
549 Case DirectionsEnum.Out
550 node.bHasOut = True
551 End Select
552 AddNode(loc.arlDirections(d).LocationKey, node, OppositeDirection(d))
553 ' First, check to see if the other location already has our link
554 Dim nodeDest As MapNode = Nothing
555 If d = DirectionsEnum.In OrElse d = DirectionsEnum.Out Then
556 nodeDest = FindNode(loc.arlDirections(d).LocationKey)
557 Else
558 nodeDest = Pages(node.Page).GetNode(loc.arlDirections(d).LocationKey)
559 End If
560
561 Dim link As MapLink = Nothing
562 If nodeDest IsNot Nothing Then
563 If nodeDest.Links.ContainsKey(OppositeDirection(d)) Then
564 link = nodeDest.Links(OppositeDirection(d))
565 Else
566 For Each linkDest As MapLink In nodeDest.Links.Values
567 If linkDest.sDestination = sLocKey Then
568 ' Make assumption that this is our link - in some layouts this may not be true
569 link = linkDest
570 Exit For
571 End If
572 Next
573 End If
574 End If
575
576 If link Is Nothing Then
577 AddLink(node, loc.arlDirections(d).LocationKey, d, OppositeDirection(d))
578 Else
579 link.sDestination = sLocKey
580 link.eDestinationLinkPoint = d
581 If DottedLink(loc.arlDirections(d)) Then
582 link.Style = DashStyles.Dot
583 End If
584 link.Duplex = True
585 If Pages(node.Page).GetNode(sLocKey).Anchors.ContainsKey(d) Then Pages(node.Page).GetNode(sLocKey).Anchors(d).HasLink = True
586 End If
587 End If
588 Next
589 Else
590 ' Check to see if we need to merge pages
591 If nodeFrom IsNot Nothing AndAlso node.Page <> nodeFrom.Page Then
592 If dirFrom <> DirectionsEnum.In AndAlso dirFrom <> DirectionsEnum.Out Then
593 MergePages(node, nodeFrom)
594 End If
595 End If
596 End If
597 Return node
598 End Function
599
600
601 Friend Function DottedLink(dir As clsDirection) As Boolean
602 If dir.Restrictions.Count > 0 Then
603 Return True
604 Else
605 Return False
606 End If
607 End Function
608
609
610 Private Sub AddLink(ByVal nodeSource As MapNode, ByVal sDest As String, ByVal eSourcePoint As DirectionsEnum, ByVal eDestPoint As DirectionsEnum)
611 Dim link As New MapLink
612 Dim loc As clsLocation = Adventure.htblLocations(nodeSource.Key)
613
614 link.sSource = nodeSource.Key
615 link.sDestination = sDest
616 link.Duplex = False
617 If DottedLink(loc.arlDirections(eSourcePoint)) Then
618 link.Style = DashStyles.Dot
619 Else
620 link.Style = DashStyles.Solid
621 End If
622 link.eSourceLinkPoint = eSourcePoint
623 ' Make assumption that end point is opposite of this one
624 link.sDestination = sDest
625 link.eDestinationLinkPoint = eDestPoint
626 If Not nodeSource.Links.ContainsKey(eSourcePoint) Then nodeSource.Links.Add(eSourcePoint, link)
627 If nodeSource.Anchors.ContainsKey(eSourcePoint) Then nodeSource.Anchors(eSourcePoint).HasLink = True
628 End Sub
629
630
631 Public Sub MergePages(ByVal node1 As MapNode, ByVal node2 As MapNode)
632 Dim pageFrom As MapPage
633 Dim pageTo As MapPage
634 Dim nodeMoving As MapNode
635 Dim nodeStaying As MapNode
636
637 If Pages(node1.Page).Nodes.Count > Pages(node2.Page).Nodes.Count OrElse (Pages(node1.Page).Nodes.Count = Pages(node2.Page).Nodes.Count AndAlso node2.Page > node1.Page) Then
638 nodeMoving = node2
639 nodeStaying = node1
640 Else
641 nodeMoving = node1
642 nodeStaying = node2
643 End If
644 pageFrom = Pages(nodeMoving.Page)
645 pageTo = Pages(nodeStaying.Page)
646
647 ' Work out what to offset each node by
648 ' First, get correct location for
649 Dim locMoving As clsLocation = Adventure.htblLocations(nodeMoving.Key)
650 Dim locStaying As clsLocation = Adventure.htblLocations(nodeStaying.Key)
651 Dim dirMove As DirectionsEnum
652
653 For Each d As DirectionsEnum In [Enum].GetValues(GetType(DirectionsEnum))
654 If locMoving.arlDirections(d).LocationKey = locStaying.Key Then
655 AddLink(nodeStaying, nodeMoving.Key, OppositeDirection(d), d)
656 dirMove = d
657 End If
658 Next
659
660 Dim ptNewLocation As Point3D = GetNewLocation(nodeMoving, nodeStaying, dirMove)
661 Dim iXOffset As Integer = nodeMoving.Location.X - ptNewLocation.X
662 Dim iYOffset As Integer = nodeMoving.Location.Y - ptNewLocation.Y
663 Dim iZOffset As Integer = nodeMoving.Location.Z - ptNewLocation.Z
664
665 For Each n As MapNode In pageFrom.Nodes
666 pageTo.AddNode(n)
667 n.Page = pageTo.iKey
668 n.Location.X -= iXOffset
669 n.Location.Y -= iYOffset
670 n.Location.Z -= iZOffset
671 Next
672 pageFrom.Nodes.Clear()
673 Pages.Remove(pageFrom.iKey)
674 End Sub
675
676 Public Function FindNode(ByVal sLocKey As String) As MapNode
677 For Each page As MapPage In Pages.Values
678 For Each node As MapNode In page.Nodes
679 If node.Key = sLocKey Then Return node
680 Next
681 Next
682 Return Nothing
683 End Function
684
685 Public Function GetNewPage(Optional ByVal bAllowEmptyPages As Boolean = False) As Integer
686 Dim iPage As Integer = 0
687 While Pages.ContainsKey(iPage) AndAlso (bAllowEmptyPages OrElse Pages(iPage).Nodes.Count > 0)
688 iPage += 1
689 End While
690 Return iPage
691 End Function
692
693 Public Sub New()
694 Pages.Add(0, New MapPage(0))
695 End Sub
696
697 End Class