diff options
author | JimB16 <f1@jimb.de> | 2015-08-31 03:47:03 +0200 |
---|---|---|
committer | JimB16 <f1@jimb.de> | 2015-08-31 03:47:03 +0200 |
commit | 4f1014976c380b9b2fcca2cbfa32ba77487279d3 (patch) | |
tree | aeef8ef64fa48a97c1fca3b57aa8b0ac45e6622d /gfx.py | |
parent | 7608472ef4313877a11f290097a8bd8c1b78e40c (diff) | |
parent | 8f74b553db37ddc1842476eb0d96ec3c8f1ac0ed (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'gfx.py')
-rw-r--r-- | gfx.py | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -12,6 +12,26 @@ pics = [ 'gfx/shrink2', ] +base_stats = None +def get_base_stats(): + global base_stats + if not base_stats: + base_stats = open('data/base_stats.asm').read() + 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(name.title() + 'BaseData:') + 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 + def filepath_rules(filepath): """Infer attributes of certain graphics by their location in the filesystem.""" args = {} @@ -19,9 +39,12 @@ def filepath_rules(filepath): filedir, filename = os.path.split(filepath) name, ext = os.path.splitext(filename) + pokemon_name = '' + if 'gfx/pics/' in filedir: - if 'unown' in filedir: - index = filedir.find('unown_') + pokemon_name = filedir.split('/')[3] + if pokemon_name.startswith('unown_'): + index = filedir.find(pokemon_name) if index != -1: filedir = filedir[:index + len('unown')] + filedir[index + len('unown_a'):] if name == 'front': @@ -49,6 +72,12 @@ def filepath_rules(filepath): w, h = gfx.png.Reader(filepath).asRGBA8()[:2] w = min(w/8, h/8) args['pic_dimensions'] = w, w + elif ext == '.2bpp': + if pokemon_name: + w, h = get_pokemon_dimensions(pokemon_name) + args['pic_dimensions'] = w, w + else: + args['pic_dimensions'] = 7, 7 return args |