Skip to content

Commit a8850cc

Browse files
author
Julien Dehos
committed
level + ci
1 parent 12b0698 commit a8850cc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Build using Nix
4343
run: |
4444
export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/refs/tags/25.05.tar.gz
45-
nix-shell --run "cabal run"
45+
nix-shell --run "cabal build"
4646
4747
build-dev:
4848
runs-on: ubuntu-latest
@@ -55,7 +55,7 @@ jobs:
5555
github_access_token: ${{ secrets.GITHUB_TOKEN }}
5656

5757
- name: Build using Nix
58-
run: nix develop .#default --command bash -c "cabal update && cabal run"
58+
run: nix develop .#default --command bash -c "cabal update && cabal build"
5959

6060
deploy:
6161
runs-on: ubuntu-latest

src/Component.hs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import Miso.Lens
1212
import Miso.Html.Element as H
1313
import Miso.Html.Event as E
1414
import Miso.Html.Property as P
15+
import Miso.String (fromMisoStringEither)
1516

1617
import Model
1718
import Game
19+
import GeneratedWorlds (allWorlds)
1820

1921
-------------------------------------------------------------------------------
2022
-- params
@@ -30,6 +32,7 @@ assetsUrl = "assets/"
3032
data 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
9199
viewModel 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+
109125
initCanvas :: DOMRef -> Canvas Resources
110126
initCanvas _ = liftJSM $
111127
Resources <$> newImage (assetsUrl <> "box1.png")

0 commit comments

Comments
 (0)