-- | The type of definitions of screen layout and features.
module Game.LambdaHack.Client.UI.Content.Screen
  ( ScreenContent(..), makeData
#ifdef EXPOSE_INTERNAL
    -- * Internal operations
  , validateSingle
#endif
  ) where

import Prelude ()

import Game.LambdaHack.Core.Prelude

import qualified Data.EnumMap.Strict as EM
import qualified Data.Text as T

import Game.LambdaHack.Definition.Defs

-- | Screen layout and features definition.
data ScreenContent = ScreenContent
  { ScreenContent -> X
rwidth          :: X         -- ^ screen width
  , ScreenContent -> X
rheight         :: Y         -- ^ screen height
  , ScreenContent -> Text
rmainMenuArt    :: Text      -- ^ the ASCII art for the main menu
  , ScreenContent -> [String]
rintroScreen    :: [String]  -- ^ the intro screen (first help screen) text
  , ScreenContent -> [String]
rmoveKeysScreen :: [String]  -- ^ the fixed move key help blurb
  , ScreenContent -> EnumMap Char Text
rapplyVerbMap   :: EM.EnumMap Char T.Text
                                 -- ^ verbs to use for apply actions
  }

-- | Catch invalid rule kind definitions.
validateSingle :: ScreenContent -> [Text]
validateSingle :: ScreenContent -> [Text]
validateSingle ScreenContent{Text
rmainMenuArt :: Text
rmainMenuArt :: ScreenContent -> Text
rmainMenuArt} =
  let ts :: [Text]
ts = Text -> [Text]
T.lines Text
rmainMenuArt
      tsNot80 :: [Text]
tsNot80 = (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter ((X -> X -> Bool
forall a. Eq a => a -> a -> Bool
/= 80) (X -> Bool) -> (Text -> X) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> X
T.length) [Text]
ts
  in case [Text]
tsNot80 of
     [] -> [ "rmainMenuArt doesn't have at least 24 lines, but "
             Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> X -> Text
forall a. Show a => a -> Text
tshow ([Text] -> X
forall a. [a] -> X
length [Text]
ts)
           | [Text] -> X
forall a. [a] -> X
length [Text]
ts X -> X -> Bool
forall a. Ord a => a -> a -> Bool
< 24]
     tNot80 :: Text
tNot80 : _ ->
       ["rmainMenuArt has a line with length other than 80:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tNot80]

makeData :: ScreenContent -> ScreenContent
makeData :: ScreenContent -> ScreenContent
makeData sc :: ScreenContent
sc =
  let singleOffenders :: [Text]
singleOffenders = ScreenContent -> [Text]
validateSingle ScreenContent
sc
  in Bool -> ScreenContent -> ScreenContent
forall a. (?callStack::CallStack) => Bool -> a -> a
assert ([Text] -> Bool
forall a. [a] -> Bool
null [Text]
singleOffenders
             Bool -> (String, [Text]) -> Bool
forall a. Show a => Bool -> a -> Bool
`blame` "Screen Content" String -> String -> String
forall a. [a] -> [a] -> [a]
++ ": some content items not valid"
             String -> [Text] -> (String, [Text])
forall v. String -> v -> (String, v)
`swith` [Text]
singleOffenders)
     ScreenContent
sc