Skip to content

Commit

Permalink
make dimensions non-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Feb 16, 2022
1 parent 1dc2429 commit fe0bae5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
10 changes: 3 additions & 7 deletions src/Main.elm
Expand Up @@ -86,8 +86,8 @@ update msg model =
, Route.Maze
{ shape = shape
, seed = model.nextSeed
, width = Just width
, height = Just height
, width = width
, height = height
}
|> Route.toAbsolutePath
|> Navigation.pushUrl model.key
Expand Down Expand Up @@ -146,11 +146,7 @@ view model =
]

Route.Maze info ->
baseMaze
{ width = Maybe.withDefault 10 info.width
, height = Maybe.withDefault 10 info.height
, shape = info.shape
}
baseMaze info
|> Maze.generate (Random.initialSeed info.seed)
|> Maze.view
{ cell = cellAttrs
Expand Down
16 changes: 7 additions & 9 deletions src/Route.elm
Expand Up @@ -2,13 +2,13 @@ module Route exposing (MazeShape(..), Route(..), parse, toAbsolutePath)

import Url exposing (Url)
import Url.Builder as Builder
import Url.Parser as Parser exposing ((</>), (<?>), Parser, int, map, oneOf, s, top)
import Url.Parser as Parser exposing ((</>), Parser, int, map, oneOf, s, top)
import Url.Parser.Query as Query


type Route
= New
| Maze { shape : MazeShape, seed : Int, width : Maybe Int, height : Maybe Int }
| Maze { shape : MazeShape, seed : Int, width : Int, height : Int }
| NotFound


Expand All @@ -26,10 +26,10 @@ parser : Parser (Route -> b) b
parser =
oneOf
[ map
(\shape seed width height ->
(\shape width height seed ->
Maze { shape = shape, seed = seed, width = width, height = height }
)
(top </> s "maze" </> mazeShapeParser </> int <?> Query.int "width" <?> Query.int "height")
(top </> s "maze" </> mazeShapeParser </> int </> int </> int)
, map New top
]

Expand Down Expand Up @@ -60,13 +60,11 @@ toAbsolutePath route =
Builder.absolute
[ "maze"
, shapeToSegment shape
, String.fromInt width
, String.fromInt height
, String.fromInt seed
]
(List.filterMap identity
[ Maybe.map (Builder.int "width") width
, Maybe.map (Builder.int "height") height
]
)
[]

NotFound ->
Builder.absolute [ "404" ] []
Expand Down
12 changes: 2 additions & 10 deletions tests/RouteTests.elm
Expand Up @@ -36,20 +36,12 @@ routeFuzzer =
)
mazeShapeFuzzer
(Fuzz.intRange 0 1)
maybeDimensionFuzzer
maybeDimensionFuzzer
(Fuzz.intRange 0 1)
(Fuzz.intRange 0 1)
, Fuzz.constant Route.NotFound
]


maybeDimensionFuzzer : Fuzzer (Maybe Int)
maybeDimensionFuzzer =
Fuzz.oneOf
[ Fuzz.constant Nothing
, Fuzz.map Just (Fuzz.intRange 0 1)
]


mazeShapeFuzzer : Fuzzer Route.MazeShape
mazeShapeFuzzer =
Fuzz.oneOf
Expand Down

0 comments on commit fe0bae5

Please sign in to comment.