diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-04-26 22:29:51 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-04-26 22:29:51 +0200 |
commit | 4d58ddd03b22dab33f37d1916fc94e6d6a875c87 (patch) | |
tree | 942e1fc0a74c20a64637750d99da55d5dfa177bf /maps/mapgen.py | |
parent | f6272349aedb3c09e8e5a964f6ea4064bf9a2e0a (diff) |
debug maps
Diffstat (limited to 'maps/mapgen.py')
-rwxr-xr-x | maps/mapgen.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/maps/mapgen.py b/maps/mapgen.py new file mode 100755 index 0000000..a7e6817 --- /dev/null +++ b/maps/mapgen.py @@ -0,0 +1,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) |