~sjm/builds-character

073cb3c9121b33b595d8a323edabfc723b03c460 — Sam Marshall 2 years ago de38ba5
chore: add attribute data

TIKT-123. Describe change further, add context and reasons for decisions.
3 files changed, 74 insertions(+), 0 deletions(-)

A src/CharSheet/Attributes.purs
M src/CharSheet/Class.purs
A src/Random/Dice.purs
A src/CharSheet/Attributes.purs => src/CharSheet/Attributes.purs +50 -0
@@ 0,0 1,50 @@
module CharSheet.Attributes (Attributes, fresh, empty, _str, _dex, _con, _int, _wis, _cha) where

import Prelude
import Data.Lens as L
import Effect (Effect)
import Random.Dice as RD

type Attributes
  = { str :: Int
    , dex :: Int
    , con :: Int
    , int :: Int
    , wis :: Int
    , cha :: Int
    }

manual :: Int -> Int -> Int -> Int -> Int -> Int -> Attributes
manual str dex con int wis cha = { str, dex, con, int, wis, cha }

empty :: Attributes
empty = manual 0 0 0 0 0 0

fresh :: Effect Attributes
fresh = do
  (RD.Roll str _) <- RD.threeDSix
  (RD.Roll dex _) <- RD.threeDSix
  (RD.Roll con _) <- RD.threeDSix
  (RD.Roll int _) <- RD.threeDSix
  (RD.Roll wis _) <- RD.threeDSix
  (RD.Roll cha _) <- RD.threeDSix
  pure $ manual str dex con int wis cha

-- lenses
_str :: L.Lens' Attributes Int
_str = L.lens _.str $ _ { str = _ }

_dex :: L.Lens' Attributes Int
_dex = L.lens _.dex $ _ { dex = _ }

_con :: L.Lens' Attributes Int
_con = L.lens _.con $ _ { con = _ }

_int :: L.Lens' Attributes Int
_int = L.lens _.int $ _ { int = _ }

_wis :: L.Lens' Attributes Int
_wis = L.lens _.wis $ _ { wis = _ }

_cha :: L.Lens' Attributes Int
_cha = L.lens _.cha $ _ { cha = _ }

M src/CharSheet/Class.purs => src/CharSheet/Class.purs +3 -0
@@ 16,6 16,9 @@ data Class
  -- allow the initial class to be undecided to avoid having to wrap in a Maybe
  | Undecided

instance showCharSheetClass :: Show Class where
  show = toString

_expert :: String
_expert = "expert"


A src/Random/Dice.purs => src/Random/Dice.purs +21 -0
@@ 0,0 1,21 @@
module Random.Dice where

import Prelude

import Effect.Random (randomInt)
import Effect (Effect)

data Result = Roll Int (Array Int)

dSix :: Effect Result
dSix = do
  x <- randomInt 1 6
  pure $ Roll x [x]

threeDSix :: Effect Result
threeDSix = do
  (Roll a _) <- dSix
  (Roll b _) <- dSix
  (Roll c _) <- dSix

  pure $ Roll (a + b + c) [a, b, c]