make dimensions non-optional

main
Brian Hicks 2022-02-16 09:37:16 -06:00
parent 1dc2429612
commit fe0bae54fa
3 changed files with 12 additions and 26 deletions

View File

@ -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
@ -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

View File

@ -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
@ -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
]
@ -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" ] []

View File

@ -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