Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle Robot activity counts in F2 menu #1490

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Swarm/TUI/View/Attribute/Attr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ module Swarm.TUI.View.Attribute.Attr (
customEditFocusedAttr,
) where

import Data.List.NonEmpty (NonEmpty (..))
import Data.List.NonEmpty qualified as NE
import Brick
import Brick.Forms
import Brick.Widgets.Dialog
import Brick.Widgets.Edit qualified as E
import Brick.Widgets.List hiding (reverse)
import Data.Bifunctor (bimap)
import Data.Colour.Palette.BrewerSet
import Data.List.NonEmpty (NonEmpty (..))
import Data.List.NonEmpty qualified as NE
import Data.Maybe (fromMaybe)
import Data.Text (unpack)
import Graphics.Vty qualified as V
import Swarm.Game.Display (Attribute (..))
import Swarm.TUI.View.Attribute.Util
import Data.Maybe (fromMaybe)

toAttrName :: Attribute -> AttrName
toAttrName = \case
Expand Down Expand Up @@ -149,9 +149,9 @@ activityMeterPrefix = attrName "activityMeter"

activityMeterAttributes :: NonEmpty (AttrName, V.Attr)
activityMeterAttributes =
NE.zip indices $ fromMaybe (pure $ bg V.black) $ NE.nonEmpty brewers
NE.zip indices $ fromMaybe (pure $ bg V.black) $ NE.nonEmpty brewers
where
indices = NE.map ((activityMeterPrefix <>) . attrName . show) $ (0 :: Int) :| [1..]
indices = NE.map ((activityMeterPrefix <>) . attrName . show) $ (0 :: Int) :| [1 ..]
brewers = map bgWithAutoForeground $ reverse $ brewerSet RdYlGn 7

meterAttributeNames :: NonEmpty AttrName
Expand Down
9 changes: 5 additions & 4 deletions src/Swarm/Util/UnitInterval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module Swarm.Util.UnitInterval (
safeIndex,
) where

import Prelude hiding ((!!))
import Data.List.NonEmpty (NonEmpty, (!!))
import Prelude hiding ((!!))

newtype UnitInterval a = UnitInterval
{ getValue :: a
Expand All @@ -27,10 +27,11 @@ mkInterval = UnitInterval . max 0 . min 1
-- -- one less than the length of 'meterAttributeNames' (i.e., a valid index).
--
-- See also: 'Swarm.Util.indexWrapNonEmpty'.
safeIndex :: RealFrac a =>
safeIndex ::
RealFrac a =>
-- | alpha
UnitInterval a ->
NonEmpty b ->
b
NonEmpty b ->
b
safeIndex (UnitInterval alpha) xs =
xs !! floor (alpha * fromIntegral (length xs - 1))