diff options
author | Griffin Smith <root@gws.fyi> | 2019-09-19T17·56-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-09-19T17·56-0400 |
commit | 62a2e05ef222dd69263b819a400a83f8910816f9 (patch) | |
tree | b81ee35bcc1f6f20290e6347e5b6ceff8a9fff12 /src/Xanthous/Entities/Character.hs | |
parent | 15895c69fe8f1415f45fe33f7b3d564f4239496e (diff) |
Add items and inventory
Add a new "Item" entity, which pulls from the previously-existent ItemType raw, and add a "PickUp" command which takes the (currently *only*) item off the ground and puts it into the inventory.
Diffstat (limited to 'src/Xanthous/Entities/Character.hs')
-rw-r--r-- | src/Xanthous/Entities/Character.hs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Xanthous/Entities/Character.hs b/src/Xanthous/Entities/Character.hs index 246e55071cb8..3b2b320004e2 100644 --- a/src/Xanthous/Entities/Character.hs +++ b/src/Xanthous/Entities/Character.hs @@ -1,23 +1,30 @@ +{-# LANGUAGE TemplateHaskell #-} module Xanthous.Entities.Character ( Character(..) , mkCharacter + , pickUpItem ) where -------------------------------------------------------------------------------- import Xanthous.Prelude import Test.QuickCheck +import Test.QuickCheck.Instances.Vector () +import Test.QuickCheck.Arbitrary.Generic import Brick -------------------------------------------------------------------------------- import Xanthous.Entities +import Xanthous.Entities.Item -------------------------------------------------------------------------------- data Character = Character - deriving stock (Show, Eq, Ord, Generic) + { _inventory :: !(Vector Item) + } + deriving stock (Show, Eq, Generic) deriving anyclass (CoArbitrary, Function) +makeLenses ''Character scrollOffset :: Int scrollOffset = 5 --- deriving Draw via (DrawCharacter "@" Character) instance Draw Character where draw _ = visibleRegion rloc rreg $ str "@" where @@ -28,7 +35,13 @@ instance Entity Character where blocksVision _ = False instance Arbitrary Character where - arbitrary = pure Character + arbitrary = genericArbitrary mkCharacter :: Character mkCharacter = Character + { _inventory = mempty + } + +pickUpItem :: Item -> Character -> Character +pickUpItem item = inventory %~ (item <|) + |