joypad_motion_textures.gd 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Copyright (C) 2022-2023 John Pennycook
  2. # SPDX-License-Identifier: MIT
  3. @tool
  4. class_name JoypadMotionTextures
  5. extends Resource
  6. ## Textures used by a [JoypadMotionPrompt] or [ActionPrompt].
  7. ##
  8. ## Textures used by a [JoypadMotionPrompt] or [ActionPrompt]. Stores a texture
  9. ## for each joypad axis and value.
  10. ## Texture for Axis 0 - (Left Stick Left, Joystick 0 Left)
  11. @export var axis_0_minus: Texture2D = null
  12. ## Texture for Axis 0 + (Left Stick Right, Joystick 0 Right)
  13. @export var axis_0_plus: Texture2D = null
  14. ## Texture for Axis 1 - (Left Stick Up, Joystick 0 Up)
  15. @export var axis_1_minus: Texture2D = null
  16. ## Texture for Axis 1 + (Left Stick Down, Joystick 0 Down)
  17. @export var axis_1_plus: Texture2D = null
  18. ## Texture for Axis 2 - (Right Stick Left, Joystick 1 Left)
  19. @export var axis_2_minus: Texture2D = null
  20. ## Texture for Axis 2 + (Right Stick Right, Joystick 1 Right)
  21. @export var axis_2_plus: Texture2D = null
  22. ## Texture for Axis 3 - (Right Stick Up, Joystick 1 Up)
  23. @export var axis_3_minus: Texture2D = null
  24. ## Texture for Axis 3 + (Left Stick Down, Joystick 1 Down)
  25. @export var axis_3_plus: Texture2D = null
  26. ## Texture for Axis 4 - (Joystick 2 Left)
  27. @export var axis_4_minus: Texture2D = null
  28. ## Texture for Axis 4 + (Left Trigger, Sony L2, Xbox LT, Joystick 2 Right)
  29. @export var axis_4_plus: Texture2D = null
  30. ## Texture for Axis 5 - (Joystick 2 Up)
  31. @export var axis_5_minus: Texture2D = null
  32. ## Texture for Axis 5 + (Right Trigger, Sony R2, Xbox RT, Joystick 2 Down)
  33. @export var axis_5_plus: Texture2D = null
  34. ## Return the [Texture2D] associated with the specified [InputEvent], or null.
  35. func get_texture(event: InputEvent) -> Texture2D:
  36. if not event is InputEventJoypadMotion:
  37. return null
  38. var motion_event := event as InputEventJoypadMotion
  39. var axis = motion_event.axis
  40. var axis_value = motion_event.axis_value
  41. var suffix := "_minus" if axis_value == -1 else "_plus"
  42. return get("axis_" + str(axis) + suffix)