module Game.LambdaHack.Client.UI.Content.Screen
( ScreenContent(..), emptyScreenContent, makeData
#ifdef EXPOSE_INTERNAL
, emptyScreenContentRaw, validateSingle
#endif
) where
import Prelude ()
import Game.LambdaHack.Core.Prelude
import qualified Data.ByteString as BS
import qualified Data.EnumMap.Strict as EM
import qualified Data.Text as T
import Game.LambdaHack.Content.ItemKind (ItemKind)
import qualified Game.LambdaHack.Content.RuleKind as RK
import Game.LambdaHack.Definition.Defs
data ScreenContent = ScreenContent
{ ScreenContent -> X
rwidth :: X
, ScreenContent -> X
rheight :: Y
, ScreenContent -> String
rwebAddress :: String
, ScreenContent -> ([String], [[String]])
rintroScreen :: ([String], [[String]])
, ScreenContent -> EnumMap (ContentSymbol ItemKind) Text
rapplyVerbMap :: EM.EnumMap (ContentSymbol ItemKind) T.Text
, ScreenContent -> [(String, ByteString)]
rFontFiles :: [(FilePath, BS.ByteString)]
}
emptyScreenContentRaw :: ScreenContent
emptyScreenContentRaw :: ScreenContent
emptyScreenContentRaw = ScreenContent :: X
-> X
-> String
-> ([String], [[String]])
-> EnumMap (ContentSymbol ItemKind) Text
-> [(String, ByteString)]
-> ScreenContent
ScreenContent { rwidth :: X
rwidth = X
5
, rheight :: X
rheight = X
5
, rwebAddress :: String
rwebAddress = String
""
, rintroScreen :: ([String], [[String]])
rintroScreen = ([], [])
, rapplyVerbMap :: EnumMap (ContentSymbol ItemKind) Text
rapplyVerbMap = EnumMap (ContentSymbol ItemKind) Text
forall k a. EnumMap k a
EM.empty
, rFontFiles :: [(String, ByteString)]
rFontFiles = []
}
emptyScreenContent :: ScreenContent
emptyScreenContent :: ScreenContent
emptyScreenContent =
Bool -> ScreenContent -> ScreenContent
forall a. (?callStack::CallStack) => Bool -> a -> a
assert ([Text] -> Bool
forall a. [a] -> Bool
null ([Text] -> Bool) -> [Text] -> Bool
forall a b. (a -> b) -> a -> b
$ RuleContent -> ScreenContent -> [Text]
validateSingle RuleContent
RK.emptyRuleContent ScreenContent
emptyScreenContentRaw)
ScreenContent
emptyScreenContentRaw
validateSingle :: RK.RuleContent -> ScreenContent -> [Text]
validateSingle :: RuleContent -> ScreenContent -> [Text]
validateSingle RuleContent
corule ScreenContent{X
String
[(String, ByteString)]
([String], [[String]])
EnumMap (ContentSymbol ItemKind) Text
rFontFiles :: [(String, ByteString)]
rapplyVerbMap :: EnumMap (ContentSymbol ItemKind) Text
rintroScreen :: ([String], [[String]])
rwebAddress :: String
rheight :: X
rwidth :: X
rFontFiles :: ScreenContent -> [(String, ByteString)]
rapplyVerbMap :: ScreenContent -> EnumMap (ContentSymbol ItemKind) Text
rintroScreen :: ScreenContent -> ([String], [[String]])
rwebAddress :: ScreenContent -> String
rheight :: ScreenContent -> X
rwidth :: ScreenContent -> X
..} =
(let tsGt80 :: [Text]
tsGt80 = (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter ((X -> X -> Bool
forall a. Ord a => a -> a -> Bool
> X
80) (X -> Bool) -> (Text -> X) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> X
T.length) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ (String -> Text) -> [String] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map String -> Text
T.pack [String
rwebAddress]
in case [Text]
tsGt80 of
[] -> []
Text
tGt80 : [Text]
_ -> [Text
"rwebAddress's length is over 80:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tGt80])
[Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let tsGt41 :: [Text]
tsGt41 = (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter ((X -> X -> Bool
forall a. Ord a => a -> a -> Bool
> X
41) (X -> Bool) -> (Text -> X) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> X
T.length) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ (String -> Text) -> [String] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map String -> Text
T.pack ([String] -> [Text]) -> [String] -> [Text]
forall a b. (a -> b) -> a -> b
$ ([String], [[String]]) -> [String]
forall a b. (a, b) -> a
fst ([String], [[String]])
rintroScreen
in case [Text]
tsGt41 of
[] -> []
Text
tGt41 : [Text]
_ -> [Text
"intro screen has a line with length over 41:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tGt41])
[Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ (let tsGt80 :: [Text]
tsGt80 = (Text -> Bool) -> [Text] -> [Text]
forall a. (a -> Bool) -> [a] -> [a]
filter ((X -> X -> Bool
forall a. Ord a => a -> a -> Bool
> X
80) (X -> Bool) -> (Text -> X) -> Text -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> X
T.length) ([Text] -> [Text]) -> [Text] -> [Text]
forall a b. (a -> b) -> a -> b
$ (String -> Text) -> [String] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map String -> Text
T.pack ([String] -> [Text]) -> [String] -> [Text]
forall a b. (a -> b) -> a -> b
$ [String] -> [[String]] -> [String]
forall a. [a] -> [[a]] -> [a]
intercalate [String
""]
([[String]] -> [String]) -> [[String]] -> [String]
forall a b. (a -> b) -> a -> b
$ ([String], [[String]]) -> [[String]]
forall a b. (a, b) -> b
snd ([String], [[String]])
rintroScreen
in case [Text]
tsGt80 of
[] -> []
Text
tGt80 : [Text]
_ -> [Text
"manual has a line with length over 80:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
tGt80])
[Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ Text
"rwidth /= RK.rWidthMax" | X
rwidth X -> X -> Bool
forall a. Eq a => a -> a -> Bool
/= RuleContent -> X
RK.rWidthMax RuleContent
corule ]
[Text] -> [Text] -> [Text]
forall a. [a] -> [a] -> [a]
++ [ Text
"rheight /= RK.rHeightMax + 3" | X
rheight X -> X -> Bool
forall a. Eq a => a -> a -> Bool
/= RuleContent -> X
RK.rHeightMax RuleContent
corule X -> X -> X
forall a. Num a => a -> a -> a
+ X
3]
makeData :: RK.RuleContent -> ScreenContent -> ScreenContent
makeData :: RuleContent -> ScreenContent -> ScreenContent
makeData RuleContent
corule ScreenContent
sc =
let singleOffenders :: [Text]
singleOffenders = RuleContent -> ScreenContent -> [Text]
validateSingle RuleContent
corule 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` String
"Screen Content not valid"
String -> [Text] -> (String, [Text])
forall v. String -> v -> (String, v)
`swith` [Text]
singleOffenders)
ScreenContent
sc