@@ -249,6 +249,25 @@ def generate_alias_code(alias_name: str, object_name: str) -> str:
249
249
return f"{ alias_name } = { object_name } \n "
250
250
251
251
252
+ def generate_enum_code (enum_data , for_stub = False ):
253
+ _string = ""
254
+ _string += f"class { enum_data ['name' ]} (enum.IntEnum):\n "
255
+ if enum_data ['description' ] != '' :
256
+ _string += f"\t \" \" \" { enum_data ['description' ]} \" \" \" \n "
257
+
258
+ for value in enum_data ['values' ]:
259
+ _string += f"\t { value ['name' ]} : int"
260
+ if not for_stub :
261
+ _string += f" = { value ['value' ]} "
262
+ if value ['description' ] != '' :
263
+ _string += f" # { value ['description' ]} "
264
+ _string += "\n "
265
+
266
+ _string += "\n "
267
+
268
+ return _string
269
+
270
+
252
271
def generate_function_signature_code (function_data : Dict [str , Union [str , List [Dict [str , str ]]]]) -> str :
253
272
function_string = f"def { function_data ['name' ]} ("
254
273
if 'params' in function_data .keys (): # only return stuff
@@ -351,6 +370,19 @@ def generate_structures_dictionary_code(wrapped_structures: List[str], for_stub:
351
370
return dictionary_sting
352
371
353
372
373
+ def generate_enums_code (enums_api , for_stub = False ):
374
+ _string = ""
375
+ for enum in enums_api :
376
+ if for_stub or enum ['name' ] not in wrapped_enums_names :
377
+ enum_string_logic = generate_enum_code (enum , for_stub )
378
+ if enum_string_logic != "" :
379
+ wrapped_enums_names .append (enum ['name' ])
380
+ enum_string_logic += "\n "
381
+
382
+ _string += enum_string_logic
383
+ return _string
384
+
385
+
354
386
def check_for_functions_that_can_wrap (functions_api : List [Union [Any , Dict [str , Union [str , List [Dict [str , str ]]]], Dict [str , str ]]]) -> List [Union [Any , Dict [str , Union [str , List [Dict [str , str ]]]], Dict [str , str ]]]:
355
387
functions_that_can_be_wrap = []
356
388
functions_that_cant_be_wrap = []
@@ -449,7 +481,7 @@ def generate_functions_code(functions_set: List[Union[Any, Dict[str, Union[str,
449
481
generate_file (RAYPYC_FOLDER_PATH / 'colors/__init__.pyi' )
450
482
add_text_to_file (RAYPYC_FOLDER_PATH / 'colors/__init__.pyi' , 'import raypyc\n \n \n ' )
451
483
452
- # generate colors code add colors code to files
484
+ # generate colors code and add colors code to files
453
485
add_text_to_file (RAYPYC_FOLDER_PATH / 'colors/__init__.py' , generate_colors_code (config_api_defines , for_stub = False ))
454
486
add_text_to_file (RAYPYC_FOLDER_PATH / 'colors/__init__.py' , generate_colors_code (rlgl_api_defines , for_stub = False ))
455
487
add_text_to_file (RAYPYC_FOLDER_PATH / 'colors/__init__.py' , generate_colors_code (raylib_api_defines , for_stub = False ))
@@ -466,7 +498,7 @@ def generate_functions_code(functions_set: List[Union[Any, Dict[str, Union[str,
466
498
generate_file (RAYPYC_FOLDER_PATH / 'defines/__init__.py' )
467
499
generate_file (RAYPYC_FOLDER_PATH / 'defines/__init__.pyi' )
468
500
469
- # generate defines code add defines code to files
8000
td>501
+ # generate defines code ans add defines code to files
470
502
add_text_to_file (RAYPYC_FOLDER_PATH / 'defines/__init__.py' , generate_defines_code (config_api_defines , for_stub = False ))
471
503
add_text_to_file (RAYPYC_FOLDER_PATH / 'defines/__init__.py' , generate_defines_code (rlgl_api_defines , for_stub = False ))
472
504
add_text_to_file (RAYPYC_FOLDER_PATH / 'defines/__init__.py' , generate_defines_code (raylib_api_defines , for_stub = False ))
@@ -485,7 +517,7 @@ def generate_functions_code(functions_set: List[Union[Any, Dict[str, Union[str,
485
517
generate_file (RAYPYC_FOLDER_PATH / 'structures/__init__.pyi' )
486
518
add_text_to_file (RAYPYC_FOLDER_PATH / 'structures/__init__.pyi' , 'import ctypes\n from raypyc.defines import *\n from typing import Type\n \n \n ' )
487
519
488
- # generate dummy structures code add dummy structures code to files
520
+ # generate dummy structures code and add dummy structures code to files
489
521
add_text_to_file (RAYPYC_FOLDER_PATH / 'structures/__init__.py' , generate_dummy_structs_code (['rAudioBuffer' , 'rAudioProcessor' ], for_stub = False ))
490
522
add_text_to_file (RAYPYC_FOLDER_PATH / 'structures/__init__.pyi' , generate_dummy_structs_code (['rAudioBuffer' , 'rAudioProcessor' ], for_stub = True ))
491
523
@@ -506,6 +538,26 @@ def generate_functions_code(functions_set: List[Union[Any, Dict[str, Union[str,
506
538
add_text_to_file (RAYPYC_FOLDER_PATH / 'structures/__init__.pyi' , generate_structures_dictionary_code (wrapped_structures_names_stub , for_stub = True ))
507
539
# -----------------------------------------
508
540
541
+ # generate enums files and add import stuff
542
+ generate_file (RAYPYC_FOLDER_PATH / 'enums/__init__.py' )
543
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.py' , 'import enum\n \n \n ' )
544
+ generate_file (RAYPYC_FOLDER_PATH / 'enums/__init__.pyi' )
545
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.pyi' , 'import enum\n \n \n ' )
546
+
547
+ # generate enums code and add enums code to files
548
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.py' , generate_enums_code (config_api_enums , for_stub = False ))
549
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.py' , generate_enums_code (rlgl_api_enums , for_stub = False ))
550
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.py' , generate_enums_code (raylib_api_enums , for_stub = False ))
551
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.py' , generate_enums_code (raymath_api_enums , for_stub = False ))
552
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.py' , generate_enums_code (raygui_api_enums , for_stub = False ))
553
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.pyi' , generate_enums_code (config_api_enums , for_stub = True ))
554
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.pyi' , generate_enums_code (rlgl_api_enums , for_stub = True ))
555
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.pyi' , generate_enums_code (raylib_api_enums , for_stub = True ))
556
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.pyi' , generate_enums_code (raymath_api_enums , for_stub = True ))
557
+ add_text_to_file (RAYPYC_FOLDER_PATH / 'enums/__init__.pyi' , generate_enums_code (raygui_api_enums , for_stub = True ))
558
+
559
+ # -----------------------------------------
560
+
509
561
generate_file (RAYPYC_FOLDER_PATH / '__init__.pyi' )
510
562
add_text_to_file (RAYPYC_FOLDER_PATH / '__init__.pyi' , 'import ctypes\n from raypyc.defines import *\n from raypyc.defines import *\n from raypyc.colors import *\n from raypyc.enums import *\n from raypyc.structures import *\n \n \n ' )
511
563
0 commit comments