Add generic derivations and To/FromJSON instances
This commit is contained in:
+15
-3
@@ -1,6 +1,9 @@
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
module Sound.Data
|
||||
where
|
||||
import GHC.Generics
|
||||
import Data.Aeson
|
||||
import qualified SDL.Mixer as Mix
|
||||
import qualified IntMapHelp as IM
|
||||
--import qualified Data.Map.Strict as M
|
||||
@@ -12,7 +15,10 @@ data SoundStatus = SoundStatus
|
||||
{_playStatus :: PlayStatus
|
||||
,_isLooping :: Bool
|
||||
}
|
||||
deriving (Eq,Ord,Show)
|
||||
deriving (Eq,Ord,Show,Generic)
|
||||
instance ToJSON SoundStatus where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON SoundStatus
|
||||
-- TODO make this more sensible (use product rather than union in some cases)
|
||||
data PlayStatus
|
||||
= JustStartedPlaying
|
||||
@@ -20,9 +26,15 @@ data PlayStatus
|
||||
| ToStart
|
||||
| ToContinueStart
|
||||
| ToStop
|
||||
deriving (Eq,Ord,Show)
|
||||
deriving (Eq,Ord,Show,Generic)
|
||||
instance ToJSON PlayStatus where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON PlayStatus
|
||||
newtype SoundID = SoundID { _getSoundID :: Int }
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON SoundID where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON SoundID
|
||||
newtype SoundData = SoundData
|
||||
{_loadedChunks :: IM.IntMap Mix.Chunk
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user