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

37 lines
896 B
Haskell

module DND.Sheet.Parser
( parseSheet
--, getSheet
, listSkills
, createExample
, getName
, listSkillNames
) where
import Data.Aeson
import DND.Sheet.Content
import DND.Bob(bob)
import Control.Monad
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 = unwrap . decode =<< B.readFile x
where unwrap (Just y) = return y
unwrap Nothing = error $ "Failed to parse character sheet: " ++ x
listSkills :: Character -> [Skill]
listSkills = join . map skills . stats
listSkillNames :: Character -> IO ()
listSkillNames = mapM_ (putStrLn . skillName) . listSkills
createExample :: FilePath -> IO ()
createExample = flip encodeFile bob
getName :: Character -> String
getName = charName . preamble