fix setMouseCursor() and setTextureWrap() enum types (#126)

* tidying

no change to behavior, just change a few things to be
more consistent with the rest

* fix enum type conversions

setMouseCursor() and setTextureWrap() both took c_int arguments;
now they take zig enums instead

* make fix_enums table-driven

hopefully this is easier to visually parse than the if-else chain
This commit is contained in:
pancelor 2024-07-27 14:19:14 -07:00 committed by GitHub
parent 85e07d7db5
commit 6efc03f6fe
Failed to generate hash of commit
4 changed files with 37 additions and 55 deletions

View file

@ -147,6 +147,28 @@ def fix_pointer(name: str, t: str):
return name, t
_fix_enums_data = [
# arg_name, new_type, func_name_regex
("key", "KeyboardKey", r".*"),
("mode", "CameraMode", r"UpdateCamera"),
("mode", "BlendMode", r"BeginBlendMode"),
("gesture", "Gesture", r".*"),
("logLevel", "TraceLogLevel", r".*"),
("ty", "FontType", r".*"),
("uniformType", "ShaderUniformDataType", r".*"),
("cursor", "MouseCursor", r".*"),
("format", "PixelFormat", r".*"),
("newFormat", "PixelFormat", r".*"),
("layout", "CubemapLayout", r".*"),
("mapType", "MaterialMapIndex", r".*"),
("filter", "TextureFilter", r"SetTextureFilter"),
("wrap", "TextureWrap", r"SetTextureWrap"),
("flags", "ConfigFlags", r"SetWindowState|ClearWindowState|SetConfigFlags"),
("flag", "ConfigFlags", r"IsWindowState"),
("flags", "Gesture", r"SetGesturesEnabled"),
("button", "GamepadButton", r".*GamepadButton.*"),
("button", "MouseButton", r".*MouseButton.*"),
]
def fix_enums(arg_name, arg_type, func_name):
if func_name.startswith("rl"):
return arg_type
@ -154,47 +176,9 @@ def fix_enums(arg_name, arg_type, func_name):
# Hacking specific enums in here.
# Raylib doesn't use the enums but rather the resulting ints.
if arg_type == "int" or arg_type == "unsigned int":
if arg_name == "key":
arg_type = "KeyboardKey"
elif arg_name == "button":
if "Gamepad" in func_name:
arg_type = "GamepadButton"
else:
arg_type = "MouseButton"
elif arg_name == "mode":
if func_name == "UpdateCamera":
arg_type = "CameraMode"
elif func_name == "BeginBlendMode":
arg_type = "BlendMode"
elif arg_name == "gesture":
arg_type = "Gesture"
elif arg_name == "flags" or arg_name == "flag":
if func_name in [
"SetWindowState", "ClearWindowState", "SetConfigFlags", "IsWindowState"
]:
arg_type = "ConfigFlags"
elif func_name == "SetGesturesEnabled":
arg_type = "Gesture"
elif arg_name == "logLevel":
arg_type = "TraceLogLevel"
elif arg_name == "ty":
arg_type = "FontType"
elif arg_name == "uniformType":
arg_type = "ShaderUniformDataType"
elif arg_name == "Cursor":
arg_type = "MouseCursor"
elif arg_name == "newFormat":
arg_type = "PixelFormat"
elif arg_name == "layout":
arg_type = "CubemapLayout"
elif arg_name == "filter" and func_name == "SetTextureFilter":
arg_type = "TextureFilter"
elif arg_name == "TextureWrap":
arg_type = "TextureWrap"
elif arg_name == "format":
arg_type = "PixelFormat"
elif arg_name == "mapType":
arg_type = "MaterialMapIndex"
for target_arg_name,new_type,func_name_regex in _fix_enums_data:
if arg_name==target_arg_name and re.fullmatch(func_name_regex,func_name):
return new_type
return arg_type