@@ -3,6 +3,18 @@ import dijkstra from "dijkstrajs";
33import { ForkNode , reverseConnection } from "./ForkNode" ;
44import { StairNode , onFloor } from "./StairNode" ;
55import { serializeNode , nodeFromString , Node } from "./node" ;
6+ import { OneWay } from "./Hallway" ;
7+
8+ export type HallConnectorsStructures <
9+ ForkName extends string ,
10+ StairName extends string
11+ > = {
12+ nodes : {
13+ nodeId : Node < ForkName , StairName > ;
14+ edgeLengthFromPreviousNodeInHallway : number ;
15+ } [ ] ;
16+ oneWay : OneWay ;
17+ } [ ] ;
618
719/**
820 * @ignore
@@ -11,12 +23,10 @@ function getHallwayConnections<
1123 ForkName extends string ,
1224 StairName extends string
1325> (
14- hallConnections : {
15- nodeId : Node < ForkName , StairName > ;
16- edgeLengthFromPreviousNodeInHallway : number ;
17- } [ ] [ ]
26+ hallConnections : HallConnectorsStructures < ForkName , StairName >
1827) : [ string , string ] [ ] {
1928 return hallConnections
29+ . map ( hallway => hallway . nodes )
2030 . flat ( )
2131 . map ( thing => thing . nodeId )
2232 . filter (
@@ -32,12 +42,10 @@ function getHallwayConnections<
3242
3343/** @ignore */
3444function getStairConnections < ForkName extends string , StairName extends string > (
35- hallConnections : {
36- nodeId : Node < ForkName , StairName > ;
37- edgeLengthFromPreviousNodeInHallway : number ;
38- } [ ] [ ]
45+ hallConnections : HallConnectorsStructures < ForkName , StairName >
3946) : string [ ] [ ] {
4047 const stairNodes = hallConnections
48+ . map ( hallway => hallway . nodes )
4149 . flat ( )
4250 . map ( thing => thing . nodeId )
4351 . filter ( ( st ) : st is StairNode < StairName > => st instanceof StairNode ) ;
@@ -59,30 +67,30 @@ function getStairConnections<ForkName extends string, StairName extends string>(
5967 * @returns The graph to be used by getShortestPath
6068 */
6169export function getGraph < ForkName extends string , StairName extends string > (
62- hallConnectorsStructures : {
63- nodeId : Node < ForkName , StairName > ;
64- edgeLengthFromPreviousNodeInHallway : number ;
65- } [ ] [ ]
70+ hallConnectorsStructures : HallConnectorsStructures < ForkName , StairName >
6671) {
67- const hallConnectors = hallConnectorsStructures . map ( hall =>
68- hall . map ( ( { nodeId, edgeLengthFromPreviousNodeInHallway } ) => ( {
69- nodeId : serializeNode ( nodeId ) ,
70- edgeLengthFromPreviousNodeInHallway,
71- } ) )
72- ) ;
72+ const hallConnectors = hallConnectorsStructures . map ( hall => ( {
73+ oneWay : hall . oneWay ,
74+ nodes : hall . nodes . map (
75+ ( { nodeId, edgeLengthFromPreviousNodeInHallway } ) => ( {
76+ nodeId : serializeNode ( nodeId ) ,
77+ edgeLengthFromPreviousNodeInHallway,
78+ } )
79+ ) ,
80+ } ) ) ;
7381 const stairConnections = getStairConnections ( hallConnectorsStructures ) ;
7482 const hallwayConnections = getHallwayConnections ( hallConnectorsStructures ) ;
7583
7684 const graph : dijkstra . Graph = { } ;
77- hallConnectors . forEach ( hall => {
85+ hallConnectors . forEach ( ( { oneWay , nodes : hall } ) => {
7886 hall . forEach ( ( node , ind ) => {
7987 const id = node . nodeId ;
8088 const edgesTo : { [ key : string ] : number } = { } ;
81- if ( ind != 0 ) {
89+ if ( ind !== 0 && oneWay !== "forward" ) {
8290 edgesTo [ hall [ ind - 1 ] . nodeId ] =
8391 hall [ ind ] . edgeLengthFromPreviousNodeInHallway ;
8492 }
85- if ( ind != hall . length - 1 ) {
93+ if ( ind !== hall . length - 1 && oneWay !== "backward" ) {
8694 edgesTo [ hall [ ind + 1 ] . nodeId ] =
8795 hall [ ind + 1 ] . edgeLengthFromPreviousNodeInHallway ;
8896 }
0 commit comments