Skip to content

Commit

Permalink
plumb 'displayObscured' property
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Dec 17, 2023
1 parent ec9147b commit de82038
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Swarm/Game/Display.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module Swarm.Game.Display (
curOrientation,
displayAttr,
displayPriority,
displayObscured,
invisible,

-- ** Rendering
Expand Down Expand Up @@ -85,6 +86,7 @@ data Display = Display
, _curOrientation :: Maybe Direction
, _displayAttr :: Attribute
, _displayPriority :: Priority
, _displayObscured :: Bool
, _invisible :: Bool
}
deriving (Eq, Ord, Show, Generic, Hashable)
Expand Down Expand Up @@ -117,6 +119,11 @@ displayAttr :: Lens' Display Attribute
-- on top of lower.
displayPriority :: Lens' Display Priority

-- | True for static. This field is a workaround to allow robot-occupied
-- cells to take on ambient background; it distinguishes displays
-- that have an adoptable background from displays that do not.
displayObscured :: Lens' Display Bool

-- | Whether the entity is currently invisible.
invisible :: Lens' Display Bool

Expand All @@ -140,6 +147,7 @@ instance FromJSONE Display Display where
<*> v .:? "curOrientation" .!= (defD ^. curOrientation)
<*> (v .:? "attr") .!= (defD ^. displayAttr)
<*> v .:? "priority" .!= (defD ^. displayPriority)
<*> pure False
<*> v .:? "invisible" .!= (defD ^. invisible)
where
validateChar c =
Expand Down Expand Up @@ -194,6 +202,7 @@ defaultEntityDisplay c =
, _curOrientation = Nothing
, _displayAttr = AEntity
, _displayPriority = 1
, _displayObscured = False
, _invisible = False
}

Expand All @@ -217,6 +226,7 @@ defaultRobotDisplay =
, _curOrientation = Nothing
, _displayAttr = ARobot
, _displayPriority = 10
, _displayObscured = False
, _invisible = False
}

Expand Down
2 changes: 2 additions & 0 deletions src/Swarm/TUI/View/CellDisplay.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Swarm.Game.Display (
defaultEntityDisplay,
displayAttr,
displayChar,
displayObscured,
displayPriority,
hidden,
)
Expand Down Expand Up @@ -200,6 +201,7 @@ displayStatic s =
defaultEntityDisplay (staticChar s)
& displayPriority .~ maxBound -- Static has higher priority than anything else
& displayAttr .~ AEntity
& displayObscured .~ True

-- | Given a value from 0--15, considered as 4 bits, pick the
-- character with the corresponding quarter pixels turned on.
Expand Down

0 comments on commit de82038

Please sign in to comment.