blob: a7e6817c107d61c2d29c549ea20609a1ab197ba0 (
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
25
26
27
28
29
30
31
|
import sys
from struct import pack
def mapgen(filename):
file = open(filename, 'r')
target = open(filename + '.map', 'wb')
contents = file.read()
lines = contents.strip().split("\n")
target.write(pack('>H', len(lines[0])))
target.write(pack('>H', len(lines)))
first_nibble = False
temp_byte = 0
for char in contents.replace('\n', '').strip():
first_nibble = not first_nibble
num = int(char, 16)
temp_byte |= num << (4 * first_nibble)
if not first_nibble:
target.write(pack('B', temp_byte))
temp_byte = 0
if first_nibble: target.write(pack('B', temp_byte))
file.close()
target.close()
if __name__ == "__main__":
if len(sys.argv) > 1:
mapgen(sys.argv[1])
else:
exit(1)
|