local_input.gd 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. class_name LocalInput
  2. extends Node
  3. # Sends commands from a local device
  4. signal dir_changed(new_dir: Vector2)
  5. signal main_action(pressed: bool)
  6. signal get_in_action(commander: LocalInput)
  7. signal analog_action(side: int, value: float)
  8. func _unhandled_input(event: InputEvent) -> void:
  9. if event.is_action("main"):
  10. main_action.emit(event.is_pressed())
  11. elif event.is_action_pressed("get_in"):
  12. get_in_action.emit(self)
  13. elif event.is_action("move_left") or event.is_action("move_right") or event.is_action("move_back") or event.is_action("move_forward"):
  14. var dir: Vector2 = Input.get_vector("move_left", "move_right", "move_back", "move_forward")
  15. dir_changed.emit(dir)
  16. elif event.is_action("analog_main"):
  17. analog_action.emit(1, event.get_action_strength("analog_main"))
  18. elif event.is_action("analog_secondary"):
  19. analog_action.emit(-1, event.get_action_strength("analog_secondary"))
  20. func _on_title_screen_start_game() -> void:
  21. _enable()
  22. func _enable() -> void:
  23. set_process_mode(Node.PROCESS_MODE_PAUSABLE)