2018-02-07 00:18:16 +00:00
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
|
|
{-# LANGUAGE TypeFamilies #-}
|
|
|
|
|
|
|
|
module Types.UserData where
|
|
|
|
|
|
|
|
import Affection
|
|
|
|
|
|
|
|
import Control.Concurrent.STM
|
|
|
|
|
|
|
|
import NanoVG hiding (V2(..), V3(..))
|
|
|
|
|
|
|
|
import qualified Data.Map.Strict as M
|
2018-02-17 01:36:06 +00:00
|
|
|
import Data.Matrix
|
2018-02-07 00:18:16 +00:00
|
|
|
import Data.Ecstasy
|
|
|
|
|
2018-02-17 01:36:06 +00:00
|
|
|
import Types.Map
|
|
|
|
|
2018-02-07 00:18:16 +00:00
|
|
|
data UserData = UserData
|
|
|
|
{ state :: State
|
|
|
|
, subsystems :: Subsystems
|
|
|
|
, assetImages :: M.Map ImgId Image
|
|
|
|
, nano :: Context
|
|
|
|
, uuid :: [UUID]
|
|
|
|
, world :: Entity 'WorldOf
|
2018-02-24 14:33:46 +00:00
|
|
|
, worldState :: SystemState Entity
|
2018-02-17 01:36:06 +00:00
|
|
|
, stateData :: StateData
|
2018-02-07 00:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
data State
|
|
|
|
= Menu
|
|
|
|
| Test
|
|
|
|
|
2018-02-17 01:36:06 +00:00
|
|
|
data StateData
|
|
|
|
= None
|
|
|
|
| MenuData
|
|
|
|
{ mapMat :: Matrix TileState
|
2018-02-23 12:07:24 +00:00
|
|
|
, initCoords :: (Int, Int)
|
2018-02-17 01:36:06 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 00:18:16 +00:00
|
|
|
data ImgId
|
|
|
|
= ImgFloor
|
|
|
|
|
|
|
|
data Direction
|
|
|
|
= N
|
|
|
|
| W
|
|
|
|
| S
|
|
|
|
| E
|
|
|
|
| NW
|
|
|
|
| SW
|
|
|
|
| NE
|
|
|
|
| SE
|
|
|
|
|
|
|
|
data Entity f = Entity
|
2018-02-18 04:31:34 +00:00
|
|
|
{ pos :: Component f 'Field (V2 Double)
|
|
|
|
, gridPos :: Component f 'Field (V2 Int)
|
|
|
|
, vel :: Component f 'Field (V2 Double)
|
|
|
|
, rot :: Component f 'Field Direction
|
|
|
|
, player :: Component f 'Unique Bool
|
2018-02-07 00:18:16 +00:00
|
|
|
}
|
|
|
|
deriving (Generic)
|
|
|
|
|
|
|
|
data Subsystems = Subsystems
|
|
|
|
{ subWindow :: Window
|
|
|
|
, subMouse :: Mouse
|
|
|
|
}
|
|
|
|
|
|
|
|
newtype Window = Window (TVar [(UUID, WindowMessage -> Affection UserData())])
|
|
|
|
newtype Mouse = Mouse (TVar [(UUID, MouseMessage -> Affection UserData ())])
|
|
|
|
|
|
|
|
instance Participant Window UserData where
|
|
|
|
type Mesg Window UserData = WindowMessage
|
|
|
|
|
|
|
|
partSubscribers (Window t) = generalSubscribers t
|
|
|
|
|
|
|
|
partSubscribe (Window t) = generalSubscribe t
|
|
|
|
|
|
|
|
partUnSubscribe (Window t) = generalUnSubscribe t
|
|
|
|
|
|
|
|
instance SDLSubsystem Window UserData where
|
|
|
|
consumeSDLEvents = consumeSDLWindowEvents
|
|
|
|
|
|
|
|
instance Participant Mouse UserData where
|
|
|
|
type Mesg Mouse UserData = MouseMessage
|
|
|
|
|
|
|
|
partSubscribers (Mouse t) = generalSubscribers t
|
|
|
|
|
|
|
|
partSubscribe (Mouse t) = generalSubscribe t
|
|
|
|
|
|
|
|
partUnSubscribe (Mouse t) = generalUnSubscribe t
|
|
|
|
|
|
|
|
instance SDLSubsystem Mouse UserData where
|
|
|
|
consumeSDLEvents = consumeSDLMouseEvents
|
|
|
|
|
|
|
|
generalSubscribers
|
|
|
|
:: TVar [(UUID, msg -> Affection UserData ())]
|
|
|
|
-> Affection UserData [(msg -> Affection UserData ())]
|
|
|
|
generalSubscribers t = do
|
|
|
|
subTups <- liftIO $ readTVarIO t
|
|
|
|
return $ map snd subTups
|
|
|
|
|
|
|
|
generalSubscribe
|
|
|
|
:: TVar [(UUID, msg -> Affection UserData ())]
|
|
|
|
-> (msg -> Affection UserData ())
|
|
|
|
-> Affection UserData UUID
|
|
|
|
generalSubscribe t funct = do
|
2018-02-18 02:11:41 +00:00
|
|
|
uu <- genUUID
|
|
|
|
liftIO $ atomically $ modifyTVar' t ((uu, funct) :)
|
|
|
|
return uu
|
2018-02-07 00:18:16 +00:00
|
|
|
|
|
|
|
generalUnSubscribe
|
|
|
|
:: TVar [(UUID, msg -> Affection UserData ())]
|
|
|
|
-> UUID
|
|
|
|
-> Affection UserData ()
|
2018-02-18 02:11:41 +00:00
|
|
|
generalUnSubscribe t uu =
|
|
|
|
liftIO $ atomically $ modifyTVar' t (filter (`filterMsg` uu))
|
2018-02-07 00:18:16 +00:00
|
|
|
where
|
|
|
|
filterMsg (u, _) p = u /= p
|