tools/hwmap.hs
author unc0rr
Wed, 18 Jun 2014 17:36:46 +0400
changeset 10323 72e6df962cb6
child 10329 e2dba215655a
permissions -rw-r--r--
Code drawn map in haskell \o/ (not finished, todo: compressing and base64 encoding)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10323
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     1
module Main where
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     2
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     3
import qualified Data.ByteString.Lazy as BL
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     4
import Data.Word
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     5
import Data.Int
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     6
import Data.Binary
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     7
import Data.Bits
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     8
import Control.Monad
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
     9
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    10
data LineType = Solid | Erasing
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    11
    deriving Eq
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    12
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    13
data Chunk = Line LineType Word8 [(Int16, Int16)]
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    14
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    15
instance Binary Chunk where
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    16
    put (Line lt r ((x1, y1):ps)) = do
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    17
        let flags = r .|. (if lt == Solid then 0 else (1 `shift` 6))
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    18
        putWord8 $ flags .|. (1 `shift` 7)
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    19
        put x1
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    20
        put y1
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    21
        forM_ ps $ \(x, y) -> do
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    22
            putWord8 flags
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    23
            put x
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    24
            put y
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    25
    get = undefined
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    26
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    27
mapString = BL.drop 8 . encode $
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    28
    [
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    29
        Line Solid 7 [(0, 0), (2048, 1024), (1024, 768)]
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    30
    ]
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    31
72e6df962cb6 Code drawn map in haskell \o/
unc0rr
parents:
diff changeset
    32
main = BL.writeFile "out.hwmap" mapString