Seperate libraries and some parser functionality
This commit is contained in:
parent
4c46789ae4
commit
dcc2488e37
5
Notes.md
Normal file
5
Notes.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# Some development notes
|
||||||
|
|
||||||
|
## Maps
|
||||||
|
|
||||||
|
Consider thinking about using the `Data.Map.Map` datatype instead of `[Skill]` and `[Stat]`.
|
16
app/Main.hs
16
app/Main.hs
|
@ -1,17 +1,13 @@
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Data.Aeson
|
import DND.Sheet.Parser
|
||||||
import GHC.Generics
|
|
||||||
import qualified Data.ByteString.Lazy as B
|
|
||||||
import qualified Data.ByteString.Lazy.UTF8 as BSU
|
|
||||||
import DND.Sheet
|
|
||||||
import DND.Bob
|
|
||||||
|
|
||||||
testfile :: FilePath
|
testfile :: FilePath
|
||||||
testfile = "./example.json"
|
testfile = "./example.json"
|
||||||
|
|
||||||
createExample :: IO ()
|
|
||||||
createExample = encodeFile testfile bob
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = createExample
|
main = do
|
||||||
|
createExample testfile
|
||||||
|
sheet <- parseSheet testfile
|
||||||
|
putStrLn $ "wrote example character named \"" ++ getName sheet ++ "\" to: " ++ testfile
|
||||||
|
listSkills sheet
|
|
@ -1,7 +1,7 @@
|
||||||
module DND
|
module DND
|
||||||
( module DND.Sheet
|
( module DND.Sheet.Content
|
||||||
, module DND.Bob
|
, module DND.Bob
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import DND.Sheet
|
import DND.Sheet.Content
|
||||||
import DND.Bob
|
import DND.Bob
|
||||||
|
|
122
lib/DND/Sheet.hs
122
lib/DND/Sheet.hs
|
@ -1,121 +1,5 @@
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
|
||||||
|
|
||||||
module DND.Sheet
|
module DND.Sheet
|
||||||
( Character (..)
|
( module DND.Sheet.Content
|
||||||
, Preamble (..)
|
) where
|
||||||
, Trivia (..)
|
|
||||||
, Skill (..)
|
|
||||||
, Stat (..)
|
|
||||||
, ScoreMod(..)
|
|
||||||
, Spell(..)
|
|
||||||
, SpellComponent(..)
|
|
||||||
, Feature(..)
|
|
||||||
)
|
|
||||||
where
|
|
||||||
|
|
||||||
import Data.Aeson
|
import DND.Sheet.Content
|
||||||
import GHC.Generics
|
|
||||||
|
|
||||||
instance FromJSON Character
|
|
||||||
instance ToJSON Character
|
|
||||||
|
|
||||||
instance FromJSON Preamble
|
|
||||||
instance ToJSON Preamble
|
|
||||||
|
|
||||||
instance FromJSON Trivia
|
|
||||||
instance ToJSON Trivia
|
|
||||||
|
|
||||||
instance FromJSON Stat
|
|
||||||
instance ToJSON Stat
|
|
||||||
|
|
||||||
instance FromJSON Skill
|
|
||||||
instance ToJSON Skill
|
|
||||||
|
|
||||||
instance FromJSON ScoreMod
|
|
||||||
instance ToJSON ScoreMod
|
|
||||||
|
|
||||||
instance FromJSON Spell
|
|
||||||
instance ToJSON Spell
|
|
||||||
|
|
||||||
instance FromJSON SpellComponent
|
|
||||||
instance ToJSON SpellComponent
|
|
||||||
|
|
||||||
data ScoreMod = None
|
|
||||||
| Proficient
|
|
||||||
| Expertise
|
|
||||||
deriving (Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data Character = Character
|
|
||||||
{ preamble :: Preamble
|
|
||||||
, trivia :: Trivia
|
|
||||||
, stats :: [Stat]
|
|
||||||
, spells :: Maybe [Spell]
|
|
||||||
--, feats :: [Feat]
|
|
||||||
} deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data Preamble = Preamble
|
|
||||||
{ charLevel :: Int
|
|
||||||
, charName :: String
|
|
||||||
, charRace :: String
|
|
||||||
, charClass :: String
|
|
||||||
, jackOfAllTrades :: Bool
|
|
||||||
} deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data Trivia = Trivia
|
|
||||||
{ background :: String
|
|
||||||
, personalityTrait :: String
|
|
||||||
, ideals :: String
|
|
||||||
, bonds :: String
|
|
||||||
, flaws :: String
|
|
||||||
, quirk :: String
|
|
||||||
} deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data Skill = Skill
|
|
||||||
{ skillName :: String
|
|
||||||
, skillMod :: ScoreMod
|
|
||||||
} deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data Stat = Stat
|
|
||||||
{ stat :: String
|
|
||||||
, score :: Int
|
|
||||||
, proficient :: Bool
|
|
||||||
, skills :: [Skill]
|
|
||||||
} deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data Spell = Spell
|
|
||||||
{ spellName :: String
|
|
||||||
, spellLevel :: Int
|
|
||||||
, castingTime :: String
|
|
||||||
, range :: Int
|
|
||||||
, components :: [SpellComponent]
|
|
||||||
, duration :: String
|
|
||||||
, attackSave :: String
|
|
||||||
, damageEffect :: String
|
|
||||||
, description :: String
|
|
||||||
, school :: String
|
|
||||||
, atHighLevel :: String
|
|
||||||
} deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data SpellComponent = Verbal
|
|
||||||
| Somatic
|
|
||||||
| Material
|
|
||||||
deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
||||||
data Feature = StatIncrease
|
|
||||||
{ increase :: [Stat] }
|
|
||||||
| SetProficiency
|
|
||||||
{ changeModState :: [ScoreMod]
|
|
||||||
, featDescription :: String
|
|
||||||
}
|
|
||||||
| SetExpertise
|
|
||||||
{ changeModState :: [ScoreMod]
|
|
||||||
, featDescription :: String
|
|
||||||
}
|
|
||||||
| AddSpell
|
|
||||||
{ addSpell :: [Spell]
|
|
||||||
, featDescription :: String
|
|
||||||
}
|
|
||||||
| Roleplay
|
|
||||||
{ featDescription :: String
|
|
||||||
}
|
|
||||||
deriving ( Show, Eq, Ord, Generic)
|
|
||||||
|
|
120
lib/DND/Sheet/Content.hs
Normal file
120
lib/DND/Sheet/Content.hs
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
|
||||||
|
module DND.Sheet.Content
|
||||||
|
( Character (..)
|
||||||
|
, Preamble (..)
|
||||||
|
, Trivia (..)
|
||||||
|
, Skill (..)
|
||||||
|
, Stat (..)
|
||||||
|
, ScoreMod(..)
|
||||||
|
, Spell(..)
|
||||||
|
, SpellComponent(..)
|
||||||
|
, Feature(..)
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Data.Aeson ( FromJSON, ToJSON )
|
||||||
|
import GHC.Generics ( Generic )
|
||||||
|
|
||||||
|
instance FromJSON Character
|
||||||
|
instance ToJSON Character
|
||||||
|
|
||||||
|
instance FromJSON Preamble
|
||||||
|
instance ToJSON Preamble
|
||||||
|
|
||||||
|
instance FromJSON Trivia
|
||||||
|
instance ToJSON Trivia
|
||||||
|
|
||||||
|
instance FromJSON Stat
|
||||||
|
instance ToJSON Stat
|
||||||
|
|
||||||
|
instance FromJSON Skill
|
||||||
|
instance ToJSON Skill
|
||||||
|
|
||||||
|
instance FromJSON ScoreMod
|
||||||
|
instance ToJSON ScoreMod
|
||||||
|
|
||||||
|
instance FromJSON Spell
|
||||||
|
instance ToJSON Spell
|
||||||
|
|
||||||
|
instance FromJSON SpellComponent
|
||||||
|
instance ToJSON SpellComponent
|
||||||
|
|
||||||
|
data ScoreMod = None
|
||||||
|
| Proficient
|
||||||
|
| Expertise
|
||||||
|
deriving (Show, Eq, Ord, Generic, Enum)
|
||||||
|
|
||||||
|
data Character = Character
|
||||||
|
{ preamble :: Preamble
|
||||||
|
, trivia :: Trivia
|
||||||
|
, stats :: [Stat]
|
||||||
|
, spells :: Maybe [Spell]
|
||||||
|
--, feats :: [Feat]
|
||||||
|
} deriving ( Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
|
data Preamble = Preamble
|
||||||
|
{ charLevel :: Int
|
||||||
|
, charName :: String
|
||||||
|
, charRace :: String
|
||||||
|
, charClass :: String
|
||||||
|
, jackOfAllTrades :: Bool
|
||||||
|
} deriving ( Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
|
data Trivia = Trivia
|
||||||
|
{ background :: String
|
||||||
|
, personalityTrait :: String
|
||||||
|
, ideals :: String
|
||||||
|
, bonds :: String
|
||||||
|
, flaws :: String
|
||||||
|
, quirk :: String
|
||||||
|
} deriving ( Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
|
data Skill = Skill
|
||||||
|
{ skillName :: String
|
||||||
|
, skillMod :: ScoreMod
|
||||||
|
} deriving ( Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
|
data Stat = Stat
|
||||||
|
{ stat :: String
|
||||||
|
, score :: Int
|
||||||
|
, proficient :: Bool
|
||||||
|
, skills :: [Skill]
|
||||||
|
} deriving ( Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
|
data Spell = Spell
|
||||||
|
{ spellName :: String
|
||||||
|
, spellLevel :: Int
|
||||||
|
, castingTime :: String
|
||||||
|
, range :: Int
|
||||||
|
, components :: [SpellComponent]
|
||||||
|
, duration :: String
|
||||||
|
, attackSave :: String
|
||||||
|
, damageEffect :: String
|
||||||
|
, description :: String
|
||||||
|
, school :: String
|
||||||
|
, atHighLevel :: String
|
||||||
|
} deriving ( Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
|
data SpellComponent = Verbal
|
||||||
|
| Somatic
|
||||||
|
| Material
|
||||||
|
deriving ( Show, Eq, Ord, Generic)
|
||||||
|
|
||||||
|
data Feature = StatIncrease
|
||||||
|
{ increase :: [Stat] }
|
||||||
|
| SetProficiency
|
||||||
|
{ changeModState :: [ScoreMod]
|
||||||
|
, featDescription :: String
|
||||||
|
}
|
||||||
|
| SetExpertise
|
||||||
|
{ changeModState :: [ScoreMod]
|
||||||
|
, featDescription :: String
|
||||||
|
}
|
||||||
|
| AddSpell
|
||||||
|
{ addSpell :: [Spell]
|
||||||
|
, featDescription :: String
|
||||||
|
}
|
||||||
|
| Roleplay
|
||||||
|
{ featDescription :: String
|
||||||
|
}
|
||||||
|
deriving ( Show, Eq, Ord, Generic)
|
35
lib/DND/Sheet/Parser.hs
Normal file
35
lib/DND/Sheet/Parser.hs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
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
|
|
@ -57,11 +57,15 @@ library
|
||||||
import: warnings
|
import: warnings
|
||||||
|
|
||||||
exposed-modules: DND
|
exposed-modules: DND
|
||||||
, DND.Sheet
|
|
||||||
, DND.Bob
|
, DND.Bob
|
||||||
|
, DND.Sheet
|
||||||
|
, DND.Sheet.Content
|
||||||
|
, DND.Sheet.Parser
|
||||||
|
|
||||||
build-depends: base ^>=4.16.4.0
|
build-depends: base ^>=4.16.4.0
|
||||||
, aeson
|
, aeson
|
||||||
|
, bytestring
|
||||||
|
, utf8-string
|
||||||
|
|
||||||
hs-source-dirs: lib
|
hs-source-dirs: lib
|
||||||
|
|
||||||
|
@ -84,9 +88,9 @@ executable sheet-parser-hs
|
||||||
build-depends: base ^>=4.16.4.0
|
build-depends: base ^>=4.16.4.0
|
||||||
, optparse-applicative
|
, optparse-applicative
|
||||||
, aeson
|
, aeson
|
||||||
|
, sheet-parser-hs
|
||||||
, bytestring
|
, bytestring
|
||||||
, utf8-string
|
, utf8-string
|
||||||
, sheet-parser-hs
|
|
||||||
|
|
||||||
-- Directories containing source files.
|
-- Directories containing source files.
|
||||||
hs-source-dirs: app
|
hs-source-dirs: app
|
||||||
|
|
Loading…
Reference in a new issue