equal
deleted
inserted
replaced
13 moveClientToRoom, |
13 moveClientToRoom, |
14 clientRoom, |
14 clientRoom, |
15 client, |
15 client, |
16 allClients, |
16 allClients, |
17 withRoomsAndClients, |
17 withRoomsAndClients, |
18 showRooms |
18 showRooms, |
|
19 roomClients |
19 ) where |
20 ) where |
20 |
21 |
21 |
22 |
22 import Store |
23 import Store |
23 import Control.Monad |
24 import Control.Monad |
36 |
37 |
37 |
38 |
38 newtype RoomIndex = RoomIndex ElemIndex |
39 newtype RoomIndex = RoomIndex ElemIndex |
39 deriving (Eq) |
40 deriving (Eq) |
40 newtype ClientIndex = ClientIndex ElemIndex |
41 newtype ClientIndex = ClientIndex ElemIndex |
41 deriving (Eq) |
42 deriving (Eq, Show, Read) |
42 |
43 |
43 instance Show RoomIndex where |
44 instance Show RoomIndex where |
44 show (RoomIndex i) = 'r' : show i |
45 show (RoomIndex i) = 'r' : show i |
45 instance Show ClientIndex where |
|
46 show (ClientIndex i) = 'c' : show i |
|
47 |
46 |
48 unRoomIndex :: RoomIndex -> ElemIndex |
47 unRoomIndex :: RoomIndex -> ElemIndex |
49 unRoomIndex (RoomIndex r) = r |
48 unRoomIndex (RoomIndex r) = r |
50 |
49 |
51 unClientIndex :: ClientIndex -> ElemIndex |
50 unClientIndex :: ClientIndex -> ElemIndex |
74 roomAddClient cl room = room{roomClients' = cl : roomClients' room} |
73 roomAddClient cl room = room{roomClients' = cl : roomClients' room} |
75 |
74 |
76 roomRemoveClient :: ClientIndex -> Room r -> Room r |
75 roomRemoveClient :: ClientIndex -> Room r -> Room r |
77 roomRemoveClient cl room = room{roomClients' = filter (/= cl) $ roomClients' room} |
76 roomRemoveClient cl room = room{roomClients' = filter (/= cl) $ roomClients' room} |
78 |
77 |
79 |
78 |
80 addRoom :: MRoomsAndClients r c -> r -> IO RoomIndex |
79 addRoom :: MRoomsAndClients r c -> r -> IO RoomIndex |
81 addRoom (MRoomsAndClients (rooms, _)) room = do |
80 addRoom (MRoomsAndClients (rooms, _)) room = do |
82 i <- addElem rooms (Room [] room) |
81 i <- addElem rooms (Room [] room) |
83 return $ RoomIndex i |
82 return $ RoomIndex i |
84 |
83 |
147 |
146 |
148 allClients :: IRoomsAndClients r c -> [ClientIndex] |
147 allClients :: IRoomsAndClients r c -> [ClientIndex] |
149 allClients (IRoomsAndClients (_, clients)) = map ClientIndex $ indices clients |
148 allClients (IRoomsAndClients (_, clients)) = map ClientIndex $ indices clients |
150 |
149 |
151 |
150 |
152 clientRoom :: ClientIndex -> IRoomsAndClients r c -> RoomIndex |
151 clientRoom :: IRoomsAndClients r c -> ClientIndex -> RoomIndex |
153 clientRoom (ClientIndex ci) (IRoomsAndClients (_, clients)) = clientRoom' (clients ! ci) |
152 clientRoom (IRoomsAndClients (_, clients)) (ClientIndex ci) = clientRoom' (clients ! ci) |
154 |
153 |
155 client :: IRoomsAndClients r c -> ClientIndex -> c |
154 client :: IRoomsAndClients r c -> ClientIndex -> c |
156 client (IRoomsAndClients (_, clients)) (ClientIndex ci) = client' (clients ! ci) |
155 client (IRoomsAndClients (_, clients)) (ClientIndex ci) = client' (clients ! ci) |
|
156 |
|
157 roomClients :: IRoomsAndClients r c -> RoomIndex -> [ClientIndex] |
|
158 roomClients (IRoomsAndClients (rooms, _)) (RoomIndex ri) = roomClients' $ (rooms ! ri) |