Compare commits

..

3 commits

Author SHA1 Message Date
Nox Sluijtman 7d8bf5d857
Stylish Haskell 2024-11-18 17:24:26 +01:00
Nox Sluijtman f12134bf55
Refactor of skills and start of dice module 2024-11-18 17:09:42 +01:00
Nox Sluijtman 554a26fff6
Indentation 2024-11-18 09:20:17 +01:00
10 changed files with 142 additions and 97 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

View file

@ -5,11 +5,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1694529238, "lastModified": 1731533236,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide", "owner": "numtide",
"repo": "flake-utils", "repo": "flake-utils",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -20,11 +20,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1699169573, "lastModified": 1704290814,
"narHash": "sha256-cvUb1xZkvOp3W2SzylStrTirhVd9zCeo5utJl9nSIhw=", "narHash": "sha256-LWvKHp7kGxk/GEtlrGYV68qIvPHkU9iToomNFGagixU=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "aeefe2054617cae501809b82b44a8e8f7be7cc4b", "rev": "70bdadeb94ffc8806c0570eb5c2695ad29f0e421",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -35,6 +35,7 @@
haskellPackages.haskell-language-server # you must build it with your ghc to work haskellPackages.haskell-language-server # you must build it with your ghc to work
ghcid ghcid
cabal-install cabal-install
stylish-haskell
]; ];
inputsFrom = map (__getAttr "env") (__attrValues self.packages.${system}); inputsFrom = map (__getAttr "env") (__attrValues self.packages.${system});
}; };

View file

@ -2,8 +2,10 @@ module DND
( module DND.Sheet.Content ( module DND.Sheet.Content
, module DND.Sheet.Parser , module DND.Sheet.Parser
, module DND.Bob , module DND.Bob
, module DND.Dice
) where ) where
import DND.Sheet.Content import DND.Bob
import DND.Sheet.Parser import DND.Dice
import DND.Bob import DND.Sheet.Content
import DND.Sheet.Parser

View file

@ -1,12 +1,12 @@
module DND.Bob (bob) where module DND.Bob (bob) where
import DND.Sheet.Content import DND.Sheet.Content
bob :: Character bob :: Character
bob = Character testPreamble testTrivia testStats (Just testSpells) bob = Character {skills = testSkills, trivia = testTrivia, stats = testStats, spells = Just testSpells, preamble = testPreamble, feats = Just testFeatures}
testStats :: [Stat] testStats :: [Stat]
testStats = [strStat,dexStat,conStat,intStat,wisStat,chaStat] testStats = [strStat, dexStat, conStat, intStat, wisStat, chaStat]
testPreamble :: Preamble testPreamble :: Preamble
testPreamble = Preamble 1 "Bob" "Elf" "Fighter" False testPreamble = Preamble 1 "Bob" "Elf" "Fighter" False
@ -15,65 +15,72 @@ testTrivia :: Trivia
testTrivia = Trivia "farmer" "none" "I me likey fun things" "yay" "all" "idk" testTrivia = Trivia "farmer" "none" "I me likey fun things" "yay" "all" "idk"
strStat :: Stat strStat :: Stat
strStat = Stat "Strength" 10 False strSkills strStat = Stat "Strength" 10 False
strSkills :: [Skill] strSkills :: [Skill]
strSkills = [ Skill "Athletics" None ] strSkills = [ Skill "Athletics" None "Strength" ]
dexStat :: Stat dexStat :: Stat
dexStat = Stat "Dexterity" 10 False dexSkills dexStat = Stat "Dexterity" 10 False
dexSkills :: [Skill] dexSkills :: [Skill]
dexSkills = [ Skill "Acrobatics" None dexSkills = [ Skill "Acrobatics" None "Dexterity"
, Skill "Sleight of Hand" None , Skill "Sleight of Hand" None "Dexterity"
, Skill "Stealth" None , Skill "Stealth" None "Dexterity"
] ]
conStat :: Stat conStat :: Stat
conStat = Stat "Constitution" 10 False [] conStat = Stat "Constitution" 10 False
intStat :: Stat intStat :: Stat
intStat = Stat "Intelligence" 10 False intSkills intStat = Stat "Intelligence" 10 False
intSkills :: [Skill] intSkills :: [Skill]
intSkills = [ Skill "Arcana" None intSkills = [ Skill "Arcana" None "Intelligence"
, Skill "History" None , Skill "History" None "Intelligence"
, Skill "Investigation" None , Skill "Investigation" None "Intelligence"
, Skill "Nature" None , Skill "Nature" None "Intelligence"
, Skill "Religion" None , Skill "Religion" None "Intelligence"
] ]
wisStat :: Stat wisStat :: Stat
wisStat = Stat "Wisdom" 10 False wisSkills wisStat = Stat "Wisdom" 10 False
wisSkills :: [Skill] wisSkills :: [Skill]
wisSkills = [ Skill "Animal Handling" None wisSkills = [ Skill "Animal Handling" None "Wisdom"
, Skill "Insight" None , Skill "Insight" None "Wisdom"
, Skill "Medicine" None , Skill "Medicine" None "Wisdom"
, Skill "Perception" None , Skill "Perception" None "Wisdom"
, Skill "Survival" None , Skill "Survival" None "Wisdom"
] ]
chaStat :: Stat chaStat :: Stat
chaStat = Stat "Charisma" 10 False chaSkills chaStat = Stat "Charisma" 10 False
chaSkills :: [Skill] chaSkills :: [Skill]
chaSkills = [ Skill "Deception" None chaSkills = [ Skill "Deception" None "Charisma"
, Skill "Intimidation" None , Skill "Intimidation" None "Charisma"
, Skill "Performance" None , Skill "Performance" None "Charisma"
, Skill "Persuasion" None , Skill "Persuasion" None "Charisma"
] ]
testSkills :: [Skill]
testSkills = strSkills ++ dexSkills ++ intSkills ++ wisSkills ++ chaSkills
testSpells :: [Spell] testSpells :: [Spell]
testSpells = [ Spell "Firetesticle" -- spellName testSpells = [ Spell { spellName = "Firetesticle"
3 -- spellLevel , spellLevel = 3
"3 Minutes" -- castingTime , castingTime = "3 Minutes"
50 -- range , range = 50
[Verbal, Somatic] -- components , components = [Verbal, Somatic]
"Instant" -- duration , duration = "Instant"
"Dexterity" -- attackSave , attackSave = "Dexterity"
"Fire" -- damge/effect , damageEffect = "Fire"
"Shoots a huge testicle shaped fireball" -- description , description = "Shoots a huge testicle shaped fireball"
"Conjuration" -- school , school = "Conjuration"
"Cast more of the sodding things" -- atHighLevel , atHighLevel = "Cast more of the sodding things"
}
] ]
testFeatures :: [Feature]
testFeatures = [ Roleplay FeatInfo { featName = "fiets", featDescription = "allows you to ride a 'fiets'" } ]

