2727from random import randint , random
2828from typing import List
2929from urllib .parse import urljoin
30+ from itertools import chain
3031
3132import colorama
3233import requests
3536from rich .console import Console
3637from rich .progress import track
3738
39+ #region global variables
40+
3841__version__ = "0.0.1"
39- assets = Path ('assets/' )
40- assets .mkdir (parents = True , exist_ok = True )
41- ASSETS = assets
42+
43+ def setup () -> List [Path ]:
44+ assets = [Path ('assets/' ), Path ('assets/textures' ), Path ('assets/data' )]
45+ for dir in assets :
46+ dir .mkdir (parents = True , exist_ok = True )
47+ return assets
48+
49+ ASSETS , TEXTURES , DATA = setup ()
4250BASE_API = "https://pokeapi.co/api/v2/pokemon/"
4351SPRITE_API = "https://pokeres.bastionbot.org/images/pokemon/"
4452CONSOLE = Console ()
4553
54+ #endregion
55+
4656#region image processing
4757
4858CHARS = [' ' , '.' , 'o' , 'v' , '@' , '#' , 'W' ]
@@ -119,13 +129,15 @@ def req_pkmn_data(id_: int, verbose: bool) -> None:
119129 }
120130 result ['moves' ] = moves
121131
122- with open (ASSETS .joinpath (f"{ result ['id' ]} .json" ), mode = 'w' , encoding = 'utf-8' ) as file_handler :
132+ data = DATA .joinpath (f"{ result ['id' ]} .json" )
133+
134+ with open (data , mode = 'w' , encoding = 'utf-8' ) as file_handler :
123135 json .dump (result , file_handler )
124136
125137 if verbose :
126138 pprint (result )
127139
128- print (f"{ Fore .YELLOW } Done! A new JSON file was created in { str (ASSETS )!r} . { Style .RESET_ALL } " )
140+ print (f"{ Fore .YELLOW } Created { str (data )!r} { Style .RESET_ALL } " )
129141
130142def gen_sprite (id_ : int , mirror : bool , verbose : bool ) -> None :
131143 colorama .init (autoreset = False )
@@ -139,22 +151,25 @@ def gen_sprite(id_: int, mirror: bool, verbose: bool) -> None:
139151 file_handler .write (chunk )
140152
141153 ascii_art = img2ascii (Image .open (image_path ), width = 20 , mirror_image = mirror )
142- with open (ASSETS .joinpath (f"{ id_ } .txt" ), mode = 'w' , encoding = 'utf-8' ) as file_handler :
154+
155+ sprite = TEXTURES .joinpath (f"{ id_ } .txt" )
156+
157+ with open (sprite , mode = 'w' , encoding = 'utf-8' ) as file_handler :
143158 file_handler .writelines (ascii_art )
144159
145160 image_path .unlink (missing_ok = True )
146161
147162 if verbose :
148163 print (f"\n { '' .join (ascii_art )} " )
149164
150- print (f"{ Fore .YELLOW } Done! A new ASCII image was created in { str (ASSETS )!r} . { Style .RESET_ALL } " )
165+ print (f"{ Fore .YELLOW } Created { str (sprite )!r} { Style .RESET_ALL } " )
151166
152167def check_manifest (verbose : bool ) -> None :
153168 extensions = ['.txt' , '.json' ]
154169
155170 files = list (filter (
156171 lambda file : file .suffix in extensions and file .stem .isnumeric (),
157- [file for file in ASSETS .glob (r'**/*' )]
172+ [file for file in chain ( DATA .glob (r'**/*' ), TEXTURES . glob ( r'**/*' ) )]
158173 ))
159174
160175 ids = list (map (lambda file : int (file .stem ), files ))
@@ -190,7 +205,7 @@ def main():
190205 if args .command == 'make' :
191206 for id_ in args .id :
192207 req_pkmn_data (id_ , verbose = False )
193- gen_sprite (id_ , args .mirror , args . verbose )
208+ gen_sprite (id_ , args .mirror , verbose = False )
194209 elif args .command == 'manifest' :
195210 check_manifest (args .verbose )
196211 else :
0 commit comments