Add generic derivations and To/FromJSON instances

This commit is contained in:
2022-07-25 22:49:18 +01:00
parent f5604ef429
commit b8e8413daa
99 changed files with 1406 additions and 517 deletions
+15 -3
View File
@@ -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
}