From 7d8bf5d857444becad609365d713964d92223955 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Mon, 18 Nov 2024 17:24:26 +0100 Subject: [PATCH] Stylish Haskell --- flake.nix | 1 + lib/DND.hs | 8 ++--- lib/DND/Bob.hs | 6 ++-- lib/DND/Dice.hs | 2 +- lib/DND/Sheet.hs | 4 +-- lib/DND/Sheet/Content.hs | 74 ++++++++++++++++++---------------------- lib/DND/Sheet/Parser.hs | 12 +++---- 7 files changed, 51 insertions(+), 56 deletions(-) diff --git a/flake.nix b/flake.nix index 0390e42..198698b 100644 --- a/flake.nix +++ b/flake.nix @@ -35,6 +35,7 @@ haskellPackages.haskell-language-server # you must build it with your ghc to work ghcid cabal-install + stylish-haskell ]; inputsFrom = map (__getAttr "env") (__attrValues self.packages.${system}); }; diff --git a/lib/DND.hs b/lib/DND.hs index 277a816..c933afb 100644 --- a/lib/DND.hs +++ b/lib/DND.hs @@ -5,7 +5,7 @@ module DND , module DND.Dice ) where -import DND.Sheet.Content -import DND.Sheet.Parser -import DND.Dice -import DND.Bob +import DND.Bob +import DND.Dice +import DND.Sheet.Content +import DND.Sheet.Parser diff --git a/lib/DND/Bob.hs b/lib/DND/Bob.hs index f7e2f51..ac462c6 100644 --- a/lib/DND/Bob.hs +++ b/lib/DND/Bob.hs @@ -1,12 +1,12 @@ module DND.Bob (bob) where -import DND.Sheet.Content +import DND.Sheet.Content bob :: Character -bob = Character {skills=testSkills, trivia=testTrivia, stats=testStats, spells=Just testSpells, preamble=testPreamble, feats=Just testFeatures} +bob = Character {skills = testSkills, trivia = testTrivia, stats = testStats, spells = Just testSpells, preamble = testPreamble, feats = Just testFeatures} testStats :: [Stat] -testStats = [strStat,dexStat,conStat,intStat,wisStat,chaStat] +testStats = [strStat, dexStat, conStat, intStat, wisStat, chaStat] testPreamble :: Preamble testPreamble = Preamble 1 "Bob" "Elf" "Fighter" False diff --git a/lib/DND/Dice.hs b/lib/DND/Dice.hs index 5c244f2..c0f142e 100644 --- a/lib/DND/Dice.hs +++ b/lib/DND/Dice.hs @@ -4,7 +4,7 @@ module DND.Dice , advantage ) where -import System.Random +import System.Random rolls :: RandomGen a => Int -> Int -> a -> [Int] rolls x y = take x . randomRs (1, y) diff --git a/lib/DND/Sheet.hs b/lib/DND/Sheet.hs index cb03f6e..a6d1e37 100644 --- a/lib/DND/Sheet.hs +++ b/lib/DND/Sheet.hs @@ -3,5 +3,5 @@ module DND.Sheet , module DND.Sheet.Parser ) where -import DND.Sheet.Content -import DND.Sheet.Parser +import DND.Sheet.Content +import DND.Sheet.Parser diff --git a/lib/DND/Sheet/Content.hs b/lib/DND/Sheet/Content.hs index a360459..c714472 100644 --- a/lib/DND/Sheet/Content.hs +++ b/lib/DND/Sheet/Content.hs @@ -11,11 +11,10 @@ module DND.Sheet.Content , SpellComponent(..) , Feature(..) , FeatInfo(..) -, fiets ) where -import Data.Aeson ( FromJSON, ToJSON ) -import GHC.Generics ( Generic ) +import Data.Aeson (FromJSON, ToJSON) +import GHC.Generics (Generic) instance FromJSON Character instance ToJSON Character @@ -54,59 +53,54 @@ data ScoreMod = None data Character = Character { preamble :: Preamble - , trivia :: Trivia - , stats :: [Stat] - , skills :: [Skill] - , spells :: Maybe [Spell] - , feats :: Maybe [Feature] + , trivia :: Trivia + , stats :: [Stat] + , skills :: [Skill] + , spells :: Maybe [Spell] + , feats :: Maybe [Feature] } deriving ( Show, Eq, Ord, Generic) data Preamble = Preamble - { charLevel :: Int - , charName :: String - , charRace :: String - , charClass :: String + { charLevel :: Int + , charName :: String + , charRace :: String + , charClass :: String , jackOfAllTrades :: Bool } deriving ( Show, Eq, Ord, Generic) data Trivia = Trivia - { background :: String + { background :: String , personalityTrait :: String - , ideals :: String - , bonds :: String - , flaws :: String - , quirk :: String + , ideals :: String + , bonds :: String + , flaws :: String + , quirk :: String } deriving ( Show, Eq, Ord, Generic) data Skill = Skill - { skillName :: String - , skillMod :: ScoreMod + { skillName :: String + , skillMod :: ScoreMod , relatedStat :: String } deriving ( Show, Eq, Ord, Generic) -fiets = Skill { skillName = "Stuff" - , skillMod = None - , relatedStat = "Strength" - } - data Stat = Stat - { statName :: String - , score :: Int + { statName :: String + , score :: Int , proficient :: Bool } deriving ( Show, Eq, Ord, Generic) data Spell = Spell - { spellName :: String - , spellLevel :: Int - , castingTime :: String - , range :: Int - , components :: [SpellComponent] - , duration :: String - , attackSave :: String + { spellName :: String + , spellLevel :: Int + , castingTime :: String + , range :: Int + , components :: [SpellComponent] + , duration :: String + , attackSave :: String , damageEffect :: String - , description :: String - , school :: String - , atHighLevel :: String + , description :: String + , school :: String + , atHighLevel :: String } deriving ( Show, Eq, Ord, Generic) data SpellComponent = Verbal @@ -114,19 +108,19 @@ data SpellComponent = Verbal | Material deriving ( Show, Eq, Ord, Generic) -data FeatInfo = FeatInfo { featName :: String +data FeatInfo = FeatInfo { featName :: String , featDescription :: String } deriving ( Show, Eq, Ord, Generic) data Feature = StatIncrease { featInfo :: FeatInfo , increase :: [Stat] } - | SetProficiency - { featInfo :: FeatInfo + | SetProficiency + { featInfo :: FeatInfo , changeModState :: [ScoreMod] } | SetExpertise - { featInfo :: FeatInfo + { featInfo :: FeatInfo , changeModState :: [ScoreMod] } | AddSpell diff --git a/lib/DND/Sheet/Parser.hs b/lib/DND/Sheet/Parser.hs index aeef6c1..29a0620 100644 --- a/lib/DND/Sheet/Parser.hs +++ b/lib/DND/Sheet/Parser.hs @@ -8,13 +8,13 @@ module DND.Sheet.Parser , listSkillNames ) where -import Data.Aeson -import DND.Sheet.Content -import DND.Bob(bob) -import Control.Monad -import qualified Data.ByteString.Lazy as B +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 Data.Maybe (fromJust) +import DND.Bob (bob) +import DND.Sheet.Content --getSheet :: FilePath -> IO B.ByteString --getSheet = B.readFile