module DND.Sheet.Parser ( parseSheet --, getSheet , listSkills , createExample , getName , getStat , listSkillNames ) where import Control.Monad import Data.Aeson import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy.UTF8 as BSU import Data.Maybe (fromJust) import DND.Bob (bob) import DND.Sheet.Content --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