MCPcopy
hub / github.com/KilledByAPixel/LittleJS / getNavigationDirection

Method getNavigationDirection

plugins/uiSystem.js:554–575  ·  view source on GitHub ↗

Get navigation direction from gamepad or keyboard * @return {number}

()

Source from the content-addressed store, hash-verified

552 /** Get navigation direction from gamepad or keyboard
553 * @return {number} */
554 getNavigationDirection()
555 {
556 const vertical = uiSystem.navigationDirection === 1;
557 const both = uiSystem.navigationDirection === 2;
558 if (isUsingGamepad)
559 {
560 const stick = gamepadStick(0, gamepadPrimary);
561 const dpad = gamepadDpad(gamepadPrimary);
562 if (both)
563 return -(stick.y || dpad.y) || (stick.x || dpad.x);
564 return vertical ? -(stick.y || dpad.y) : (stick.x || dpad.x);
565 }
566 const up = 'ArrowUp', down = 'ArrowDown', left = 'ArrowLeft', right = 'ArrowRight';
567 if (both)
568 {
569 return keyIsDown(up) || keyIsDown(left) ? -1 :
570 keyIsDown(down) || keyIsDown(right) ? 1 : 0;
571 }
572 const back = vertical ? up : left;
573 const forward = vertical ? down : right;
574 return keyIsDown(back) ? -1 : keyIsDown(forward) ? 1 : 0;
575 }
576
577 /** Get other axis navigation direction from gamepad or keyboard
578 * @return {Vector2} */

Callers 1

uiUpdateMethod · 0.80

Calls 3

gamepadStickFunction · 0.85
gamepadDpadFunction · 0.85
keyIsDownFunction · 0.85

Tested by

no test coverage detected