def get_pokemon_map_icon(pkm, weather=None, gender=None, form=None, costume=None): im_lines = [] # Add Pokemon icon if pogo_assets: source, target = pokemon_asset_path(pkm, classifier='marker', gender=gender, form=form, costume=costume, weather=weather) target_size = 96 im_lines.append('-fuzz 0.5% -trim +repage' ' -scale "133x133>" -unsharp 0x1' ' -background none -gravity center -extent 139x139' ' -background black -alpha background' ' -channel A -blur 0x1 -level 0,10%' ' -adaptive-resize {size}x{size}' ' -modulate 100,110'.format(size=target_size)) else: # Extract pokemon icon from spritesheet source = path_pokemon_spritesheet weather_suffix = '_{}'.format( WeatherCondition.Name(weather)) if weather else '' target_path = os.path.join(path_generated, 'pokemon_spritesheet_marker') target = os.path.join(target_path, 'pokemon_{}{}.png'.format(pkm, weather_suffix)) target_size = pkm_sprites_size pkm_idx = pkm - 1 x = (pkm_idx % pkm_sprites_cols) * pkm_sprites_size y = (pkm_idx / pkm_sprites_cols) * pkm_sprites_size im_lines.append('-crop {size}x{size}+{x}+{y} +repage'.format( size=target_size, x=x, y=y)) if weather: radius = 20 x = target_size - radius - 2 y = radius + 1 y2 = 1 im_lines.append( '-gravity northeast' ' -fill "#FFFD" -stroke black -draw "circle {x},{y} {x},{y2}"' ' -draw "image over 1,1 42,42 \'{weather_img}\'"'.format( x=x, y=y, y2=y2, weather_img=weather_images[weather])) return run_imagemagick(source, im_lines, target)
def pokemon_asset_path(pkm, classifier=None, gender=GENDER_UNSET, form=None, costume=None, weather=None, shiny=False): gender_suffix = gender_assets_suffix = '' form_suffix = form_assets_suffix = '' costume_suffix = costume_assets_suffix = '' weather_suffix = '_{}'.format( WeatherCondition.Name(weather)) if weather else '' shiny_suffix = '_shiny' if shiny else '' if gender in (MALE, FEMALE): gender_assets_suffix = '_{:02d}'.format(gender - 1) gender_suffix = '_{}'.format(Gender.Name(gender)) elif gender in (GENDER_UNSET, GENDERLESS): gender_assets_suffix = '_00' if pkm > 0 else '' if form and pkm == 201: # Unown = no gender gender_suffix = gender_assets_suffix = '' form_assets_suffix = '_{:02d}'.format(form + 10) form_suffix = '_{}'.format(Form.Name(form)) if costume: costume_assets_suffix = '_{:02d}'.format(costume) costume_suffix = '_{}'.format(Costume.Name(costume)) if (not gender_assets_suffix and not form_assets_suffix and not costume_assets_suffix): gender_assets_suffix = ('_16' if pkm == 201 else '_00' if pkm > 0 else '') # Castform if form and pkm == 351: gender_suffix = gender_assets_suffix = '' gender_suffix = '_{}'.format(Gender.Name(gender)) form_assets_suffix = '_{:02d}'.format(form - 18) form_suffix = '_{}'.format(Form.Name(form)) assets_basedir = os.path.join(pogo_assets, 'decrypted_assets') assets_fullname = os.path.join( assets_basedir, 'pokemon_icon_{:03d}{}{}{}{}.png'.format(pkm, gender_assets_suffix, form_assets_suffix, costume_assets_suffix, shiny_suffix)) target_path = os.path.join(path_generated, 'pokemon_{}'.format( classifier)) if classifier else os.path.join(path_generated, 'pokemon') target_name = os.path.join( target_path, "pkm_{:03d}{}{}{}{}{}.png".format(pkm, gender_suffix, form_suffix, costume_suffix, weather_suffix, shiny_suffix)) if os.path.isfile(assets_fullname): return assets_fullname, target_name else: if gender == MALE: # Dummy Pokemon icon return (os.path.join(assets_basedir, 'pokemon_icon_000.png'), os.path.join(target_path, 'pkm_000.png')) return pokemon_asset_path(pkm, classifier=classifier, gender=MALE, form=form, costume=costume, weather=weather, shiny=shiny)
def pokemon_asset_path(pkm, classifier=None, gender=GENDER_UNSET, form=None, costume=None, weather=None, shiny=False): gender_suffix = gender_assets_suffix = '' form_suffix = form_assets_suffix = '' costume_suffix = costume_assets_suffix = '' weather_suffix = '_{}'.format( WeatherCondition.Name(weather)) if weather else '' shiny_suffix = '_shiny' if shiny else '' if gender in (MALE, FEMALE): gender_assets_suffix = '_{:02d}'.format(gender - 1) gender_suffix = '_{}'.format(Gender.Name(gender)) elif gender in (GENDER_UNSET, GENDERLESS): gender_assets_suffix = '_00' if pkm > 0 else '' if costume: costume_assets_suffix = '_{:02d}'.format(costume) costume_suffix = '_{}'.format(costume_names[costume]) if ( not gender_assets_suffix and not form_assets_suffix and not costume_assets_suffix ): gender_assets_suffix = ('_16' if pkm == 201 else '_00' if pkm > 0 else '') pokemon_data = get_pokemon_data(pkm) forms = pokemon_data.get('forms', {}) should_use_suffix = False if forms: # default value is first form form_data = list(forms.values())[0] if form and str(form) in forms: form_data = forms[str(form)] asset_id = '' if 'assetId' in form_data: asset_id = form_data['assetId'] elif 'assetSuffix' in form_data: should_use_suffix = True asset_id = form_data['assetSuffix'] gender_assets_suffix = '_' + asset_id form_suffix = '_' + asset_id assets_basedir = os.path.join(pogo_assets, 'pokemon_icons') assets_fullname = os.path.join(assets_basedir, 'pokemon_icon_{:03d}{}{}{}{}.png'.format( pkm, gender_assets_suffix, form_assets_suffix, costume_assets_suffix, shiny_suffix)) if should_use_suffix: assets_fullname = os.path.join(assets_basedir, 'pokemon_icon{}.png'.format(form_suffix) ) target_path = os.path.join( path_generated, 'pokemon_{}'.format( classifier)) if classifier else os.path.join( path_generated, 'pokemon') target_name = os.path.join(target_path, "pkm_{:03d}{}{}{}{}{}.png".format( pkm, gender_suffix, form_suffix, costume_suffix, weather_suffix, shiny_suffix)) if os.path.isfile(assets_fullname): return assets_fullname, target_name else: if gender == MALE: log.warning("Cannot find PogoAssets file {}".format( assets_fullname)) # Dummy Pokemon icon return ( os.path.join(assets_basedir, 'pokemon_icon_000.png'), os.path.join(target_path, 'pkm_000.png')) return pokemon_asset_path(pkm, classifier=classifier, gender=MALE, form=form, costume=costume, weather=weather, shiny=shiny)