about summary refs log tree commit diff
path: root/src/Xanthous/Game/Draw.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-10-16T16·10-0400
committerGriffin Smith <root@gws.fyi>2019-10-16T16·10-0400
commit87fedcb6c9bc251a5a23a632ccf985b674b84bc7 (patch)
tree739fab972e9ae8af9849f3e8f65dad0f5bf13c7d /src/Xanthous/Game/Draw.hs
parent4882350f5d7e54a6ae5c8760f2510273dae19c60 (diff)
Add draw priority
Rather than blindly taking one entity from the list when we have
multiple entities on the same tile, add a `drawPriority` method to the
Draw typeclass which allows individual entities to request to be drawn
on top - this avoids the "noodles floating over your head" bug we saw
before.
Diffstat (limited to 'src/Xanthous/Game/Draw.hs')
-rw-r--r--src/Xanthous/Game/Draw.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Xanthous/Game/Draw.hs b/src/Xanthous/Game/Draw.hs
index 24c177513ed1..b7d7a76956ed 100644
--- a/src/Xanthous/Game/Draw.hs
+++ b/src/Xanthous/Game/Draw.hs
@@ -4,12 +4,12 @@ module Xanthous.Game.Draw
   ) where
 --------------------------------------------------------------------------------
 import           Xanthous.Prelude
-import           Brick hiding (loc)
+import           Brick hiding (loc, on)
 import           Brick.Widgets.Border
 import           Brick.Widgets.Border.Style
 import           Brick.Widgets.Edit
 --------------------------------------------------------------------------------
-import           Xanthous.Data (Position'(..), type Position, x, y, loc)
+import           Xanthous.Data
 import           Xanthous.Data.EntityMap (EntityMap, atPosition)
 import qualified Xanthous.Data.EntityMap as EntityMap
 import           Xanthous.Entities
@@ -68,7 +68,10 @@ drawEntities canRenderPos allEnts
       | canRenderPos pos
       = let neighbors = EntityMap.neighbors pos allEnts
         in maybe (str " ") (drawWithNeighbors neighbors)
-           $ allEnts ^? atPosition pos . folded
+           $ maximumByOf
+             (atPosition pos . folded)
+             (compare `on` drawPriority)
+             allEnts
       | otherwise = str " "
 
 drawMap :: GameState -> Widget Name