make dimensions non-optional
parent
1dc2429612
commit
fe0bae54fa
10
src/Main.elm
10
src/Main.elm
|
@ -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
|
||||
|
|
|
@ -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" ] []
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue