about summary refs log tree commit diff
path: root/src/Xanthous/Entities
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-11-30T03·59-0500
committerGriffin Smith <root@gws.fyi>2019-11-30T03·59-0500
commit8a1235c3dcf7fe69b2e2ea3eea326858d26d38b9 (patch)
tree398c6dce549602c9890fbded64e3bdf2646b2a1f /src/Xanthous/Entities
parent7d8ce026a2acc5a4d208110750be188f0ce5591c (diff)
Use menus for combat and picking up items
Refactor a bunch of stuff around to allow for polymorphically surfacing
an EntityChar for all entities, and use this to write a generic
`entityMenu` function, which generates a menu from the chars of a list
of entities - and use that to fully implement (removing `undefined`)
menus for both attacking and picking things up when there are multiple
entities on the relevant tile.
Diffstat (limited to 'src/Xanthous/Entities')
-rw-r--r--src/Xanthous/Entities/Character.hs3
-rw-r--r--src/Xanthous/Entities/Creature.hs2
-rw-r--r--src/Xanthous/Entities/Entities.hs2
-rw-r--r--src/Xanthous/Entities/Environment.hs12
-rw-r--r--src/Xanthous/Entities/Item.hs10
-rw-r--r--src/Xanthous/Entities/RawTypes.hs3
-rw-r--r--src/Xanthous/Entities/Raws.hs2
7 files changed, 12 insertions, 22 deletions
diff --git a/src/Xanthous/Entities/Character.hs b/src/Xanthous/Entities/Character.hs
index cc04340f6e24..22589252acce 100644
--- a/src/Xanthous/Entities/Character.hs
+++ b/src/Xanthous/Entities/Character.hs
@@ -27,7 +27,7 @@ import Data.Aeson.Generic.DerivingVia
 import Data.Aeson (ToJSON, FromJSON)
 import Data.Coerce (coerce)
 --------------------------------------------------------------------------------
-import Xanthous.Entities
+import Xanthous.Game.State
 import Xanthous.Entities.Item
 import Xanthous.Data (TicksPerTile, Hitpoints, Per, Ticks, (|*|), positioned)
 --------------------------------------------------------------------------------
@@ -68,6 +68,7 @@ instance Brain Character where
 instance Entity Character where
   blocksVision _ = False
   description _ = "yourself"
+  entityChar _ = "@"
 
 instance Arbitrary Character where
   arbitrary = genericArbitrary
diff --git a/src/Xanthous/Entities/Creature.hs b/src/Xanthous/Entities/Creature.hs
index 11cad1ce6b8b..de9122746bcf 100644
--- a/src/Xanthous/Entities/Creature.hs
+++ b/src/Xanthous/Entities/Creature.hs
@@ -35,7 +35,7 @@ import           Data.Aeson.Generic.DerivingVia
 import           Data.Aeson (ToJSON, FromJSON)
 --------------------------------------------------------------------------------
 import           Xanthous.Entities.RawTypes hiding (Creature, description)
-import           Xanthous.Entities (Draw(..), DrawRawCharPriority(..))
+import           Xanthous.Game.State
 import           Xanthous.Data
 --------------------------------------------------------------------------------
 
diff --git a/src/Xanthous/Entities/Entities.hs b/src/Xanthous/Entities/Entities.hs
index 410a6514ae4f..7e41fc8b7b3a 100644
--- a/src/Xanthous/Entities/Entities.hs
+++ b/src/Xanthous/Entities/Entities.hs
@@ -9,7 +9,6 @@ import           Test.QuickCheck
 import qualified Test.QuickCheck.Gen as Gen
 import           Data.Aeson
 --------------------------------------------------------------------------------
-import           Xanthous.Entities (Entity(..), SomeEntity(..))
 import           Xanthous.Entities.Character
 import           Xanthous.Entities.Item
 import           Xanthous.Entities.Creature
@@ -46,6 +45,7 @@ deriving via WithOptions '[ FieldLabelModifier '[Drop 1] ] GameState
 instance Entity SomeEntity where
   blocksVision (SomeEntity ent) = blocksVision ent
   description (SomeEntity ent) = description ent
+  entityChar (SomeEntity ent) = entityChar ent
 
 instance Function SomeEntity where
   function = functionJSON
