{-# LANGUAGE OverloadedStrings #-}

-- |
-- SPDX-License-Identifier: BSD-3-Clause
--
-- Code for drawing the Swarm logo.
module Swarm.TUI.View.Logo where

import Brick
import Brick.Widgets.Center (centerLayer)
import Data.Text (Text)
import Data.Text qualified as T
import Swarm.Game.Entity.Cosmetic.Assignment
import Swarm.TUI.Model.Name
import Swarm.TUI.View.Attribute.Attr

drawLogo :: Text -> Widget Name
 = Widget Name -> Widget Name
forall n. Widget n -> Widget n
centerLayer (Widget Name -> Widget Name)
-> (Text -> Widget Name) -> Text -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Widget Name] -> Widget Name
forall n. [Widget n] -> Widget n
vBox ([Widget Name] -> Widget Name)
-> (Text -> [Widget Name]) -> Text -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Widget Name) -> [Text] -> [Widget Name]
forall a b. (a -> b) -> [a] -> [b]
map ([Widget Name] -> Widget Name
forall n. [Widget n] -> Widget n
hBox ([Widget Name] -> Widget Name)
-> (Text -> [Widget Name]) -> Text -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> [Widget Name] -> [Widget Name])
-> [Widget Name] -> Text -> [Widget Name]
forall a. (Char -> a -> a) -> a -> Text -> a
T.foldr (\Char
c [Widget Name]
ws -> Char -> Widget Name
drawThing Char
c Widget Name -> [Widget Name] -> [Widget Name]
forall a. a -> [a] -> [a]
: [Widget Name]
ws) []) ([Text] -> [Widget Name])
-> (Text -> [Text]) -> Text -> [Widget Name]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.lines
 where
  drawThing :: Char -> Widget Name
  drawThing :: Char -> Widget Name
drawThing Char
c = AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withAttr (Char -> AttrName
attrFor Char
c) (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ String -> Widget Name
forall n. String -> Widget n
str [Char
c]

  attrFor :: Char -> AttrName
  attrFor :: Char -> AttrName
attrFor Char
c
    | Char
c Char -> String -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` (String
"<>v^" :: String) = AttrName
robotAttr
  attrFor Char
'T' = AttrName
plantAttr
  attrFor Char
'@' = AttrName
rockAttr
  attrFor Char
'~' = AttrName
waterAttr
  attrFor Char
'▒' = AttrName
dirtAttr
  attrFor Char
_ = AttrName
defAttr

  waterAttr :: AttrName
  waterAttr :: AttrName
waterAttr = WorldAttr -> AttrName
getWorldAttrName (WorldAttr -> AttrName) -> WorldAttr -> AttrName
forall a b. (a -> b) -> a -> b
$ (WorldAttr, PreservableColor) -> WorldAttr
forall a b. (a, b) -> a
fst (WorldAttr, PreservableColor)
water

  rockAttr :: AttrName
  rockAttr :: AttrName
rockAttr = WorldAttr -> AttrName
getWorldAttrName (WorldAttr -> AttrName) -> WorldAttr -> AttrName
forall a b. (a -> b) -> a -> b
$ (WorldAttr, PreservableColor) -> WorldAttr
forall a b. (a, b) -> a
fst (WorldAttr, PreservableColor)
rock

  plantAttr :: AttrName
  plantAttr :: AttrName
plantAttr = WorldAttr -> AttrName
getWorldAttrName (WorldAttr -> AttrName) -> WorldAttr -> AttrName
forall a b. (a -> b) -> a -> b
$ (WorldAttr, PreservableColor) -> WorldAttr
forall a b. (a, b) -> a
fst (WorldAttr, PreservableColor)
plant

  dirtAttr :: AttrName
  dirtAttr :: AttrName
dirtAttr = WorldAttr -> AttrName
getWorldAttrName (WorldAttr -> AttrName) -> WorldAttr -> AttrName
forall a b. (a -> b) -> a -> b
$ (WorldAttr, PreservableColor) -> WorldAttr
forall a b. (a, b) -> a
fst (WorldAttr, PreservableColor)
dirt