From 62a2e05ef222dd69263b819a400a83f8910816f9 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Thu, 19 Sep 2019 13:56:14 -0400 Subject: 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. --- src/Xanthous/Entities/Item.hs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Xanthous/Entities/Item.hs (limited to 'src/Xanthous/Entities/Item.hs') diff --git a/src/Xanthous/Entities/Item.hs b/src/Xanthous/Entities/Item.hs new file mode 100644 index 000000000000..baf4be2f5426 --- /dev/null +++ b/src/Xanthous/Entities/Item.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE TemplateHaskell #-} +module Xanthous.Entities.Item + ( Item(..) + , itemType + , newWithType + ) where +-------------------------------------------------------------------------------- +import Xanthous.Prelude +import Test.QuickCheck +import Data.Aeson (ToJSON, FromJSON) +import Data.Aeson.Generic.DerivingVia +-------------------------------------------------------------------------------- +import Xanthous.Entities.RawTypes hiding (Item) +import Xanthous.Entities (Draw(..), Entity(..), DrawRawChar(..)) +-------------------------------------------------------------------------------- + +data Item = Item + { _itemType :: ItemType + } + deriving stock (Eq, Show, Generic) + deriving anyclass (CoArbitrary, Function) + deriving Draw via DrawRawChar "_itemType" Item + deriving (ToJSON, FromJSON) + via WithOptions '[ FieldLabelModifier '[Drop 1] ] + Item +makeLenses ''Item + +instance Arbitrary Item where + arbitrary = Item <$> arbitrary + +instance Entity Item where + blocksVision _ = False + +newWithType :: ItemType -> Item +newWithType = Item -- cgit 1.4.1