-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.elm
56 lines (46 loc) · 1.5 KB
/
Main.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import Game
import Graphics.Element as GElem exposing (Element)
import Signal exposing ((<~))
import Timer
import Text
import Input
main : Signal Element
main =
layoutMany_live [
GElem.show <~ Timer.incomingToggleTimer,
Signal.constant <| GElem.leftAligned <| Text.fromString " Evolving: ",
GElem.show <~ Timer.indicator,
Signal.constant <| GElem.leftAligned <| Text.fromString "Speed: ",
view <~ state
]
type Model = GlobalState Input.Model Game.Model
type Update = UserInput Input.Update
| Clock
update : Update -> Model -> Model
update update (GlobalState inputM gameM) =
case update of
Clock ->
GlobalState inputM (Game.update Game.Evolve gameM)
UserInput inputU ->
let nextInputM = Input.update inputU inputM gameM
gameUpdate = Input.updateGame inputU inputM gameM
nextGameM = case gameUpdate of
Just upd -> Game.update upd gameM
Nothing -> gameM
in GlobalState nextInputM nextGameM
updated : Signal Update
updated =
Signal.merge (always Clock <~ Timer.timeUp)
(UserInput <~ Input.updated)
view : Model -> Element
view (GlobalState inputM gameM) =
Game.view gameM
state : Signal Model
state =
Signal.foldp update (GlobalState Input.init Game.init) updated
layoutMany_live : List (Signal Element) -> Signal Element
layoutMany_live (head::tail) =
List.foldl (Signal.map2 layout) head tail
layout : Element -> Element -> Element
layout e1 e2 =
GElem.flow GElem.right [e1, e2]