commit 8e7da96bfcd52b230feaf40fbc6d4a42b80c5723
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Sat Oct 17 18:55:14 2026 +0200
Make state machine more reusable
commit 37da7248b8c33ce95cff7ef9332c5ccf6e3cd418
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Sat Oct 17 18:44:34 2026 +0200
Change aim state into flag
commit fbb3a84a12e2cabff9b36390da7483b8de7e9379
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Sat Oct 17 18:33:08 2026 +0200
Replace fixed references with ui references
commit 913955b13e9980780ac88761845d9e1f165f0d0e
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Fri Oct 16 13:32:21 2026 +0200
Update camera action handling
commit 4ce0ac13ffea473cf62c2fefd1571e9df1fbbcaa
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Fri Oct 16 13:04:39 2026 +0200
Update mounting system
commit e410eca38760955b2866eecd6ac0281e2041e76d
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Fri Oct 16 12:57:25 2026 +0200
Update aiming system
commit 4c788df485ccbff5f91fd51d9f480e495f11da5f
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Thu Oct 15 21:50:26 2026 +0200
Centralize states names into constants
commit 6059479c87d749e986a48adb520ef33121104da5
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Thu Oct 15 21:25:32 2026 +0200
Refator Crouch state into flag
commit 08faec70e770042d36eed6f173a63f3aac1f67c6
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Wed Oct 14 10:19:35 2026 +0200
Update player input management and state machine
commit 11a0aecc58c50c5862a03b4fd0b55e8db024031f
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Wed Oct 14 10:17:06 2026 +0200
Delete charizard.tres
commit 399eac2b6c64f242a1c2e12360d811127f87681c
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Tue Oct 13 18:20:45 2026 +0200
Remove unused MountedState
commit 42a3668c52fe96a7509a74290a94fc5a8084b713
Author: TheThomaas <thethomaas@protonmail.ch>
Date: Tue Oct 13 18:18:08 2026 +0200
Group grounded states under common class
121 lines
5 KiB
GDScript
121 lines
5 KiB
GDScript
extends PlayerComponent
|
|
|
|
class_name InputManagementComponent
|
|
|
|
#instead of setting up keybinds in 3 differents scripts, it's centralized in this one only
|
|
#
|
|
#point d'entree unique de l'input du joueur :
|
|
# - declare les noms des actions (exports ci-dessous) : c'est la seule definition, ni PlayerCharacter ni CameraHolder n'en gardent de copie
|
|
# (le CameraHolder lit la camera par read_look_vector / read_zoom_axis)
|
|
# - fournit les lectures utilisees par les etats (read_move_dir, wants_jump...) : plus aucun etat n'appelle Input directement
|
|
# sauf pour les actions portees par un Hint (cancel, unlock, switch target, mount, dismount), lues par leur proprietaire
|
|
|
|
@export_group("Keybind variables")
|
|
@export_subgroup("Player character variables")
|
|
@export var move_forward_action : StringName = "player_move_forward"
|
|
@export var move_backward_action : StringName = "player_move_backward"
|
|
@export var move_left_action : StringName = "player_move_left"
|
|
@export var move_right_action : StringName = "player_move_right"
|
|
@export var run_action : StringName = "player_run"
|
|
@export var jump_action : StringName = "player_jump"
|
|
@export var dodge_action : StringName = "player_dodge"
|
|
@export var crouch_action : StringName = "player_crouch"
|
|
@export var throw_action : StringName = &"player_throw" #RT / clic gauche : maintenir pour charger, relacher pour lancer
|
|
@export_subgroup("Camera variables")
|
|
@export var aim_cam_action : StringName = "player_aim_camera"
|
|
@export var cam_zoom_in_action : StringName = "player_zoom_camera_in"
|
|
@export var cam_zoom_out_action : StringName = "player_zoom_camera_out"
|
|
@export var cam_look_up_action : StringName = "player_look_up"
|
|
@export var cam_look_down_action : StringName = "player_look_down"
|
|
@export var cam_look_left_action : StringName = "player_look_left"
|
|
@export var cam_look_right_action : StringName = "player_look_right"
|
|
|
|
func register_with_player() -> void:
|
|
player.player_input = self
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
player.cam_holder.player_input = self #le CameraHolder lit la camera ici, il ne connait aucun nom d'action
|
|
InputRegistry.ensure(throw_action, [InputRegistry.pad_axis(JOY_AXIS_TRIGGER_RIGHT, 1.0), InputRegistry.mouse(MOUSE_BUTTON_LEFT)])
|
|
|
|
#---------- camera ----------
|
|
|
|
func read_look_vector() -> Vector2:
|
|
#rotation de la camera a la manette / aux touches (la souris est geree par le CameraHolder lui-meme)
|
|
return Input.get_vector(cam_look_left_action, cam_look_right_action, cam_look_up_action, cam_look_down_action)
|
|
|
|
func read_zoom_axis() -> float:
|
|
return Input.get_axis(cam_zoom_in_action, cam_zoom_out_action)
|
|
|
|
#---------- deplacement ----------
|
|
|
|
func read_move_dir() -> Vector2:
|
|
#direction voulue, relative a la camera
|
|
return read_move_raw().rotated(-player.cam_holder.global_rotation.y)
|
|
|
|
func read_move_raw() -> Vector2:
|
|
#direction brute du stick / des touches, sans tenir compte de la camera
|
|
return Input.get_vector(move_left_action, move_right_action, move_forward_action, move_backward_action)
|
|
|
|
#---------- input consomme ----------
|
|
|
|
#un appui consomme est ignore par tous les getters ci-dessous jusqu'a ce que le bouton soit relache.
|
|
#sert quand un meme bouton a deux roles (ex : A monte sur un pokemon ET fait sauter) : celui qui agit en premier consomme l'appui
|
|
#(avant : MountRider bloquait des etats pendant une frame avec un await). Les composants qui consomment doivent s'executer
|
|
#avant la StateMachine (process_physics_priority plus petit, comme MountRider).
|
|
|
|
var _consumed : Dictionary = {} #action -> true
|
|
|
|
func consume(action : StringName) -> void:
|
|
if Input.is_action_pressed(action): _consumed[action] = true #rien a consommer si le bouton n'est pas enfonce
|
|
|
|
func is_consumed(action : StringName) -> bool:
|
|
if !_consumed.has(action): return false
|
|
if Input.is_action_pressed(action): return true
|
|
_consumed.erase(action) #bouton relache : l'action redevient disponible
|
|
return false
|
|
|
|
func _just_pressed(action : StringName) -> bool:
|
|
return !is_consumed(action) and Input.is_action_just_pressed(action)
|
|
|
|
func _held(action : StringName) -> bool:
|
|
return !is_consumed(action) and Input.is_action_pressed(action)
|
|
|
|
#---------- actions au sol ----------
|
|
|
|
func wants_dodge() -> bool:
|
|
return _just_pressed(dodge_action) and player.dodge_cooldown <= 0.0
|
|
|
|
func wants_jump() -> bool:
|
|
#depart d'un saut depuis le sol : tient compte de auto_jump (rester appuye)
|
|
if player.auto_jump: return _held(jump_action)
|
|
return _just_pressed(jump_action)
|
|
|
|
func jump_pressed() -> bool:
|
|
return _just_pressed(jump_action)
|
|
|
|
func jump_released() -> bool:
|
|
return Input.is_action_just_released(jump_action)
|
|
|
|
func crouch_pressed() -> bool:
|
|
return _just_pressed(crouch_action)
|
|
|
|
func run_pressed() -> bool:
|
|
return _held(run_action)
|
|
|
|
func run_just_pressed() -> bool:
|
|
return _just_pressed(run_action)
|
|
|
|
#---------- visee et lancer ----------
|
|
|
|
func aim_pressed() -> bool:
|
|
return _just_pressed(aim_cam_action)
|
|
|
|
func aim_held() -> bool:
|
|
return _held(aim_cam_action)
|
|
|
|
func throw_pressed() -> bool:
|
|
return _just_pressed(throw_action)
|
|
|
|
func throw_held() -> bool:
|
|
return _held(throw_action) |