Huge dangling commit
This commit is contained in:
parent
3597b2b7cf
commit
c24768c5c6
12 changed files with 118 additions and 40 deletions
|
@ -76,7 +76,7 @@ data Trivia = Trivia
|
|||
, bonds :: String
|
||||
, flaws :: String
|
||||
, quirk :: String
|
||||
} deriving ( Show, Eq, Ord, Generic)
|
||||
} deriving (Show, Eq, Ord, Generic)
|
||||
|
||||
data Skill = Skill
|
||||
{ skillName :: String
|
||||
|
@ -85,9 +85,9 @@ data Skill = Skill
|
|||
} deriving ( Show, Eq, Ord, Generic)
|
||||
|
||||
data Stat = Stat
|
||||
{ statName :: String
|
||||
, statScore :: Int
|
||||
, proficient :: Bool
|
||||
{ statName :: String
|
||||
, statScore :: Int
|
||||
, statProf :: Bool
|
||||
} deriving ( Show, Eq, Ord, Generic)
|
||||
|
||||
data Spell = Spell
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
module DND.Sheet.Parser
|
||||
( parseSheet
|
||||
, createExample
|
||||
, getName
|
||||
, getStat
|
||||
, getSkill
|
||||
, getSkillNames
|
||||
, getStatNames
|
||||
, getSkillScore
|
||||
, getSkillMod
|
||||
, getStatMod
|
||||
, getSaveMod
|
||||
, getProficiency
|
||||
, scoreMod
|
||||
) where
|
||||
|
||||
import Control.Monad
|
||||
--import Control.Monad
|
||||
import Data.Aeson
|
||||
import qualified Data.ByteString.Lazy as B
|
||||
import qualified Data.ByteString.Lazy.UTF8 as BSU
|
||||
--import qualified Data.ByteString.Lazy.UTF8 as BSU
|
||||
import Data.Maybe (fromJust)
|
||||
import DND.Bob (bob)
|
||||
import DND.Sheet.Content
|
||||
|
@ -27,25 +27,17 @@ parseSheet x = unwrap . decode =<< B.readFile x
|
|||
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
|
||||
|
||||
getSkill :: Character -> String -> Skill
|
||||
getSkill char s = head . filter (\a -> skillName a == s) . skills $ char
|
||||
|
||||
getSkillNames :: Character -> [String]
|
||||
getSkillNames = map skillName . skills
|
||||
|
||||
getStatNames :: Character -> [String]
|
||||
getStatNames = map statName . stats
|
||||
|
||||
getProficiency :: Character -> Int
|
||||
getProficiency = fromJust . flip Map.lookup profTable . charLevel . preamble
|
||||
-- https://www.nerdsandscoundrels.com/how-to-calculate-proficiency-bonus-5e/
|
||||
-- for some fucking reason there appears to be no simple mathematical way to get a character's proficiency bonus
|
||||
-- for some fucking reason there appears to be no simple mathematical way to
|
||||
-- get a character's proficiency bonus
|
||||
where profTable = Map.fromList
|
||||
[ (1,2), (2,2), (3,2), (4,2)
|
||||
, (5,3), (6,3), (7,3), (8,3)
|
||||
|
@ -56,16 +48,26 @@ getProficiency = fromJust . flip Map.lookup profTable . charLevel . preamble
|
|||
|
||||
-- https://worldbuildersjunction.com/dungeon-and-dragons-ability-scores-explained-for-beginners/
|
||||
-- from the Go implementation
|
||||
-- return (stat.Score - 10) / 2
|
||||
-- (stat.Score - 10) / 2
|
||||
scoreMod :: Int -> Int
|
||||
scoreMod x = div (x - 10) 2
|
||||
|
||||
getSkillScore :: Character -> String -> Int
|
||||
getSkillScore char skillString = let
|
||||
getSkillMod :: Character -> String -> Int
|
||||
getSkillMod char skillString = let
|
||||
skill = getSkill char skillString
|
||||
stat = getStat char $ skillStat skill
|
||||
prof = getProficiency char
|
||||
stat = getStat char $ skillStat skill
|
||||
prof = getProficiency char
|
||||
modifier = case skillMod skill of
|
||||
Proficient -> prof
|
||||
Expertise -> prof * 2
|
||||
Half -> div prof 2
|
||||
None -> 0
|
||||
in (modifier +) . (`div` 2) $ statScore stat - 10
|
||||
in (modifier +) . scoreMod . statScore $ stat
|
||||
|
||||
getStatMod :: Character -> String -> Int
|
||||
getStatMod char statString = scoreMod $ statScore (getStat char statString)
|
||||
|
||||
getSaveMod :: Character -> String -> Int
|
||||
getSaveMod char statString = let stat = getStat char statString
|
||||
modifier = if statProf stat then getProficiency char else 0
|
||||
in (modifier +) . scoreMod . statScore $ stat
|
||||
|
|
36
lib/DND/Sheet/Pretty.hs
Normal file
36
lib/DND/Sheet/Pretty.hs
Normal file
|
@ -0,0 +1,36 @@
|
|||
module DND.Sheet.Pretty
|
||||
( getName
|
||||
, getTrivia
|
||||
, statFunctions
|
||||
, getStats
|
||||
) where
|
||||
|
||||
import DND.Sheet.Content
|
||||
|
||||
getName :: Character -> String
|
||||
getName = charName . preamble
|
||||
|
||||
getTrivia :: Character -> [String]
|
||||
getTrivia char = map (\a -> a $ trivia char) functions
|
||||
where functions = [ background
|
||||
, personalityTrait
|
||||
, ideals
|
||||
, bonds
|
||||
, flaws
|
||||
, quirk
|
||||
]
|
||||
|
||||
--getStats :: Character -> [String]
|
||||
--getStats =
|
||||
|
||||
getStats :: Character -> [String]
|
||||
getStats char = let
|
||||
statList = map (\a -> map a (stats char)) statFunctions
|
||||
name = head statList
|
||||
score = statList !! 1
|
||||
proficiency = statList !! 2
|
||||
in zipWith3 format name score proficiency
|
||||
where format a b c = a ++ " score: " ++ b ++ " Proficient: " ++ c
|
||||
|
||||
statFunctions :: [Stat -> String]
|
||||
statFunctions = [ statName, show . statScore, show . statProf ]
|
Loading…
Add table
Add a link
Reference in a new issue