diff options
author | Diego Roversi <diegor@tiscali.it> | 2020-05-23 10:05:51 +0200 |
---|---|---|
committer | Diego Roversi <diegor@tiscali.it> | 2020-05-23 10:05:51 +0200 |
commit | 2c41e377ab7257f879840abca9305fd25c274100 (patch) | |
tree | e0760281aff75f297aae75474fda0224edff206c /bubbob/macbinary.py | |
parent | 81c86067960952f0ec87a035ce060da584e05df3 (diff) |
more string to bytearray conversion
Diffstat (limited to 'bubbob/macbinary.py')
-rw-r--r-- | bubbob/macbinary.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/bubbob/macbinary.py b/bubbob/macbinary.py index a485290..9d48764 100644 --- a/bubbob/macbinary.py +++ b/bubbob/macbinary.py @@ -1,11 +1,11 @@ import struct - +import sys def padto(n, m): return (n+m-1) & ~(m-1) def resourceclass(rtype): - return globals().get(rtype.strip() + 'Resource', Resource) + return globals().get(rtype.decode().strip() + 'Resource', Resource) class TypeList: @@ -118,7 +118,7 @@ class Subfile: if size is None or self.position + size > self.length: size = self.length - self.position if size <= 0: - return '' + return b'' self.f.seek(self.start + self.position) self.position = self.position + size return self.f.read(size) @@ -170,8 +170,9 @@ def image2rgb(image): result1 = [] for line in image: for r, g, b in line: - result1.append(chr(int(r)) + chr(int(g)) + chr(int(b))) - return len(image[0]), len(image), ''.join(result1) + # result1.append(chr(int(r)) + chr(int(g)) + chr(int(b))) + result1.append( bytes([int(r),int(g),int(b)]) ) + return len(image[0]), len(image), b''.join(result1) class clutResource(Resource): @@ -209,7 +210,7 @@ class ppatResource(Resource): imgline = [] for x in range(w): n = x//pixels_per_byte - idx = ((ord(line[n]) >> ((pixels_per_byte - 1 - x%pixels_per_byte) * bits_per_pixel)) + idx = ((line[n] >> ((pixels_per_byte - 1 - x%pixels_per_byte) * bits_per_pixel)) & ((1<<bits_per_pixel)-1)) imgline.append(colormap[idx]) image.append(imgline) @@ -221,8 +222,8 @@ class LEVLResource(Resource): WIDTH = 32 HEIGHT = 25 MONSTERS = 30 - WALLS = { 1:'#', 0:' '} - WINDS = { 0:' ', 1:'>', 2:'<', 3:'v', 4:'^', 5:'x', 0x66:' '} + WALLS = { 1:b'#', 0:b' '} + WINDS = { 0:b' ', 1:b'>', 2:b'<', 3:b'v', 4:b'^', 5:b'x', 0x66:b' '} FLAGS = ['flag0', 'letter', 'fire', 'lightning', 'water', 'top', 'flag6', 'flag7'] def getlevel(self, mnstrlist): @@ -232,17 +233,18 @@ class LEVLResource(Resource): walls = [] for y in range(self.HEIGHT): line = f.read(self.WIDTH//8) - line = [self.WALLS[(ord(line[x//8]) >> (x%8)) & 1] + print(f"LVLResource: line={line}", file=sys.stderr) + line = [self.WALLS[(line[x//8] >> (x%8)) & 1] for x in range(self.WIDTH)] - walls.append(''.join(line)) - result['walls'] = '\n'.join(walls) + walls.append(b''.join(line)) + result['walls'] = b'\n'.join(walls) winds = [] for y in range(self.HEIGHT): line = f.read(self.WIDTH) - line = [self.WINDS[ord(v)] for v in line] - winds.append(''.join(line)) - result['winds'] = '\n'.join(winds) + line = [self.WINDS[v] for v in line] + winds.append(b''.join(line)) + result['winds'] = b'\n'.join(winds) monsters = [] for i in range(self.MONSTERS): |