1
- {-# LANGUAGE CPP, OverloadedStrings #-}
1
+ {-# LANGUAGE CPP, OverloadedStrings, ForeignFunctionInterface #-}
2
2
3
3
import Reactive.Banana
4
4
import Reactive.Banana.Frameworks
@@ -14,11 +14,19 @@ defaultHeadIndex = 23
14
14
defaultNumCells = 14
15
15
16
16
main = do initializePage (defaultHeadIndex, defaultNumCells)
17
- (draw, rando, gener) <- mkSources
17
+ (draw, rando, gener, clicks, keys ) <- mkSources
18
18
wireButton draw sDrawButton (cullErrors >> readInputState)
19
- wireButton rando sRandomButton (cullErrors >> mkRandomInput)
20
- wireButton gener sCellGen (cullErrors >> generateCells)
21
- n <- compile (mkNetwork (draw, rando, gener))
19
+ wireButton rando sRandomButton (cullErrors
20
+ >> mkCanvas
21
+ >> mkRandomInput
22
+ >> readInputState)
23
+ wireButton
24
+ gener
25
+ sCellGen
26
+ (cullErrors >> generateCells >> readInputState)
27
+ wireClicks clicks
28
+ wireKeys keys readInputState
29
+ n <- compile (mkNetwork (draw, rando, gener, clicks, keys))
22
30
actuate n
23
31
24
32
generateCells :: IO ()
@@ -39,7 +47,10 @@ initializePage (start,size) =
39
47
>> writeInputState (emptyInput start size)
40
48
>> mkCanvas
41
49
42
-
50
+ wireClicks _ = return () -- maybe implement this later?
51
+ wireKeys (addHandler, fire) f = do let handler _ = f >>= fire
52
+ box <- sLowerControls
53
+ keyup handler def box
43
54
44
55
wireButton (addHandler, fire) button f = do
45
56
let handler _ = f >>= fire
@@ -49,21 +60,37 @@ wireButton (addHandler, fire) button f = do
49
60
mkSources = do a <- newAddHandler
50
61
b <- newAddHandler
51
62
c <- newAddHandler
52
- return (a,b,c)
63
+ d <- newAddHandler
64
+ e <- newAddHandler
65
+ return (a,b,c,d,e)
53
66
54
67
addHandler = fst
55
68
fire = snd
56
69
57
- mkNetwork (drawSource, randomSource, genSource) = do
70
+ mkNetwork (drawSource, randomSource, genSource, clickSource, keySource ) = do
58
71
eDraws <- fromAddHandler (addHandler drawSource)
59
72
eRandoms <- fromAddHandler (addHandler randomSource)
60
- let eInputs = eDraws `union` eRandoms
61
- -- bInputState :: Behavior t InputState
73
+ eGens <- fromAddHandler (addHandler genSource)
74
+ eKeys <- fromAddHandler (addHandler keySource)
75
+ let eResets = eRandoms `union` eGens
76
+ eInputs = eRandoms `union` eGens `union` eKeys
77
+ -- bInputState :: Behavior t InputState
62
78
bInputState = stepper (emptyInput 5 20 ) eInputs
63
-
79
+ eDrawnInputState = bInputState <@ eDraws
80
+ bLastInputState = stepper (emptyInput 5 20 )
81
+ (eDrawnInputState `union` eResets)
82
+ bDirty = mismatches <$> bInputState <*> bLastInputState
83
+ cIn <- changes bInputState
84
+ cLIn <- changes bLastInputState
85
+ cDirty <- changes bDirty
86
+
87
+
64
88
-- reactimate' $ fmap (\is -> process is) eISChanged
65
89
-- reactimate' <$> (fmap (fmap process) eISChanged)
66
90
reactimate (fmap (\ a -> mkCanvas >> process a) eDraws)
91
+ reactimate' $ fmap (\ d -> mark d >> print (show d) >> return () ) <$> cDirty
92
+ reactimate' $ fmap (\ d -> print (" InputState: " ++ show d)) <$> cIn
93
+ reactimate' $ fmap (\ d -> print (" LastState: " ++ show d)) <$> cLIn
67
94
-- reactimate (fmap (\_ -> fmap process bInputState) eDraws)
68
95
69
96
process :: InputState -> IO ()
0 commit comments