sheet-parser-hs/lib/DND/Sheet/Parser.hs

35 lines
806 B
Haskell

module DND.Sheet.Parser
(getSheet
, parseSheet
, listSkills
, createExample
, getName
) where
import Data.Aeson
import DND.Sheet.Content
import DND.Bob(bob)
import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Lazy.UTF8 as BSU
import Data.Maybe (fromJust)
getSheet :: FilePath -> IO B.ByteString
getSheet = B.readFile
parseSheet :: FilePath -> IO Character
parseSheet x = do
file <- B.readFile x
let character = decode file :: Maybe Character
return $ fromJust character
listSkills :: Character -> IO ()
listSkills = mapM_ (mapM_ putStrLn)
. filter (not . null)
. map (map skillName . skills)
. stats
createExample :: FilePath -> IO ()
createExample = flip encodeFile bob
getName :: Character -> String
getName = charName . preamble