# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1567984731 14400 # Node ID 47680c83e0e0a58a6a11d431042c2e311a12e3b1 # Parent 2e9f6582c3d22cbf419f65ec9450bb937c7e223e parse_tile: move this into a classmethod of Tile class Seems like that's where it should belong. diff --git a/tilerswift b/tilerswift --- 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):