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 , Route.Maze
{ shape = shape { shape = shape
, seed = model.nextSeed , seed = model.nextSeed
, width = Just width , width = width
, height = Just height , height = height
} }
|> Route.toAbsolutePath |> Route.toAbsolutePath
|> Navigation.pushUrl model.key |> Navigation.pushUrl model.key
@ -146,11 +146,7 @@ view model =
] ]
Route.Maze info -> Route.Maze info ->
baseMaze baseMaze info
{ width = Maybe.withDefault 10 info.width
, height = Maybe.withDefault 10 info.height
, shape = info.shape
}
|> Maze.generate (Random.initialSeed info.seed) |> Maze.generate (Random.initialSeed info.seed)
|> Maze.view |> Maze.view
{ cell = cellAttrs { cell = cellAttrs

View File

@ -2,13 +2,13 @@ module Route exposing (MazeShape(..), Route(..), parse, toAbsolutePath)
import Url exposing (Url) import Url exposing (Url)
import Url.Builder as Builder 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 import Url.Parser.Query as Query
type Route type Route
= New = New
| Maze { shape : MazeShape, seed : Int, width : Maybe Int, height : Maybe Int } | Maze { shape : MazeShape, seed : Int, width : Int, height : Int }
| NotFound | NotFound
@ -26,10 +26,10 @@ parser : Parser (Route -> b) b
parser = parser =
oneOf oneOf
[ map [ map
(\shape seed width height -> (\shape width height seed ->
Maze { shape = shape, seed = seed, width = width, height = height } 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 , map New top
] ]
@ -60,13 +60,11 @@ toAbsolutePath route =
Builder.absolute Builder.absolute
[ "maze" [ "maze"
, shapeToSegment shape , shapeToSegment shape
, String.fromInt width
, String.fromInt height
, String.fromInt seed , String.fromInt seed
] ]
(List.filterMap identity []
[ Maybe.map (Builder.int "width") width
, Maybe.map (Builder.int "height") height
]
)
NotFound -> NotFound ->
Builder.absolute [ "404" ] [] Builder.absolute [ "404" ] []

View File

@ -36,20 +36,12 @@ routeFuzzer =
) )
mazeShapeFuzzer mazeShapeFuzzer
(Fuzz.intRange 0 1) (Fuzz.intRange 0 1)
maybeDimensionFuzzer (Fuzz.intRange 0 1)
maybeDimensionFuzzer (Fuzz.intRange 0 1)
, Fuzz.constant Route.NotFound , 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 : Fuzzer Route.MazeShape
mazeShapeFuzzer = mazeShapeFuzzer =
Fuzz.oneOf Fuzz.oneOf