module Terminal.Game (
TPS,
FPS,
Event(..),
GEnv(..),
Game(..),
playGame,
playGameS,
assertTermDims,
blankPlaneFull,
centerFull,
Timed,
creaTimer, creaBoolTimer,
creaTimerLoop, creaBoolTimerLoop,
Animation,
creaAnimation,
creaLoopAnimation,
tick, ticks, reset, lapse,
fetchFrame, isExpired,
StdGen,
getStdGen, mkStdGen,
getRandom, pickRandom,
UniformRange,
Plane,
Dimensions,
Coords,
Row, Column,
Width, Height,
blankPlane,
stringPlane,
stringPlaneTrans,
makeTransparent,
makeOpaque,
planePaper,
planeSize,
Draw,
(%), (&), (#),
subPlane,
mergePlanes,
cell, word, box,
Color(..), ColorIntensity(..),
color, bold, invert,
(%^>), (%.<), (%.>),
textBox, textBoxLiquid,
textBoxHyphen, textBoxHyphenLiquid,
Hyphenator,
english_GB, english_US, esperanto,
french, german_1996, italian, spanish,
(|||), (===), (***), hcat, vcat,
testGame,
setupGame,
recordGame,
readRecord,
narrateGame,
Terminal.Game.displaySize,
errorPress,
ATGException(..)
)
where
import System.Console.ANSI
import Terminal.Game.Animation
import Terminal.Game.Draw
import Terminal.Game.Layer.Imperative
import Terminal.Game.Layer.Object as O
import Terminal.Game.Plane
import Terminal.Game.Random
import Text.LineBreak
import qualified Control.Monad as CM
displaySize :: IO Dimensions
displaySize :: IO Dimensions
displaySize = IO Dimensions
forall (m :: * -> *).
(MonadDisplay m, MonadException m) =>
m Dimensions
O.displaySizeErr
assertTermDims :: Dimensions -> IO ()
assertTermDims :: Dimensions -> IO ()
assertTermDims (Width
sw, Width
sh) =
IO ()
clearScreen IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
Width -> Width -> IO ()
setCursorPosition Width
0 Width
0 IO () -> IO Dimensions -> IO Dimensions
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
IO Dimensions
forall (m :: * -> *).
(MonadDisplay m, MonadException m) =>
m Dimensions
displaySizeErr IO Dimensions -> (Dimensions -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Dimensions
tds ->
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
CM.when (Dimensions -> Bool
isSmaller Dimensions
tds) ([Char] -> IO ()
forall a. HasCallStack => [Char] -> a
error ([Char] -> IO ()) -> [Char] -> IO ()
forall a b. (a -> b) -> a -> b
$ Dimensions -> [Char]
smallMsg Dimensions
tds)
where
colS :: Width -> Bool
colS Width
ww = Width
ww Width -> Width -> Bool
forall a. Ord a => a -> a -> Bool
< Width
sw
rowS :: Width -> Bool
rowS Width
wh = Width
wh Width -> Width -> Bool
forall a. Ord a => a -> a -> Bool
< Width
sh
isSmaller :: Dimensions -> Bool
isSmaller :: Dimensions -> Bool
isSmaller (Width
ww, Width
wh) = Width -> Bool
colS Width
ww Bool -> Bool -> Bool
|| Width -> Bool
rowS Width
wh
smallMsg :: Dimensions -> String
smallMsg :: Dimensions -> [Char]
smallMsg (Width
ww, Width
wh) =
let cm :: [Char]
cm = Width -> [Char]
forall a. Show a => a -> [Char]
show Width
ww [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" columns"
rm :: [Char]
rm = Width -> [Char]
forall a. Show a => a -> [Char]
show Width
wh [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" rows"
em :: [Char]
em | Width -> Bool
colS Width
ww Bool -> Bool -> Bool
&& Width -> Bool
rowS Width
wh = [Char]
cm [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" and " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
rm
| Width -> Bool
colS Width
ww = [Char]
cm
| Width -> Bool
rowS Width
wh = [Char]
rm
| Bool
otherwise = [Char]
"smallMsg: passed correct term size!"
in
[Char]
"This games requires a grid of " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Width -> [Char]
forall a. Show a => a -> [Char]
show Width
sw [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
" columns and " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ Width -> [Char]
forall a. Show a => a -> [Char]
show Width
sh [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
" rows.\n" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
"Yours only has " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
em [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"!\n\n" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++
[Char]
"Please resize your terminal now!\n"