-
Notifications
You must be signed in to change notification settings - Fork 2
/
world.hs
26 lines (20 loc) · 857 Bytes
/
world.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module World where
import Data
import Control.Concurrent.MVar
import Control.Exception
import System.IO
import qualified System.IO.Strict as Strict
defaultRoom = Room { rnum = 0, roomName = "Void", roomExits = [], roomUsers = [] }
defaultWorld = World { roomsAll = [defaultRoom], usersAll = [], usersConnected = [] }
loadWorld fileName defaultWorld =
(try (read `fmap` Strict.readFile fileName) :: IO (Either SomeException World)) >>= \l ->
case l of
Left _ -> putStrLn "Using default instanceOfWorld." >> return defaultWorld
Right w -> putStrLn ("Loaded " ++ fileName) >> return w
saveWorld fileName instanceOfWorld =
writeFile fileName (show instanceOfWorld)
>> putStrLn ("Saved to " ++ fileName)
fWorld f boxOfWorld =
takeMVar boxOfWorld >>= \instanceOfWorld ->
f instanceOfWorld >>= \_ ->
putMVar boxOfWorld instanceOfWorld