diff --git a/src/Main.elm b/src/Main.elm index 8c5256c..7ce7234 100644 --- a/src/Main.elm +++ b/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 diff --git a/src/Route.elm b/src/Route.elm index 5069a00..847f2da 100644 --- a/src/Route.elm +++ b/src/Route.elm @@ -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" ] [] diff --git a/tests/RouteTests.elm b/tests/RouteTests.elm index ef6e237..ea04269 100644 --- a/tests/RouteTests.elm +++ b/tests/RouteTests.elm @@ -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