From 25a1c5ade32ee0dca41b8057f053972e4ab816d7 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sat, 8 Feb 2020 17:24:27 -0500 Subject: Factor out an EntityAttributes type Factor out a new EntityAttributes type from some of the methods of the Entity class, to avoid the proliferation of 1-argument boolean methods on the entity class that always have to be forwarded through the Entity instance for SomeEntity if they have defaults (forgetting to do which has wasted tons of my time up to this point). Currently blocksVision, blocksObject, and collision are all in there. --- src/Xanthous/Entities/Environment.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/Xanthous/Entities/Environment.hs') diff --git a/src/Xanthous/Entities/Environment.hs b/src/Xanthous/Entities/Environment.hs index 430ce1b7a99e..b45a91eabed2 100644 --- a/src/Xanthous/Entities/Environment.hs +++ b/src/Xanthous/Entities/Environment.hs @@ -29,6 +29,7 @@ import Data.Aeson.Generic.DerivingVia -------------------------------------------------------------------------------- import Xanthous.Entities.Draw.Util import Xanthous.Data +import Xanthous.Data.Entities import Xanthous.Game.State import Xanthous.Util.QuickCheck -------------------------------------------------------------------------------- @@ -48,7 +49,9 @@ instance FromJSON Wall where instance Brain Wall where step = brainVia Brainless instance Entity Wall where - blocksVision _ = True + entityAttributes _ = defaultEntityAttributes + & blocksVision .~ True + & blocksObject .~ True description _ = "a wall" entityChar _ = "┼" @@ -93,7 +96,8 @@ instance Draw Door where instance Brain Door where step = brainVia Brainless instance Entity Door where - blocksVision = not . view open + entityAttributes door = defaultEntityAttributes + & blocksVision .~ not (door ^. open) description door | door ^. open = "an open door" | otherwise = "a closed door" entityChar _ = "d" @@ -127,7 +131,6 @@ newtype GroundMessage = GroundMessage Text instance Brain GroundMessage where step = brainVia Brainless instance Entity GroundMessage where - blocksVision = const False description = const "a message on the ground. Press r. to read it." entityChar = const "≈" entityCollision = const Nothing @@ -150,7 +153,6 @@ instance Draw Staircase where draw DownStaircase = str ">" instance Entity Staircase where - blocksVision = const False description UpStaircase = "a staircase leading upwards" description DownStaircase = "a staircase leading downwards" entityChar UpStaircase = "<" -- cgit 1.4.1