2022-11-30 13:38:12 -08:00
|
|
|
module Main where
|
|
|
|
|
|
|
|
import Data.Map qualified as Map
|
|
|
|
import Graphics.Vty
|
|
|
|
import Control.Exception
|
|
|
|
import Data.List.NonEmpty (NonEmpty(..))
|
|
|
|
import Data.List.NonEmpty qualified as NonEmpty
|
|
|
|
|
2022-12-02 10:54:31 -08:00
|
|
|
import Model
|
|
|
|
import Rendering
|
2022-11-30 16:44:30 -08:00
|
|
|
|
2022-11-30 13:38:12 -08:00
|
|
|
world0 :: World
|
|
|
|
world0 = World {
|
|
|
|
worldMe = 'b',
|
|
|
|
worldBoxes = Map.fromList
|
|
|
|
[('1', Box {
|
|
|
|
boxColor = withForeColor defAttr green,
|
|
|
|
boxLocation = Location '1' (-1) 0,
|
2022-12-02 15:28:05 -08:00
|
|
|
boxType = Original $ makeWalls [
|
2022-12-02 15:46:42 -08:00
|
|
|
"▓▓ ▓▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
" ▓",
|
|
|
|
"▓ ▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓▓▓▓▓ ▓"
|
2022-11-30 13:38:12 -08:00
|
|
|
]
|
|
|
|
}),
|
|
|
|
('2', Box {
|
|
|
|
boxColor = withForeColor defAttr cyan,
|
|
|
|
boxLocation = Location '1' 1 1,
|
2022-12-02 15:28:05 -08:00
|
|
|
boxType = Original $ makeWalls [
|
2022-12-02 15:46:42 -08:00
|
|
|
"▓ ▓▓ ▓▓ ▓",
|
|
|
|
" ",
|
2022-12-02 18:49:26 -08:00
|
|
|
" ▓",
|
|
|
|
" ▓",
|
2022-12-02 15:46:42 -08:00
|
|
|
" ",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
" ",
|
|
|
|
"▓ ▓▓ ▓▓ ▓"
|
2022-11-30 13:38:12 -08:00
|
|
|
]
|
2022-11-30 23:20:18 -08:00
|
|
|
}),
|
2022-12-02 15:28:05 -08:00
|
|
|
('₂', Box {
|
|
|
|
boxColor = withForeColor defAttr cyan,
|
|
|
|
boxLocation = Location '1' 2 (-1),
|
|
|
|
boxType = Link '2'
|
|
|
|
}),
|
2022-11-30 23:20:18 -08:00
|
|
|
('3', Box {
|
|
|
|
boxColor = withForeColor defAttr blue,
|
|
|
|
boxLocation = Location '2' 1 1,
|
2022-12-02 15:28:05 -08:00
|
|
|
boxType = Original $ makeWalls [
|
2022-12-02 15:46:42 -08:00
|
|
|
"▓▓▓▓▓▓▓▓▓",
|
2022-12-02 18:49:26 -08:00
|
|
|
" ",
|
|
|
|
"▓▓▓▓▓▓▓▓ ",
|
|
|
|
"▓▓ ▓▓▓ ",
|
|
|
|
"▓▓ ▓▓▓ ",
|
|
|
|
"▓▓▓▓ ▓▓▓ ",
|
2022-12-02 15:46:42 -08:00
|
|
|
"▓▓ ▓▓▓▓",
|
|
|
|
"▓▓ ▓▓▓▓",
|
|
|
|
"▓▓▓▓ ▓▓▓▓"
|
2022-11-30 23:20:18 -08:00
|
|
|
]
|
|
|
|
}),
|
|
|
|
('4', Box {
|
|
|
|
boxColor = withForeColor defAttr black,
|
2022-12-02 15:46:42 -08:00
|
|
|
boxLocation = Location 'b' (-3) 0,
|
2022-12-02 15:28:05 -08:00
|
|
|
boxType = Original $ makeWalls [
|
2022-12-02 15:46:42 -08:00
|
|
|
"▓▓▓ ▓▓▓",
|
|
|
|
"▓ ▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓▓▓▓ ▓▓▓▓"
|
2022-11-30 23:20:18 -08:00
|
|
|
]
|
2022-11-30 13:38:12 -08:00
|
|
|
}),
|
|
|
|
('b', Box {
|
|
|
|
boxColor = withForeColor defAttr red,
|
|
|
|
boxLocation = Location '1' 0 1,
|
2022-12-02 15:28:05 -08:00
|
|
|
boxType = Original $ makeWalls [
|
2022-12-02 15:46:42 -08:00
|
|
|
"▓▓▓▓▓▓▓▓▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
2022-12-02 18:49:26 -08:00
|
|
|
"▓ ▓ ▓ ▓",
|
|
|
|
"▓ ▓",
|
2022-12-02 15:46:42 -08:00
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓▓▓▓▓▓▓▓▓"
|
2022-12-02 11:26:00 -08:00
|
|
|
]
|
2022-11-30 13:38:12 -08:00
|
|
|
}),
|
|
|
|
('x', Box {
|
|
|
|
boxColor = withForeColor defAttr yellow,
|
|
|
|
boxLocation = Location '1' 0 (-1),
|
2022-12-02 18:49:26 -08:00
|
|
|
boxType = Original $
|
|
|
|
makeWalls [
|
|
|
|
"▓▓ ▓ ",
|
|
|
|
" ",
|
|
|
|
" ▓ ▓▓▓ ",
|
|
|
|
" ▓ ",
|
|
|
|
"▓ ▓▓▓▓",
|
|
|
|
" ▓▓▓ ",
|
|
|
|
" ▓ ▓▓▓ ",
|
|
|
|
" ",
|
|
|
|
"▓ ▓ ▓"
|
|
|
|
]
|
2022-11-30 13:38:12 -08:00
|
|
|
}),
|
|
|
|
('y', Box {
|
|
|
|
boxColor = withForeColor defAttr magenta,
|
|
|
|
boxLocation = Location '1' 0 (-2),
|
2022-12-02 18:49:26 -08:00
|
|
|
boxType = Original $ makeWalls [
|
|
|
|
"▓▓ ▓ ",
|
|
|
|
" ",
|
|
|
|
"▓▓ ▓▓▓ ",
|
|
|
|
"▓▓ ",
|
|
|
|
" ▓▓▓▓",
|
|
|
|
"▓▓▓▓ ",
|
|
|
|
"▓▓ ▓▓▓ ",
|
|
|
|
" ",
|
|
|
|
"▓ ▓ ▓"
|
|
|
|
]
|
2022-12-02 11:26:00 -08:00
|
|
|
}),
|
|
|
|
('i', Box {
|
|
|
|
boxColor = withForeColor defAttr black,
|
|
|
|
boxLocation = Location 'b' 0 (-2),
|
2022-12-02 15:46:42 -08:00
|
|
|
boxType = Original $ solid 9
|
2022-12-02 11:26:00 -08:00
|
|
|
}),
|
|
|
|
('j', Box {
|
|
|
|
boxColor = withForeColor defAttr black,
|
|
|
|
boxLocation = Location 'b' 0 (-1),
|
2022-12-02 15:46:42 -08:00
|
|
|
boxType = Original $ solid 9
|
2022-12-02 11:26:00 -08:00
|
|
|
}),
|
|
|
|
('k', Box {
|
|
|
|
boxColor = withForeColor defAttr black,
|
|
|
|
boxLocation = Location 'b' 0 0,
|
2022-12-02 15:46:42 -08:00
|
|
|
boxType = Original $ solid 9
|
2022-12-02 11:26:00 -08:00
|
|
|
}),
|
|
|
|
('l', Box {
|
|
|
|
boxColor = withForeColor defAttr black,
|
|
|
|
boxLocation = Location 'b' 0 1,
|
2022-12-02 15:46:42 -08:00
|
|
|
boxType = Original $ solid 9
|
2022-12-02 15:28:05 -08:00
|
|
|
}),
|
|
|
|
('₁', Box {
|
|
|
|
boxColor = withForeColor defAttr green,
|
|
|
|
boxLocation = Location '1' 2 1,
|
|
|
|
boxType = Link '1'
|
2022-11-30 13:38:12 -08:00
|
|
|
})
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main =
|
|
|
|
bracket (mkVty =<< userConfig) shutdown \vty ->
|
|
|
|
do
|
|
|
|
loop vty (pure world0)
|
|
|
|
pure ()
|
|
|
|
|
|
|
|
loop :: Vty -> NonEmpty World -> IO ()
|
|
|
|
loop vty (world :| history) =
|
2022-11-30 16:44:30 -08:00
|
|
|
do update vty (picForImage (drawNestedWorld world))
|
2022-11-30 13:38:12 -08:00
|
|
|
ev <- nextEvent vty
|
|
|
|
case ev of
|
|
|
|
EvKey key _modifier ->
|
|
|
|
case key of
|
|
|
|
KUp -> loop vty (move world (-1,0) :| world : history)
|
2022-11-30 23:20:18 -08:00
|
|
|
KDown -> loop vty (move world (1,0) :| world : history)
|
2022-11-30 13:38:12 -08:00
|
|
|
KLeft -> loop vty (move world (0,-1) :| world : history)
|
2022-11-30 23:20:18 -08:00
|
|
|
KRight -> loop vty (move world (0,1) :| world : history)
|
2022-11-30 13:38:12 -08:00
|
|
|
KChar 'z'
|
|
|
|
| Just worlds <- NonEmpty.nonEmpty history ->
|
|
|
|
loop vty worlds
|
|
|
|
KEsc -> pure ()
|
|
|
|
_ -> loop vty (world :| history)
|
|
|
|
_ -> loop vty (world :| history)
|
2022-12-02 18:49:26 -08:00
|
|
|
|
|
|
|
smallWorld :: World
|
|
|
|
smallWorld =
|
|
|
|
World
|
|
|
|
(Map.fromList
|
|
|
|
[('a',
|
|
|
|
Box (Location 'a' 0 0)
|
|
|
|
(Original (makeWalls [
|
|
|
|
"▓▓▓▓▓▓▓▓▓",
|
|
|
|
"▓ ▓ ▓",
|
|
|
|
"▓ ▓ ▓",
|
|
|
|
"▓▓▓▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓ ▓",
|
|
|
|
"▓▓▓▓▓▓▓▓▓"
|
|
|
|
]))
|
|
|
|
(withForeColor defAttr black)),
|
|
|
|
('1',
|
|
|
|
Box
|
|
|
|
(Location 'a' (-3) (-3))
|
|
|
|
(Original (makeWalls (replicate 9 (replicate 9 ' '))))
|
|
|
|
(withForeColor defAttr yellow)),
|
|
|
|
('2',
|
|
|
|
Box
|
|
|
|
(Location 'a' (-3) (-2))
|
|
|
|
(Original (makeWalls (replicate 9 (replicate 9 ' '))))
|
|
|
|
(withForeColor defAttr magenta)),
|
|
|
|
('3',
|
|
|
|
Box
|
|
|
|
(Location 'a' (-2) (-3))
|
|
|
|
(Original (makeWalls (replicate 9 (replicate 9 ' '))))
|
|
|
|
(withForeColor defAttr blue)),
|
|
|
|
('4',
|
|
|
|
Box
|
|
|
|
(Location 'a' (-2) (-2))
|
|
|
|
(Original (makeWalls (replicate 9 (replicate 9 ' '))))
|
|
|
|
(withForeColor defAttr green)),
|
|
|
|
('b',
|
|
|
|
Box
|
|
|
|
(Location '1' 0 0)
|
|
|
|
(Original (solid 9))
|
|
|
|
(withForeColor defAttr red))
|
|
|
|
]) 'b'
|