module DND.Sheet.Parser ( parseSheet --, getSheet , listSkills , createExample , getName , getStat , 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 getStat :: Character -> String -> Stat getStat char s = head . filter (\a -> statName a == s) . stats $ char