16
lib/DND/Dice.hs Normal file
View file

@ -0,0 +1,16 @@
module DND.Dice
( rolls
, d20
, advantage
) where
import System.Random
rolls :: RandomGen a => Int -> Int -> a -> [Int]
rolls x y = take x . randomRs (1, y)
d20 :: RandomGen a => a -> Int
d20 = minimum . rolls 1 20
advantage :: RandomGen a => a -> Int
advantage = maximum . rolls 2 20

View file

@ -3,5 +3,5 @@ module DND.Sheet
, module DND.Sheet.Parser , module DND.Sheet.Parser
) where ) where
import DND.Sheet.Content import DND.Sheet.Content
import DND.Sheet.Parser import DND.Sheet.Parser

View file

@ -10,10 +10,11 @@ module DND.Sheet.Content
, Spell(..) , Spell(..)
, SpellComponent(..) , SpellComponent(..)
, Feature(..) , Feature(..)
, FeatInfo(..)
) where ) where
import Data.Aeson ( FromJSON, ToJSON ) import Data.Aeson (FromJSON, ToJSON)
import GHC.Generics ( Generic ) import GHC.Generics (Generic)
instance FromJSON Character instance FromJSON Character
instance ToJSON Character instance ToJSON Character
@ -36,6 +37,12 @@ instance ToJSON ScoreMod
instance FromJSON Spell instance FromJSON Spell
instance ToJSON Spell instance ToJSON Spell
instance FromJSON Feature
instance ToJSON Feature
instance FromJSON FeatInfo
instance ToJSON FeatInfo
instance FromJSON SpellComponent instance FromJSON SpellComponent
instance ToJSON SpellComponent instance ToJSON SpellComponent
@ -46,53 +53,54 @@ data ScoreMod = None
data Character = Character data Character = Character
{ preamble :: Preamble { preamble :: Preamble
, trivia :: Trivia , trivia :: Trivia
, stats :: [Stat] , stats :: [Stat]
, spells :: Maybe [Spell] , skills :: [Skill]
--, feats :: [Feat] , spells :: Maybe [Spell]
, feats :: Maybe [Feature]
} deriving ( Show, Eq, Ord, Generic) } deriving ( Show, Eq, Ord, Generic)
data Preamble = Preamble data Preamble = Preamble
{ charLevel :: Int { charLevel :: Int
, charName :: String , charName :: String
, charRace :: String , charRace :: String
, charClass :: String , charClass :: String
, jackOfAllTrades :: Bool , jackOfAllTrades :: Bool
} deriving ( Show, Eq, Ord, Generic) } deriving ( Show, Eq, Ord, Generic)
data Trivia = Trivia data Trivia = Trivia
{ background :: String { background :: String
, personalityTrait :: String , personalityTrait :: String
, ideals :: String , ideals :: String
, bonds :: String , bonds :: String
, flaws :: String , flaws :: String
, quirk :: String , quirk :: String
} deriving ( Show, Eq, Ord, Generic) } deriving ( Show, Eq, Ord, Generic)
data Skill = Skill data Skill = Skill
{ skillName :: String { skillName :: String
, skillMod :: ScoreMod , skillMod :: ScoreMod
, relatedStat :: String
} deriving ( Show, Eq, Ord, Generic) } deriving ( Show, Eq, Ord, Generic)
data Stat = Stat data Stat = Stat
{ stat :: String { statName :: String
, score :: Int , score :: Int
, proficient :: Bool , proficient :: Bool
, skills :: [Skill]
} deriving ( Show, Eq, Ord, Generic) } deriving ( Show, Eq, Ord, Generic)
data Spell = Spell data Spell = Spell
{ spellName :: String { spellName :: String
, spellLevel :: Int , spellLevel :: Int
, castingTime :: String , castingTime :: String
, range :: Int , range :: Int
, components :: [SpellComponent] , components :: [SpellComponent]
, duration :: String , duration :: String
, attackSave :: String , attackSave :: String
, damageEffect :: String , damageEffect :: String
, description :: String , description :: String
, school :: String , school :: String
, atHighLevel :: String , atHighLevel :: String
} deriving ( Show, Eq, Ord, Generic) } deriving ( Show, Eq, Ord, Generic)
data SpellComponent = Verbal data SpellComponent = Verbal
@ -100,21 +108,25 @@ data SpellComponent = Verbal
| Material | Material
deriving ( Show, Eq, Ord, Generic) deriving ( Show, Eq, Ord, Generic)
data FeatInfo = FeatInfo { featName :: String
, featDescription :: String
} deriving ( Show, Eq, Ord, Generic)
data Feature = StatIncrease data Feature = StatIncrease
{ increase :: [Stat] } { featInfo :: FeatInfo
| SetProficiency , increase :: [Stat] }
{ changeModState :: [ScoreMod] | SetProficiency
, featDescription :: String { featInfo :: FeatInfo
, changeModState :: [ScoreMod]
} }
| SetExpertise | SetExpertise
{ changeModState :: [ScoreMod] { featInfo :: FeatInfo
, featDescription :: String , changeModState :: [ScoreMod]
} }
| AddSpell | AddSpell
{ addSpell :: [Spell] { featInfo :: FeatInfo
, featDescription :: String , addSpell :: [Spell]
} }
| Roleplay | Roleplay
{ featDescription :: String { featInfo :: FeatInfo }
} deriving ( Show, Eq, Ord, Generic)
deriving ( Show, Eq, Ord, Generic)

