From 41055a852102dcaa8658452c09c1c0afd2f42900 Mon Sep 17 00:00:00 2001 From: Dennis Frieberg Date: Mon, 21 Sep 2020 23:13:13 +0200 Subject: [PATCH] added Aeson instances --- src/Data/Aeson/TickLeiste.hs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/Data/Aeson/TickLeiste.hs diff --git a/src/Data/Aeson/TickLeiste.hs b/src/Data/Aeson/TickLeiste.hs new file mode 100644 index 0000000..ee3cbf3 --- /dev/null +++ b/src/Data/Aeson/TickLeiste.hs @@ -0,0 +1,37 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} + +module Data.Aeson.TickLeiste + ( JSONRequest (..), + JSONEvent (..), + ) +where + +import Data.Aeson +import Data.Aeson.TH +import qualified Data.Text as T +import Data.TickLeiste +import qualified Data.UUID as U + +$(deriveJSON defaultOptions {sumEncoding = defaultTaggedObject {tagFieldName = "tickType", contentsFieldName = "tickValue"}} ''Tick) + +data JSONRequest + = SetPlayerTickR {sptRplayerUUID :: U.UUID, sptRtick :: Tick} + | AddPlayerTickR {aptRplayerName :: T.Text, aptRtick :: Tick} + | InitializeTickLeisteR {itlRtickLeiste :: [(Tick, [T.Text])]} + | TickLeisteR + | ChangeNameR {cnaRplayerUUID :: U.UUID, cnaRplayerName :: T.Text} + | RemovePlayerR {rmpRplayerUUID :: U.UUID} + deriving (Show,Eq) + +$(deriveJSON defaultOptions {sumEncoding = defaultTaggedObject {tagFieldName = "requestType"}, fieldLabelModifier = drop 4} ''JSONRequest) + +data JSONEvent + = SetPlayerTickE {sptEplayerUUID :: U.UUID, sptEtick :: Tick} + | AddPlayerTickE {aptEplayerUUID :: U.UUID, aptEplayerName :: T.Text, aptEtick :: Tick} + | InitializeTickLeisteE {itlEtickLeiste :: [(Tick, [(U.UUID, T.Text)])]} + | ChangeNameE {cnaEplayerUUID :: U.UUID, cnaEplayerName :: T.Text} + | RemovePlayerE {rmpEplayerUUID :: U.UUID} + deriving (Show,Eq) + +$(deriveJSON defaultOptions {sumEncoding = defaultTaggedObject {tagFieldName = "eventType"}, fieldLabelModifier = drop 4} ''JSONEvent)