@@ -12,9 +12,11 @@ import Miso.Lens
1212import Miso.Html.Element as H
1313import Miso.Html.Event as E
1414import Miso.Html.Property as P
15+ import Miso.String (fromMisoStringEither )
1516
1617import Model
1718import Game
19+ import GeneratedWorlds (allWorlds )
1820
1921-------------------------------------------------------------------------------
2022-- params
@@ -30,6 +32,7 @@ assetsUrl = "assets/"
3032data Action
3133 = ActionSetLevel Int
3234 | ActionKey IS. IntSet
35+ | ActionAskLevel MisoString
3336
3437-------------------------------------------------------------------------------
3538-- update
@@ -54,6 +57,11 @@ updateModel (ActionKey keys)
5457 modelGame .= g
5558 modelNbMoves += 1
5659
60+ updateModel (ActionAskLevel lStr) = do
61+ case fromMisoStringEither lStr of
62+ Left err -> io_ $ consoleLog $ ms err
63+ Right l -> issue $ ActionSetLevel l
64+
5765-------------------------------------------------------------------------------
5866-- resources
5967-------------------------------------------------------------------------------
@@ -91,8 +99,9 @@ viewModel :: Model -> View Model Action
9199viewModel m@ Model {.. } =
92100 div_ []
93101 [ p_ []
94- [ button_ [ onClick (ActionSetLevel $ getLevel _modelGame) ] [ " reset" ]
95- , button_ [ onClick (ActionSetLevel $ 1 + getLevel _modelGame) ] [ " next" ]
102+ [ select_ [ onChange ActionAskLevel ] (map fmtOption [1 .. length allWorlds])
103+ , button_ [ onClick (ActionSetLevel $ getLevel _modelGame) ] [ " new game" ]
104+ , button_ [ onClick (ActionSetLevel $ 1 + getLevel _modelGame) ] [ " next level" ]
96105 ]
97106 , p_ [] [ text (" nb moves: " <> ms (show _modelNbMoves) <> status) ]
98107 , Canvas. canvas
@@ -104,8 +113,15 @@ viewModel m@Model{..} =
104113 ]
105114 where
106115 (w, h) = ij2xy $ getNiNj _modelGame
116+
107117 status = if computeRunning _modelGame then " " else " , done !!!"
108118
119+ fmtOption l =
120+ let lStr = ms $ show l
121+ in option_
122+ [ selected_ (getLevel _modelGame == l), value_ lStr ]
123+ [ text (" level " <> lStr) ]
124+
109125initCanvas :: DOMRef -> Canvas Resources
110126initCanvas _ = liftJSM $
111127 Resources <$> newImage (assetsUrl <> " box1.png" )
0 commit comments