Mercurial > hg > tilerswift
changeset 55:47680c83e0e0
parse_tile: move this into a classmethod of Tile class
Seems like that's where it should belong.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Sun, 08 Sep 2019 19:18:51 -0400 |
parents | 2e9f6582c3d2 |
children | 198e061e93ab |
files | tilerswift |
diffstat | 1 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/tilerswift +++ b/tilerswift @@ -21,16 +21,6 @@ return tiles -def parse_tile(tile): - lowplane, hiplane = tile[0:8], tile[8:16] - rows = [] - for lowbyte, hibyte in zip(lowplane, hiplane): - row = [ - ((lowbyte >> idx) & 1) + 2*((hibyte >> idx) & 1) - for idx in range(7, -1, -1) - ] - rows.append(row) - return rows class Tile(object): @@ -47,7 +37,7 @@ super().__init__() self.raw_tile = tile - self.tile = parse_tile(self.raw_tile) + self.tile = self.parse_tile(self.raw_tile) self.img_data = bytes(sum(self.tile, [])) self.set_palette(self.default_palette) @@ -65,6 +55,19 @@ image.setColorTable(self.palette_to_qt()) self.pixmap = QtGui.QPixmap(image) + @classmethod + def parse_tile(cls, tile): + """Given a raw tile's bytes, convert it to an 8x8 array of integers.""" + lowplane, hiplane = tile[0:8], tile[8:16] + rows = [] + for lowbyte, hibyte in zip(lowplane, hiplane): + row = [ + ((lowbyte >> idx) & 1) + 2*((hibyte >> idx) & 1) + for idx in range(7, -1, -1) + ] + rows.append(row) + return rows + class GridHolder(object): def __init__(self, things, numrows, numcols, fillvalue=None):