Bits of optimisation
This commit is contained in:
parent
6d6bd045ad
commit
56b29314ad
|
@ -10,4 +10,4 @@ main = do
|
|||
createExample testfile
|
||||
sheet <- parseSheet testfile
|
||||
putStrLn $ "wrote example character named \"" ++ getName sheet ++ "\" to: " ++ testfile
|
||||
listSkills sheet
|
||||
listSkillNames sheet
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
jailbreakUnbreak = pkg:
|
||||
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; }));
|
||||
|
||||
# DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw`
|
||||
packageName = "sheet-parser-hs";
|
||||
in {
|
||||
packages.${packageName} =
|
||||
|
|
|
@ -1,35 +1,36 @@
|
|||
module DND.Sheet.Parser
|
||||
(getSheet
|
||||
, parseSheet
|
||||
( 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
|
||||
--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
|
||||
parseSheet x = unwrap . decode =<< B.readFile x
|
||||
where unwrap (Just y) = return y
|
||||
unwrap Nothing = error $ "Failed to parse character sheet: " ++ x
|
||||
|
||||
listSkills :: Character -> IO ()
|
||||
listSkills = mapM_ (mapM_ putStrLn)
|
||||
. filter (not . null)
|
||||
. map (map skillName . skills)
|
||||
. stats
|
||||
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
|
||||
getName = charName . preamble
|
||||
|
|
Loading…
Reference in a new issue