Merge pep8 fixes from master

current
Nathan Deren 2018-06-06 10:39:23 -07:00
commit 3584999c55
3 changed files with 26 additions and 14 deletions

View File

@ -18,6 +18,7 @@ import os.path as op
from PyQt5.QtGui import QImage, QPixmap, QPainter, QGuiApplication
def linear1(tile, *args):
data = bytearray()
@ -32,6 +33,7 @@ def linear1(tile, *args):
return bytes(data)
def linear2(tile, palette):
data = bytearray()
@ -55,6 +57,7 @@ def linear2(tile, palette):
return bytes(data)
def planar2(tile, palette):
data = bytearray()
@ -80,6 +83,7 @@ def planar2(tile, palette):
return bytes(data)
def linear4(tile, palette):
data = bytearray()
@ -107,7 +111,7 @@ def linear4(tile, palette):
bp4 = 0
for x in range(8):
pixel = tile.pixelIndex(x,y)
pixel = tile.pixelIndex(x, y)
a = pixel & 0x4
b = pixel & 0x8
@ -116,10 +120,11 @@ def linear4(tile, palette):
if b:
bp4 += 2**(7-x)
data.extend((bp3,bp4))
data.extend((bp3, bp4))
return bytes(data)
def padded4_2(tile, palette):
data = bytearray()
@ -146,10 +151,11 @@ def padded4_2(tile, palette):
bp3 = 0
bp4 = 0
data.extend((bp3,bp4))
data.extend((bp3, bp4))
return bytes(data)
def planar4(tile, palette):
data = bytearray()
@ -208,6 +214,7 @@ formats = {
'padded4_2': padded4_2
}
def main():
app = QGuiApplication(sys.argv)
@ -220,11 +227,11 @@ mapper in order to force palette modifications.
format is one of the supported formats:'''
)
for format in formats.keys():
print('* {}'.format(format))
for fmt in formats.keys():
print('* {}'.format(fmt))
sys.exit(1)
(image, format) = sys.argv[1:3]
(image, fmt) = sys.argv[1:3]
(image_base, ext) = op.splitext(image)
output = '{}.bin'.format(image_base)
mapper = image_base + '.txt'
@ -235,7 +242,7 @@ format is one of the supported formats:'''
if not output.startswith('output/'):
output = 'output/{}'.format(output)
bpp = int(format[-1])
bpp = int(fmt[-1])
print('Loading image...')
data = QImage(image)
@ -266,14 +273,15 @@ format is one of the supported formats:'''
print('No palette found.')
palette = None
print('Converting to {}'.format(format))
print('Converting to {}'.format(fmt))
counter = 0
with open(output, mode='wb') as f:
for row in range(rows):
for column in range(columns):
tile = data.copy(column * 8, row * 8, 8, 8)
f.write(formats[format](tile, palette))
f.write(formats[fmt](tile, palette))
counter += 1
if __name__ == '__main__':
main()

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
pyqt5==5.10.1

View File

@ -5,6 +5,7 @@ from math import ceil
from PyQt5.QtGui import QGuiApplication, QPixmap, QImage, QColor, QPainter
class Font:
"""A simple class for managing Smeargle's font data."""
def __init__(self, filename):
@ -72,6 +73,7 @@ class Font:
"""Calculate the pixel-wise length of the given string."""
return sum(self.table[x]['width'] for x in text)
class Script:
def __init__(self, filename, max_tiles=0, atlas=False, tile_offset=0):
self.max_tiles = max_tiles
@ -92,7 +94,7 @@ class Script:
continue
length = font.length(line)
length = ceil(length / font.width) * font.width
if max_tiles > 0 and length > max_tiles:
if 0 < max_tiles < length:
print('WARNING: "{}" exceeds {} tiles by {}px; truncating.'.format(
line,
int(max_tiles / font.width),
@ -117,7 +119,8 @@ class Script:
return lines
def generate_tilemap(self, font, lines):
@staticmethod
def generate_tilemap(font, lines):
tilemap = {}
raw_tiles = []
compressed_tiles = []
@ -161,7 +164,7 @@ class Script:
count -= 1
indexes.append((text, ' '.join(tile_idx)))
return (compressed_tiles, raw_tiles, map_idx, indexes, total, unique)
return compressed_tiles, raw_tiles, map_idx, indexes, total, unique
def render_tiles(self, font, tiles):
image = QImage(font.width * 16, ceil(len(tiles) / 16) * font.height, QImage.Format_RGB32)
@ -188,6 +191,7 @@ class Script:
def render_tiles_to_file(self, font, tiles, filename):
self.render_tiles(font, tiles).save(filename, 'PNG')
class Game:
def __init__(self, filename):
with open(filename, mode='rb') as f:
@ -263,6 +267,7 @@ class Game:
print('Compressed: ', output_comp)
print('Tile<->text: ', output_map)
if __name__ == '__main__':
import sys
import os
@ -285,5 +290,3 @@ if __name__ == '__main__':
print('Processing {}...'.format(script))
game.render_script(script, render_path, output=True)
print('{} processed.'.format(script))