diff --git a/affection.cabal b/affection.cabal index ba0d35d..cd3dd3f 100644 --- a/affection.cabal +++ b/affection.cabal @@ -6,7 +6,7 @@ name: affection -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 0.0.0.4 +version: 0.0.0.5 synopsis: A simple Game Engine using SDL description: This package contains Affection, a simple game engine written in Haskell using SDL and GEGL. @@ -39,6 +39,8 @@ library , Affection.Draw , Affection.Particle , Affection.Types + , Affection.StateMachine + , Affection.MouseInteractable default-extensions: OverloadedStrings -- Modules included in this library but not exported. diff --git a/src/Affection.hs b/src/Affection.hs index 0d174b9..7683e76 100644 --- a/src/Affection.hs +++ b/src/Affection.hs @@ -33,6 +33,8 @@ import Debug.Trace import Affection.Types as A import Affection.Draw as A import Affection.Particle as A +import Affection.StateMachine as A +import Affection.MouseInteractable as A import qualified BABL as B diff --git a/src/Affection/Draw.hs b/src/Affection/Draw.hs index c22aa8d..7b50933 100644 --- a/src/Affection/Draw.hs +++ b/src/Affection/Draw.hs @@ -61,7 +61,7 @@ present -> Affection us () present rect buf kill = do ad <- get - let k = if not kill then Kill Nothing else Yes + let k = if not kill then Kill Nothing else Persist put ad { drawStack = (DrawRequest rect buf k) : drawStack ad } @@ -95,7 +95,7 @@ handleDrawRequest pixels stride cpp dr@DrawRequest{..} = do -- liftIO $ SDL.updateWindowSurface $ drawWindow ad ) mrealRect case requestPersist of - Yes -> + Persist -> return Nothing Kill _ -> return $ Just dr diff --git a/src/Affection/MouseInteractable.hs b/src/Affection/MouseInteractable.hs new file mode 100644 index 0000000..ba0e3b1 --- /dev/null +++ b/src/Affection/MouseInteractable.hs @@ -0,0 +1,18 @@ +{-# LANGUAGE MultiParamTypeClasses #-} + +module Affection.MouseInteractable where + +import Affection.Types + +-- class MouseHoverable a us where +-- onHover :: a -> Affection us () + +-- | Define a mouse clickable object +class MouseClickable a us where + onClick + :: a -- The object + -> SDL.MouseButton -- The clicked button + -> (Int, Int) -- The coordinates of the click + -> SDL.InputMotion -- The 'SDL.InputMotion' of the click + -> Int -- The number of clicks + -> Affection us () diff --git a/src/Affection/StateMachine.hs b/src/Affection/StateMachine.hs new file mode 100644 index 0000000..7ea9597 --- /dev/null +++ b/src/Affection/StateMachine.hs @@ -0,0 +1,14 @@ +{-# LANGUAGE MultiParamTypeClasses #-} + +module Affection.StateMachine where + +import Affection.Types + +import qualified SDL + +class StateMachine a us where + smLoad :: a -> Affection us () + smUpdate :: a -> Double -> Affection us () + smEvent :: a -> Double -> SDL.Event -> Affection us () + smDraw :: a -> Affection us () + smClean :: a -> Affection us () diff --git a/src/Affection/Types.hs b/src/Affection/Types.hs index ecfd039..bd0193c 100644 --- a/src/Affection/Types.hs +++ b/src/Affection/Types.hs @@ -96,7 +96,7 @@ data DrawRequest = DrawRequest } data RequestPersist - = Yes + = Persist | Kill (Maybe G.GeglNode) -- | A type for storing 'DrawRequest' results to be executed frequently. TODO