Skip to content

Commit

Permalink
refactor(Inputs): remove keyboard controls
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasctnh committed Apr 7, 2022
1 parent a94b64e commit c4ac3e5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 127 deletions.
70 changes: 0 additions & 70 deletions Assets/InputControls/TouchControls.inputactions
Original file line number Diff line number Diff line change
Expand Up @@ -28,76 +28,6 @@
"isPartOfComposite": false
}
]
},
{
"name": "Keyboard",
"id": "77042264-d805-49d3-9ce2-7723f821c384",
"actions": [
{
"name": "Jump",
"type": "Button",
"id": "dc16ecb1-6c43-4c36-b79f-fca31a7f82d4",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Move",
"type": "PassThrough",
"id": "2136f2a0-cf38-4235-aa20-e583e6c1e641",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "",
"id": "260ab8a4-e9f0-4f0e-8140-fc049f4f027c",
"path": "<Keyboard>/space",
"interactions": "Press",
"processors": "",
"groups": "Keyboard",
"action": "Jump",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "1D Axis",
"id": "6c3eba72-5306-44e9-8217-6b72b86f4809",
"path": "1DAxis",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "negative",
"id": "48fe0cea-b1af-4db5-8354-b5a16df3a9ed",
"path": "<Keyboard>/downArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "positive",
"id": "a64e2045-a164-4fe2-b808-5a7f1c042503",
"path": "<Keyboard>/upArrow",
"interactions": "",
"processors": "",
"groups": "Keyboard",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
}
]
}
],
"controlSchemes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,15 @@

public class InputsController : MonoBehaviour {
public static event Action OnJump;
public static event Action OnSwitch;
public static event Action<bool> OnHoldingJump;
public static event Action<float> OnSwitch;
public static event Action OnButtonJump;
public static event Action OnButtonSwitch;

private float _yDrag = 0f;

public void ButtonJumpPointerDown(BaseEventData eventData) {
OnButtonJump?.Invoke();
OnJump?.Invoke();
OnHoldingJump?.Invoke(true);
}

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

public void ButtonSwitch() => OnButtonSwitch?.Invoke();

public void Jump(InputAction.CallbackContext context) {
if (context.performed && GameManager.Instance.IsGamePlayable)
OnJump?.Invoke();

HoldingJump(context);
}

private void HoldingJump(InputAction.CallbackContext context) {
if (context.performed)
OnHoldingJump?.Invoke(true);
if (context.canceled)
OnHoldingJump?.Invoke(false);
}

public void Switch(InputAction.CallbackContext context) {
if (context.performed && GameManager.Instance.IsGamePlayable) {
_yDrag = context.ReadValue<float>();
if (_yDrag != 0)
OnSwitch?.Invoke(_yDrag);
}
}
public void ButtonSwitch() => OnSwitch?.Invoke();
}
32 changes: 4 additions & 28 deletions Assets/Scripts/Gameplay/Controllers/Domain/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ public class PlayerController : MonoBehaviour { // TODO: refactor

private void OnEnable() {
InputsController.OnJump += Jump;
InputsController.OnSwitch += Switch;
InputsController.OnHoldingJump += isHoldingJump => AssignHoldingJump(isHoldingJump);
InputsController.OnSwitch += VerifySwitch;
InputsController.OnButtonJump += ButtonJump;
InputsController.OnButtonSwitch += ButtonSwitch;
GameManager.OnPlay += StartRun;
GameManager.OnGameOver += obj => PlayerDeath();
SkinsSystem.OnEndOfChangeSkin += AssignMaterials;
Expand All @@ -81,10 +79,8 @@ private void OnEnable() {

private void OnDisable() {
InputsController.OnJump -= Jump;
InputsController.OnSwitch -= Switch;
InputsController.OnHoldingJump -= isHoldingJump => AssignHoldingJump(isHoldingJump);
InputsController.OnSwitch -= VerifySwitch;
InputsController.OnButtonJump -= ButtonJump;
InputsController.OnButtonSwitch -= ButtonSwitch;
GameManager.OnPlay -= StartRun;
GameManager.OnGameOver -= obj => PlayerDeath();
SkinsSystem.OnEndOfChangeSkin -= AssignMaterials;
Expand Down Expand Up @@ -136,7 +132,7 @@ private void OnCollisionEnter(Collision other) {
_animator.SetTrigger("Fall");
}

public void ButtonJump() {
public void Jump() {
if (_jumps > 0 && GameManager.Instance.IsGamePlayable) {
_rigidbody.velocity = Vector3.up * _jumpForce * _gravityDirection;
AudioManager.Instance.PlaySoundOneShot(Sound.Type.Jump, 2);
Expand All @@ -146,7 +142,7 @@ public void ButtonJump() {
}
}

public void ButtonSwitch() {
public void Switch() {
if (IsGrounded && _canTeleport && GameManager.Instance.IsGamePlayable)
StartDissolving();
}
Expand Down Expand Up @@ -239,28 +235,8 @@ private void OnAir() {
_airTime += Time.deltaTime;
}

private void Jump() {
if (_jumps > 0) {
_rigidbody.velocity = Vector3.up * _jumpForce * _gravityDirection;
AudioManager.Instance.PlaySoundOneShot(Sound.Type.Jump, 2);
_animator.SetBool("Jump", true);

_jumps--;
}
}

private void AssignHoldingJump(bool isHoldingJump) => _isHoldingJump = isHoldingJump;

private void VerifySwitch(float yDrag) {
int newGravityDirection = (yDrag > 0) ? 1 : -1;
if (_gravityDirection != newGravityDirection && IsGrounded && _canTeleport) {
StartDissolving();
AssignNewGravityDirection(newGravityDirection);
}
}

private void AssignNewGravityDirection(int newGravityDirection) => _gravityDirection = newGravityDirection;

private void StartDissolving() => _canDissolveDown = true;

private void InvertPosition() {
Expand Down

0 comments on commit c4ac3e5

Please sign in to comment.