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.
This commit is contained in:
Griffin Smith 2019-10-16 12:10:59 -04:00
parent 4882350f5d
commit 87fedcb6c9
5 changed files with 30 additions and 6 deletions

View file

@ -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