Skip to content

Commit

Permalink
fix comment, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kostmo committed Sep 6, 2023
1 parent 6407871 commit 7d7a51e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
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
14 changes: 8 additions & 6 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 @@ -23,14 +23,16 @@ mkInterval :: (Ord a, Num a) => a -> UnitInterval a
mkInterval = UnitInterval . max 0 . min 1

-- | Since '(!!)' is partial, here is "proof" that it is safe:
-- If 'dutyCycleRatio' is 1, then the maximum value of 'dutyCycleAttrIdx' is
-- -- one less than the length of 'meterAttributeNames' (i.e., a valid index).
-- If "alpha" is its maximum value of @1@, then the maximum value
-- of the computed index shall be one less than the length of the
-- list (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))

0 comments on commit 7d7a51e

Please sign in to comment.