From 2ae8f65b426dff98d998bece374bea98b1e46dea Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 17 Feb 2016 16:15:18 -0500 Subject: Try to fix pic dimensions. --- gfx.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'gfx.py') diff --git a/gfx.py b/gfx.py index ec5bbb9d8..b39d919ef 100644 --- a/gfx.py +++ b/gfx.py @@ -12,11 +12,23 @@ pics = [ 'gfx/shrink2', ] +def recursive_read(filename): + def recurse(filename_): + lines = [] + for line in open(filename_): + if 'include "' in line.lower(): + lines += recurse(line.split('"')[1]) + else: + lines += [line] + return lines + lines = recurse(filename) + return ''.join(lines) + base_stats = None def get_base_stats(): global base_stats if not base_stats: - base_stats = open('data/base_stats.asm').read() + base_stats = recursive_read('data/base_stats.asm') return base_stats def get_pokemon_dimensions(name): @@ -25,7 +37,7 @@ def get_pokemon_dimensions(name): if name.startswith('unown_'): name = 'unown' base_stats = get_base_stats() - start = base_stats.find(name.title() + 'BaseData:') + start = base_stats.find('\tdb ' + name.upper()) start = base_stats.find('\tdn ', start) end = base_stats.find('\n', start) line = base_stats[start:end].replace(',', ' ') @@ -37,12 +49,15 @@ def filepath_rules(filepath): args = {} filedir, filename = os.path.split(filepath) + if filedir.startswith('./'): + filedir = filedir[2:] + name, ext = os.path.splitext(filename) pokemon_name = '' if 'gfx/pics/' in filedir: - pokemon_name = filedir.split('/')[3] + pokemon_name = filedir.split('/')[-1] if pokemon_name.startswith('unown_'): index = filedir.find(pokemon_name) if index != -1: -- cgit v1.2.3 From f6fc07d1c9fc1fdf9d95842d59879450b98fa721 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 17 Feb 2016 17:12:51 -0500 Subject: Assume pokemon pics are 7x7 if not in base stats. --- gfx.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'gfx.py') diff --git a/gfx.py b/gfx.py index b39d919ef..abd53c5b0 100644 --- a/gfx.py +++ b/gfx.py @@ -32,17 +32,22 @@ def get_base_stats(): return base_stats def get_pokemon_dimensions(name): - if name == 'egg': - return 5, 5 - if name.startswith('unown_'): - name = 'unown' - base_stats = get_base_stats() - start = base_stats.find('\tdb ' + name.upper()) - start = base_stats.find('\tdn ', start) - end = base_stats.find('\n', start) - line = base_stats[start:end].replace(',', ' ') - w, h = map(int, line.split()[1:3]) - return w, h + try: + if name == 'egg': + return 5, 5 + if name == 'questionmark': + return 7, 7 + if name.startswith('unown_'): + name = 'unown' + base_stats = get_base_stats() + start = base_stats.find('\tdb ' + name.upper()) + start = base_stats.find('\tdn ', start) + end = base_stats.find('\n', start) + line = base_stats[start:end].replace(',', ' ') + w, h = map(int, line.split()[1:3]) + return w, h + except: + return 7, 7 def filepath_rules(filepath): """Infer attributes of certain graphics by their location in the filesystem.""" -- cgit v1.2.3 From 21a9fac5d04c5865ccdeac28e236067907a420c0 Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 17 Feb 2016 18:08:11 -0500 Subject: Decompress images in one step instead of having to invoke 'unlz'. --- gfx.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'gfx.py') diff --git a/gfx.py b/gfx.py index abd53c5b0..75af28b80 100644 --- a/gfx.py +++ b/gfx.py @@ -58,6 +58,8 @@ def filepath_rules(filepath): filedir = filedir[2:] name, ext = os.path.splitext(filename) + if ext == '.lz': + name, ext = os.path.splitext(name) pokemon_name = '' @@ -104,22 +106,31 @@ def filepath_rules(filepath): def to_1bpp(filename, **kwargs): - _, ext = os.path.splitext(filename) + name, ext = os.path.splitext(filename) if ext == '.1bpp': pass elif ext == '.2bpp': gfx.export_2bpp_to_1bpp(filename, **kwargs) elif ext == '.png': gfx.export_png_to_1bpp(filename, **kwargs) + elif ext == '.lz': + decompress(filename, **kwargs) + to_1bpp(name, **kwargs) def to_2bpp(filename, **kwargs): - _, ext = os.path.splitext(filename) + name, ext = os.path.splitext(filename) if ext == '.1bpp': gfx.export_1bpp_to_2bpp(filename, **kwargs) elif ext == '.2bpp': pass elif ext == '.png': gfx.export_png_to_2bpp(filename, **kwargs) + elif ext == '.lz': + decompress(filename, **kwargs) + to_2bpp(name, **kwargs) def to_png(filename, **kwargs): - _, ext = os.path.splitext(filename) + name, ext = os.path.splitext(filename) if ext == '.1bpp': gfx.export_1bpp_to_png(filename, **kwargs) elif ext == '.2bpp': gfx.export_2bpp_to_png(filename, **kwargs) elif ext == '.png': pass + elif ext == '.lz': + decompress(filename, **kwargs) + to_png(name, **kwargs) def compress(filename, **kwargs): data = open(filename, 'rb').read() -- cgit v1.2.3