Skip to content

Commit

Permalink
Restyled by fourmolu (#2238)
Browse files Browse the repository at this point in the history
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
github-actions[bot] and restyled-commits authored Dec 27, 2024
1 parent 14ed1fd commit 5bba7f9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/swarm-scenario/Swarm/Game/Scenario/Style.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Swarm.Game.Scenario.Style where
import Codec.Picture (PixelRGBA8 (..))
import Data.Aeson
import Data.Colour.Palette.Types (Kolor)
import Data.Colour.SRGB (RGB (..), sRGB24reads, toSRGB24, sRGB24show)
import Data.Colour.SRGB (RGB (..), sRGB24reads, sRGB24show, toSRGB24)
import Data.Colour.SRGB.Linear (toRGB)
import Data.Set (Set)
import Data.Text qualified as T
Expand Down Expand Up @@ -42,7 +42,7 @@ instance ToJSON StyleFlag where

-- | A color, parsed from hexadecimal notation. May include a leading
-- hash symbol (see 'Data.Colour.SRGB.sRGB24read').
newtype HexColor = HexColor { getHexColor :: Kolor }
newtype HexColor = HexColor {getHexColor :: Kolor}
deriving (Eq, Show, Generic)

instance Ord HexColor where
Expand All @@ -54,13 +54,13 @@ instance Ord HexColor where
-- purposes of an Ord instance, it doesn't matter: we just want a
-- consistent way to put a total ordering on colors as fast as
-- possible.
compare (HexColor (toRGB -> RGB r1 g1 b1)) (HexColor (toRGB -> RGB r2 g2 b2))
= compare r1 r2 <> compare g1 g2 <> compare b1 b2
compare (HexColor (toRGB -> RGB r1 g1 b1)) (HexColor (toRGB -> RGB r2 g2 b2)) =
compare r1 r2 <> compare g1 g2 <> compare b1 b2

instance FromJSON HexColor where
parseJSON = withText "hex color" $ \t ->
case sRGB24reads (T.unpack t) of
((c, _):_) -> pure $ HexColor c
((c, _) : _) -> pure $ HexColor c
_ -> fail $ "Could not parse hex color '" ++ T.unpack t ++ "'"

instance ToJSON HexColor where
Expand Down

0 comments on commit 5bba7f9

Please sign in to comment.