10323
|
1 |
module Main where
|
|
2 |
|
10329
|
3 |
import qualified Data.ByteString.Char8 as B
|
|
4 |
import qualified Data.ByteString as BW
|
10323
|
5 |
import qualified Data.ByteString.Lazy as BL
|
10329
|
6 |
import qualified Codec.Binary.Base64 as Base64
|
10323
|
7 |
import Data.Word
|
|
8 |
import Data.Int
|
|
9 |
import Data.Binary
|
10329
|
10 |
import Data.Binary.Put
|
10323
|
11 |
import Data.Bits
|
|
12 |
import Control.Monad
|
10329
|
13 |
import qualified Codec.Compression.Zlib as Z
|
10323
|
14 |
|
|
15 |
data LineType = Solid | Erasing
|
|
16 |
deriving Eq
|
|
17 |
|
|
18 |
data Chunk = Line LineType Word8 [(Int16, Int16)]
|
|
19 |
|
|
20 |
instance Binary Chunk where
|
|
21 |
put (Line lt r ((x1, y1):ps)) = do
|
|
22 |
let flags = r .|. (if lt == Solid then 0 else (1 `shift` 6))
|
|
23 |
put x1
|
|
24 |
put y1
|
10329
|
25 |
putWord8 $ flags .|. (1 `shift` 7)
|
10323
|
26 |
forM_ ps $ \(x, y) -> do
|
|
27 |
put x
|
|
28 |
put y
|
10329
|
29 |
putWord8 flags
|
10323
|
30 |
get = undefined
|
|
31 |
|
10329
|
32 |
compressWithLength :: BL.ByteString -> BL.ByteString
|
|
33 |
compressWithLength b = BL.drop 8 . encode . runPut $ do
|
|
34 |
put $ ((fromIntegral $ BL.length b)::Word32)
|
|
35 |
mapM_ putWord8 $ BW.unpack $ BL.toStrict $ Z.compress b
|
|
36 |
|
|
37 |
mapString :: B.ByteString
|
|
38 |
mapString = B.pack . Base64.encode . BW.unpack . BL.toStrict . compressWithLength . BL.drop 8 . encode $ drawnMap
|
|
39 |
|
|
40 |
main = B.writeFile "out.hwmap" mapString
|
|
41 |
|
|
42 |
drawnMap = [
|
10323
|
43 |
Line Solid 7 [(0, 0), (2048, 1024), (1024, 768)]
|
|
44 |
]
|