Skip to content

Commit c4ac3e5

Browse files
committed
refactor(Inputs): remove keyboard controls
1 parent a94b64e commit c4ac3e5

File tree

3 files changed

+7
-127
lines changed

3 files changed

+7
-127
lines changed

Assets/InputControls/TouchControls.inputactions

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -28,76 +28,6 @@
2828
"isPartOfComposite": false
2929
}
3030
]
31-
},
32-
{
33-
"name": "Keyboard",
34-
"id": "77042264-d805-49d3-9ce2-7723f821c384",
35-
"actions": [
36-
{
37-
"name": "Jump",
38-
"type": "Button",
39-
"id": "dc16ecb1-6c43-4c36-b79f-fca31a7f82d4",
40-
"expectedControlType": "Button",
41-
"processors": "",
42-
"interactions": "",
43-
"initialStateCheck": false
44-
},
45-
{
46-
"name": "Move",
47-
"type": "PassThrough",
48-
"id": "2136f2a0-cf38-4235-aa20-e583e6c1e641",
49-
"expectedControlType": "Button",
50-
"processors": "",
51-
"interactions": "",
52-
"initialStateCheck": false
53-
}
54-
],
55-
"bindings": [
56-
{
57-
"name": "",
58-
"id": "260ab8a4-e9f0-4f0e-8140-fc049f4f027c",
59-
"path": "<Keyboard>/space",
60-
"interactions": "Press",
61-
"processors": "",
62-
"groups": "Keyboard",
63-
"action": "Jump",
64-
"isComposite": false,
65-
"isPartOfComposite": false
66-
},
67-
{
68-
"name": "1D Axis",
69-
"id": "6c3eba72-5306-44e9-8217-6b72b86f4809",
70-
"path": "1DAxis",
71-
"interactions": "",
72-
"processors": "",
73-
"groups": "",
74-
"action": "Move",
75-
"isComposite": true,
76-
"isPartOfComposite": false
77-
},
78-
{
79-
"name": "negative",
80-
"id": "48fe0cea-b1af-4db5-8354-b5a16df3a9ed",
81-
"path": "<Keyboard>/downArrow",
82-
"interactions": "",
83-
"processors": "",
84-
"groups": "Keyboard",
85-
"action": "Move",
86-
"isComposite": false,
87-
"isPartOfComposite": true
88-
},
89-
{
90-
"name": "positive",
91-
"id": "a64e2045-a164-4fe2-b808-5a7f1c042503",
92-
"path": "<Keyboard>/upArrow",
93-
"interactions": "",
94-
"processors": "",
95-
"groups": "Keyboard",
96-
"action": "Move",
97-
"isComposite": false,
98-
"isPartOfComposite": true
99-
}
100-
]
10131
}
10232
],
10333
"controlSchemes": [

Assets/Scripts/Gameplay/Controllers/Application/InputsController.cs

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,15 @@
77

88
public class InputsController : MonoBehaviour {
99
public static event Action OnJump;
10+
public static event Action OnSwitch;
1011
public static event Action<bool> OnHoldingJump;
11-
public static event Action<float> OnSwitch;
12-
public static event Action OnButtonJump;
13-
public static event Action OnButtonSwitch;
14-
15-
private float _yDrag = 0f;
1612

1713
public void ButtonJumpPointerDown(BaseEventData eventData) {
18-
OnButtonJump?.Invoke();
14+
OnJump?.Invoke();
1915
OnHoldingJump?.Invoke(true);
2016
}
2117

2218
public void ButtonJumpPointerUp(BaseEventData eventData) => OnHoldingJump?.Invoke(false);
2319

24-
public void ButtonSwitch() => OnButtonSwitch?.Invoke();
25-
26-
public void Jump(InputAction.CallbackContext context) {
27-
if (context.performed && GameManager.Instance.IsGamePlayable)
28-
OnJump?.Invoke();
29-
30-
HoldingJump(context);
31-
}
32-
33-
private void HoldingJump(InputAction.CallbackContext context) {
34-
if (context.performed)
35-
OnHoldingJump?.Invoke(true);
36-
if (context.canceled)
37-
OnHoldingJump?.Invoke(false);
38-
}
39-
40-
public void Switch(InputAction.CallbackContext context) {
41-
if (context.performed && GameManager.Instance.IsGamePlayable) {
42-
_yDrag = context.ReadValue<float>();
43-
if (_yDrag != 0)
44-
OnSwitch?.Invoke(_yDrag);
45-
}
46-
}
20+
public void ButtonSwitch() => OnSwitch?.Invoke();
4721
}

Assets/Scripts/Gameplay/Controllers/Domain/PlayerController.cs

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ public class PlayerController : MonoBehaviour { // TODO: refactor
6868

6969
private void OnEnable() {
7070
InputsController.OnJump += Jump;
71+
InputsController.OnSwitch += Switch;
7172
InputsController.OnHoldingJump += isHoldingJump => AssignHoldingJump(isHoldingJump);
72-
InputsController.OnSwitch += VerifySwitch;
73-
InputsController.OnButtonJump += ButtonJump;
74-
InputsController.OnButtonSwitch += ButtonSwitch;
7573
GameManager.OnPlay += StartRun;
7674
GameManager.OnGameOver += obj => PlayerDeath();
7775
SkinsSystem.OnEndOfChangeSkin += AssignMaterials;
@@ -81,10 +79,8 @@ private void OnEnable() {
8179

8280
private void OnDisable() {
8381
InputsController.OnJump -= Jump;
82+
InputsController.OnSwitch -= Switch;
8483
InputsController.OnHoldingJump -= isHoldingJump => AssignHoldingJump(isHoldingJump);
85-
InputsController.OnSwitch -= VerifySwitch;
86-
InputsController.OnButtonJump -= ButtonJump;
87-
InputsController.OnButtonSwitch -= ButtonSwitch;
8884
GameManager.OnPlay -= StartRun;
8985
GameManager.OnGameOver -= obj => PlayerDeath();
9086
SkinsSystem.OnEndOfChangeSkin -= AssignMaterials;
@@ -136,7 +132,7 @@ private void OnCollisionEnter(Collision other) {
136132
_animator.SetTrigger("Fall");
137133
}
138134

139-
public void ButtonJump() {
135+
public void Jump() {
140136
if (_jumps > 0 && GameManager.Instance.IsGamePlayable) {
141137
_rigidbody.velocity = Vector3.up * _jumpForce * _gravityDirection;
142138
AudioManager.Instance.PlaySoundOneShot(Sound.Type.Jump, 2);
@@ -146,7 +142,7 @@ public void ButtonJump() {
146142
}
147143
}
148144

149-
public void ButtonSwitch() {
145+
public void Switch() {
150146
if (IsGrounded && _canTeleport && GameManager.Instance.IsGamePlayable)
151147
StartDissolving();
152148
}
@@ -239,28 +235,8 @@ private void OnAir() {
239235
_airTime += Time.deltaTime;
240236
}
241237

242-
private void Jump() {
243-
if (_jumps > 0) {
244-
_rigidbody.velocity = Vector3.up * _jumpForce * _gravityDirection;
245-
AudioManager.Instance.PlaySoundOneShot(Sound.Type.Jump, 2);
246-
_animator.SetBool("Jump", true);
247-
248-
_jumps--;
249-
}
250-
}
251-
252238
private void AssignHoldingJump(bool isHoldingJump) => _isHoldingJump = isHoldingJump;
253239

254-
private void VerifySwitch(float yDrag) {
255-
int newGravityDirection = (yDrag > 0) ? 1 : -1;
256-
if (_gravityDirection != newGravityDirection && IsGrounded && _canTeleport) {
257-
StartDissolving();
258-
AssignNewGravityDirection(newGravityDirection);
259-
}
260-
}
261-
262-
private void AssignNewGravityDirection(int newGravityDirection) => _gravityDirection = newGravityDirection;
263-
264240
private void StartDissolving() => _canDissolveDown = true;
265241

266242
private void InvertPosition() {

0 commit comments

Comments
 (0)