diff --git a/src/Xanthous/Entities/Environment.hs b/src/Xanthous/Entities/Environment.hs
index 811919963122..8baa07650f7c 100644
--- a/src/Xanthous/Entities/Environment.hs
+++ b/src/Xanthous/Entities/Environment.hs
@@ -14,17 +14,9 @@ import Brick.Widgets.Border.Style (unicode)
 import Brick.Types (Edges(..))
 import Data.Aeson
 --------------------------------------------------------------------------------
-import Xanthous.Entities
-       ( Draw(..)
-       , entityIs
-       , Entity(..)
-       , SomeEntity
-       , Brain(..)
-       , Brainless(..)
-       , brainVia
-       )
 import Xanthous.Entities.Draw.Util
 import Xanthous.Data
+import Xanthous.Game.State
 --------------------------------------------------------------------------------
 
 data Wall = Wall
@@ -45,6 +37,7 @@ instance Brain Wall where step = brainVia Brainless
 instance Entity Wall where
   blocksVision _ = True
   description _ = "a wall"
+  entityChar _ = "┼"
 
 instance Arbitrary Wall where
   arbitrary = pure Wall
@@ -90,3 +83,4 @@ instance Brain Door where step = brainVia Brainless
 instance Entity Door where
   blocksVision = not . view open
   description _ = "a door"
+  entityChar _ = "d"
diff --git a/src/Xanthous/Entities/Item.hs b/src/Xanthous/Entities/Item.hs
index ddd387af8c78..465110069c1d 100644
--- a/src/Xanthous/Entities/Item.hs
+++ b/src/Xanthous/Entities/Item.hs
@@ -15,14 +15,7 @@ import           Data.Aeson.Generic.DerivingVia
 --------------------------------------------------------------------------------
 import           Xanthous.Entities.RawTypes hiding (Item, description, isEdible)
 import qualified Xanthous.Entities.RawTypes as Raw
-import           Xanthous.Entities
-                 ( Draw(..)
-                 , Entity(..)
-                 , DrawRawChar(..)
-                 , Brain(..)
-                 , Brainless(..)
-                 , brainVia
-                 )
+import           Xanthous.Game.State
 --------------------------------------------------------------------------------
 
 data Item = Item
@@ -47,6 +40,7 @@ instance Arbitrary Item where
 instance Entity Item where
   blocksVision _ = False
   description = view $ itemType . Raw.description
+  entityChar = view $ itemType . Raw.char
 
 newWithType :: ItemType -> Item
 newWithType = Item
diff --git a/src/Xanthous/Entities/RawTypes.hs b/src/Xanthous/Entities/RawTypes.hs
index 09b250fb310d..f715f8743ab1 100644
--- a/src/Xanthous/Entities/RawTypes.hs
+++ b/src/Xanthous/Entities/RawTypes.hs
@@ -10,6 +10,7 @@ module Xanthous.Entities.RawTypes
 
   , _Creature
     -- * Lens classes
+  , HasChar(..)
   , HasName(..)
   , HasDescription(..)
   , HasLongDescription(..)
@@ -27,9 +28,9 @@ import Test.QuickCheck.Arbitrary.Generic
 import Data.Aeson.Generic.DerivingVia
 import Data.Aeson (ToJSON, FromJSON)
 --------------------------------------------------------------------------------
-import Xanthous.Entities (EntityChar, HasChar(..))
 import Xanthous.Messages (Message(..))
 import Xanthous.Data (TicksPerTile, Hitpoints)
+import Xanthous.Data.EntityChar
 --------------------------------------------------------------------------------
 data CreatureType = CreatureType
   { _name         :: !Text
diff --git a/src/Xanthous/Entities/Raws.hs b/src/Xanthous/Entities/Raws.hs
index 9b7d63c6c4c5..d4cae7ccc299 100644
--- a/src/Xanthous/Entities/Raws.hs
+++ b/src/Xanthous/Entities/Raws.hs
@@ -14,7 +14,7 @@ import           Xanthous.Prelude
 import           System.FilePath.Posix
 --------------------------------------------------------------------------------
 import           Xanthous.Entities.RawTypes
-import           Xanthous.Entities
+import           Xanthous.Game.State
 import qualified Xanthous.Entities.Creature as Creature
 import qualified Xanthous.Entities.Item as Item
 import           Xanthous.AI.Gormlak ()