diff options
author | Griffin Smith <root@gws.fyi> | 2020-02-08T22·24-0500 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2020-02-08T22·24-0500 |
commit | 25a1c5ade32ee0dca41b8057f053972e4ab816d7 (patch) | |
tree | 31d252cb624ed7d6e97d542f6689234791896355 /src/Xanthous/Entities/Environment.hs | |
parent | 782d3880c8da35b48276a874d396d24ca6dc7004 (diff) |
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.
Diffstat (limited to 'src/Xanthous/Entities/Environment.hs')
-rw-r--r-- | src/Xanthous/Entities/Environment.hs | 10 |
1 files changed, 6 insertions, 4 deletions
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 = "<" |