Now the game describes when parsing JSON gives an error

This commit is contained in:
Ivy 2021-02-20 15:10:02 +01:00
parent 3dd14699f4
commit 6145eac841
1 changed files with 4 additions and 2 deletions

View File

@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
module Dungeon where
import Data.Aeson
@ -6,7 +7,6 @@ import Data.Matrix
import Linear.V2
import Data.Tuple
import Data.Maybe
import Data.Either
data Cell = Solid
| Empty
@ -38,7 +38,9 @@ instance FromJSON Dungeon where
makeDungeonFromFile :: FilePath -> IO Dungeon
makeDungeonFromFile f = do
eithDun <- eitherDecodeFileStrict f
return $ fromRight (error "") eithDun
return $ case eithDun of
Left err -> error err
Right dun -> dun
dungeonToLists :: Dungeon -> [[Cell]]
dungeonToLists (Dungeon m) = toLists m