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/RawTypes.hs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/Xanthous/Entities/RawTypes.hs') diff --git a/src/Xanthous/Entities/RawTypes.hs b/src/Xanthous/Entities/RawTypes.hs index 88087a5dab61..1546d85e4562 100644 --- a/src/Xanthous/Entities/RawTypes.hs +++ b/src/Xanthous/Entities/RawTypes.hs @@ -1,6 +1,6 @@ {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE DuplicateRecordFields #-} - +-------------------------------------------------------------------------------- module Xanthous.Entities.RawTypes ( CreatureType(..) , ItemType(..) @@ -9,19 +9,20 @@ module Xanthous.Entities.RawTypes , HasName(..) , HasDescription(..) , HasLongDescription(..) - , HasChar(..) , HasMaxHitpoints(..) , HasFriendly(..) , _Creature ) where - +-------------------------------------------------------------------------------- import Xanthous.Prelude +import Test.QuickCheck +import Test.QuickCheck.Arbitrary.Generic import Data.Aeson.Generic.DerivingVia -import Data.Aeson (FromJSON) +import Data.Aeson (ToJSON, FromJSON) import Data.Word - -import Xanthous.Entities (EntityChar) - +-------------------------------------------------------------------------------- +import Xanthous.Entities (EntityChar, HasChar(..)) +-------------------------------------------------------------------------------- data CreatureType = CreatureType { _name :: Text , _description :: Text @@ -35,7 +36,7 @@ data CreatureType = CreatureType via WithOptions '[ FieldLabelModifier '[Drop 1] ] CreatureType makeFieldsNoPrefix ''CreatureType - +-------------------------------------------------------------------------------- data ItemType = ItemType { _name :: Text , _description :: Text @@ -43,12 +44,15 @@ data ItemType = ItemType , _char :: EntityChar } deriving stock (Show, Eq, Generic) - deriving anyclass (NFData) - deriving (FromJSON) + deriving anyclass (NFData, CoArbitrary, Function) + deriving (ToJSON, FromJSON) via WithOptions '[ FieldLabelModifier '[Drop 1] ] ItemType makeFieldsNoPrefix ''ItemType +instance Arbitrary ItemType where + arbitrary = genericArbitrary + data EntityRaw = Creature CreatureType | Item ItemType -- cgit 1.4.1