View file

@ -4,16 +4,17 @@ module DND.Sheet.Parser
, listSkills , listSkills
, createExample , createExample
, getName , getName
, getStat
, listSkillNames , listSkillNames
) where ) where
import Data.Aeson import Control.Monad
import DND.Sheet.Content import Data.Aeson
import DND.Bob(bob) import qualified Data.ByteString.Lazy as B
import Control.Monad
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 Data.Maybe (fromJust)
import DND.Bob (bob)
import DND.Sheet.Content
--getSheet :: FilePath -> IO B.ByteString --getSheet :: FilePath -> IO B.ByteString
--getSheet = B.readFile --getSheet = B.readFile
@ -34,3 +35,6 @@ createExample = flip encodeFile bob
getName :: Character -> String getName :: Character -> String
getName = charName . preamble getName = charName . preamble
getStat :: Character -> String -> Stat
getStat char s = head . filter (\a -> statName a == s) . stats $ char

View file

@ -58,6 +58,7 @@ library
exposed-modules: DND exposed-modules: DND
, DND.Bob , DND.Bob
, DND.Dice
, DND.Sheet , DND.Sheet
, DND.Sheet.Content , DND.Sheet.Content
, DND.Sheet.Parser , DND.Sheet.Parser
@ -66,6 +67,7 @@ library
, aeson , aeson
, bytestring , bytestring
, utf8-string , utf8-string
, random
hs-source-dirs: lib hs-source-dirs: lib