aboutsummaryrefslogtreecommitdiff
path: root/maps/mapprint.py
blob: 4b56db643df864cbfe38444ce81018c055b064b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import sys
from struct import unpack

def mapprint(filename):
  file = open(filename, 'rb')
  contents = file.read()
  file.close()

  width, height = unpack('>HH', contents[0:4])

  for y in range(height):
    for x in range(width):
      nibble = x + y * width
      byte = int(nibble / 2)
      shift = byte * 2 - nibble + 1
      num = (contents[4 + byte] & (0xf << 4 * shift)) >> 4 * shift
      print(" ─│┘──└┴│┐│┤┌┬├┼"[num], end='')
    print("\n", end='')

if __name__ == "__main__":
  if len(sys.argv) > 1:
    mapprint(sys.argv[1])
  else:
    exit(1)