shithub: pokecrystal

Download patch

ref: 8f74b553db37ddc1842476eb0d96ec3c8f1ac0ed
parent: aa9fd87a0900a408443bcfe4ab2ddd7bd49c550c
author: yenatch <[email protected]>
date: Sun Aug 30 07:06:37 EDT 2015

Grab Pokemon pic dimensions from base stats if converting from 2bpp.

--- a/gfx.py
+++ b/gfx.py
@@ -12,6 +12,26 @@
 	'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 @@
 	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 @@
 			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