You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, you have to use a different string for each node. For each side of a connection (and for each floor that a set of stairs connects) you have to use a different string. Here's a simple example.
consthallwayConnections=[["hallway1_to_hallway2","hallway2_to_hallway1"],["hallway1_to_hallway3","hallway3_to_hallway1"],]consthallways=[// hallway 1newHallway([newFork(BACK,"hallway1_to_hallway3","the third hallway"),newRoom("a"),newFork(RIGHT,"hallway1_to_hallway2","the second hallway"),]),// hallway 2newHallway([newFork(FRONT,"hallway2_to_hallway1","the first hallway"),]),// hallway 3newHallway([newFork(LEFT,"hallway3_to_hallway1","the first hallway"),])]newBuilding(hallways,hallwayConnections)
It fells redundant that we should need to provide hallwayConnections, since it seems obvious that hallway1_to_hallway2 is connected to hallway2_to_hallway1.
Even worse in TypeScript
The example above isn't type safe in TypeScript. We can make it more type safe by using enums (like we're doing in walnut.direct) and adding a generic parameter to Building (like I was planning in #31):
enumConnectionNode{HALLWAY1_TO_HALLWAY3,HALLWAY3_TO_HALLWAY1,HALLWAY1_TO_HALLWAY2,HALLWAY2_TO_HALLWAY1,}consthallwayConnections=[[ConnectionNode.HALLWAY1_TO_HALLWAY2,ConnectionNode.HALLWAY2_TO_HALLWAY1],[ConnectionNode.HALLWAY1_TO_HALLWAY3,ConnectionNode.HALLWAY3_TO_HALLWAY1],]consthallways=[// hallway 1newHallway([newFork(BACK,ConnectionNode.HALLWAY1_TO_HALLWAY3,"the third hallway"),newRoom("a"),newFork(RIGHT,ConnectionNode.HALLWAY1_TO_HALLWAY2,"the second hallway"),]),// hallway 2newHallway([newFork(FRONT,ConnectionNode.HALLWAY2_TO_HALLWAY1,"the first hallway"),]),// hallway 3newHallway([newFork(LEFT,ConnectionNode.HALLWAY3_TO_HALLWAY1,"the first hallway"),])]newBuilding<ConnectionNode>(hallways,hallwayConnections)
Now, it's better typed, but it's even more redundant and confusing. And including stairs makes everything even more redundant.
Proposed solution
Fork example
Instead of using a different string for reverse connections, let's just provide a function called reverseConnection. Then, we don't even need to provide the hallwayConnections, since room-finder will be able to figure out what all the connections are.
consthallways=[// hallway 1newHallway([newFork(BACK,"hallway1_to_hallway3","the third hallway"),newRoom("a"),newFork(RIGHT,"hallway1_to_hallway2","the second hallway"),]),// hallway 2newHallway([newFork(FRONT,reverseConnection("hallway1_to_hallway2"),"the first hallway"),]),// hallway 3newHallway([newFork(LEFT,reverseConnection("hallway1_to_hallway3"),"the first hallway"),])]newBuilding(hallways)
TypeScript example
When using TypeScript, you can just can use a string union as a type parameter to make things more type safe. (You could also use an enum.)
consthallways=/*... same as above ... */typeMyConnections="hallway1_to_hallway2"|"hallway1_to_hallway3"newBuilding<MyConnections>(hallways)
Stairs example
For dealing with stairs, we could provide a function called onFloor.
consthallways=[// hallway 1 (on 1st floor)newHallway([newStairs(LEFT,onFloor("stair-a",1)),newRoom("a"),]),// hallway 4 (on 2nd floor)newHallway([newStairs(LEFT,onFloor("stair-a",2)),])]newBuilding(hallways)
Mentions
@presssssure @bholmbertelsen@tghuman Since you all have used room-finder at least a little, what do you think about this? I want to do this before implementing the accessibility API (#30), since it'll have an effect on what the accessibility API looks like.
The text was updated successfully, but these errors were encountered:
The problem
Currently, you have to use a different string for each node. For each side of a connection (and for each floor that a set of stairs connects) you have to use a different string. Here's a simple example.
It fells redundant that we should need to provide
hallwayConnections
, since it seems obvious thathallway1_to_hallway2
is connected tohallway2_to_hallway1
.Even worse in TypeScript
The example above isn't type safe in TypeScript. We can make it more type safe by using enums (like we're doing in walnut.direct) and adding a generic parameter to Building (like I was planning in #31):
Now, it's better typed, but it's even more redundant and confusing. And including stairs makes everything even more redundant.
Proposed solution
Fork example
Instead of using a different string for reverse connections, let's just provide a function called reverseConnection. Then, we don't even need to provide the hallwayConnections, since room-finder will be able to figure out what all the connections are.
TypeScript example
When using TypeScript, you can just can use a string union as a type parameter to make things more type safe. (You could also use an enum.)
Stairs example
For dealing with stairs, we could provide a function called onFloor.
Mentions
@presssssure @bholmbertelsen @tghuman Since you all have used room-finder at least a little, what do you think about this? I want to do this before implementing the accessibility API (#30), since it'll have an effect on what the accessibility API looks like.
The text was updated successfully, but these errors were encountered: