pituicat/src/Map.hs

44 lines
1 KiB
Haskell
Raw Normal View History

2020-10-09 23:00:33 +00:00
{-# LANGUAGE OverloadedStrings #-}
2020-10-09 03:51:00 +00:00
module Map where
import Linear
2020-10-09 23:00:33 +00:00
import Codec.Picture
import qualified Data.Vector as V
2020-10-09 03:51:00 +00:00
-- internal imports
import Types
2020-10-09 23:00:33 +00:00
testLevelDesc :: LevelDescriptor
testLevelDesc = LevelDescriptor
[ (0, "res/maps/00_test/00_test.bmp")
]
0
"res/tiles/00_test/00_test.png"
(3, 3)
-- constructMap :: LevelDescriptor -> IO LevelMap
-- cosntructMap desc = do
2020-10-09 03:51:00 +00:00
2020-10-09 23:00:33 +00:00
readLayer
:: (Word, FilePath) -- | index and path of the layer descriptor image
-> IO (MapLayer, V2 Int)
readLayer (idx, path) = do
img <- either error convertRGBA8 <$> readImage path
let width = imageWidth img
height = imageHeight img
layer = V.map
(\(py, px) -> case (pixelAt img px py) of
(PixelRGBA8 r g b _) -> Tile
(V2 (255 - fromIntegral g) (255 - fromIntegral b))
(case r of
255 -> Solid
254 -> Platform
_ -> Decoration
)
)
(V.fromList ((,) <$> [0 .. height - 1] <*> [0 .. width - 1]))
return (MapLayer layer, V2 width height)