diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8156207 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pyqt5==5.10.1 diff --git a/smeargle.py b/smeargle.py index 298c63d..f0b6cc4 100755 --- a/smeargle.py +++ b/smeargle.py @@ -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): self.max_tiles = max_tiles @@ -90,7 +92,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), @@ -115,7 +117,8 @@ class Script: return lines - def generate_tilemap(self, font, lines): + @staticmethod + def generate_tilemap(font, lines): tilemap = {} raw_tiles = [] compressed_tiles = [] @@ -159,7 +162,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) @@ -186,6 +189,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: @@ -254,6 +258,7 @@ class Game: print('Compressed: ', output_comp) print('Tile<->text: ', output_map) + if __name__ == '__main__': import sys import os @@ -276,5 +281,3 @@ if __name__ == '__main__': print('Processing {}...'.format(script)) game.render_script(script, render_path, output=True) print('{} processed.'.format(script)) - -