From f34a14b2e9530304ec7a85dc5763903f64eaea6c Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 14 Nov 2024 21:01:38 -0600 Subject: [PATCH 001/205] feat: joystick aim and movement --- client/src/scripts/managers/inputManager.ts | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/client/src/scripts/managers/inputManager.ts b/client/src/scripts/managers/inputManager.ts index fcc610fc6..ea6d45a3f 100644 --- a/client/src/scripts/managers/inputManager.ts +++ b/client/src/scripts/managers/inputManager.ts @@ -8,6 +8,7 @@ import { ItemType, type ItemDefinition } from "@common/utils/objectDefinitions"; import { Vec } from "@common/utils/vector"; import $ from "jquery"; import nipplejs, { type JoystickOutputData } from "nipplejs"; +import * as PIXI from "pixi.js"; import { isMobile } from "pixi.js"; import { getTranslatedString } from "../../translations"; import { type Game } from "../game"; @@ -342,6 +343,50 @@ export class InputManager { shootOnRelease = false; }); } + const ticker = new PIXI.Ticker(); + ticker.stop(); + ticker.add(() => { + const gamepads = navigator.getGamepads(); + if (gamepads[0]) { + const leftJoystickMoving = gamepads[0].axes[0] !== 0 || gamepads[0].axes[1] !== 0; + const rightJoystickMoving = gamepads[0].axes[2] !== 0 || gamepads[0].axes[3] !== 0; + // const rightJoystickDistance = Math.sqrt(gamepads[0].axes[2] * gamepads[0].axes[2] + gamepads[0].axes[3] * gamepads[0].axes[3]); + // distance formula for stuff like throwables, USAS-12, and M590M + if (leftJoystickMoving) { + const movementAngle = Math.atan2(gamepads[0].axes[1], gamepads[0].axes[0]); + this.movementAngle = movementAngle; + this.movement.moving = true; + // note: movement.moving only works on mobile + if (!rightJoystickMoving) { + this.rotation = movementAngle; + this.turning = true; + const activePlayer = game.activePlayer; + if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { + game.activePlayer.container.rotation = this.rotation; + this.turning = true; + } + if (!activePlayer) return; + activePlayer.images.aimTrail.alpha = 0; + } + } else { + this.movement.moving = false; + } + + if (rightJoystickMoving) { + this.rotation = Math.atan2(gamepads[0].axes[3], gamepads[0].axes[2]); + this.turning = true; + const activePlayer = game.activePlayer; + + if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && activePlayer) { + game.activePlayer.container.rotation = this.rotation; + } + + if (!activePlayer) return; + activePlayer.images.aimTrail.alpha = 1; + } + } + }); + ticker.start(); } private handleInputEvent(down: boolean, event: KeyboardEvent | MouseEvent | WheelEvent): void { From 29c3904090a13c8e3087b8aa4a54ab9bac19d5d7 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 14 Nov 2024 21:32:27 -0600 Subject: [PATCH 002/205] refactor: removed unnecessary activePlayer const fix: only imported ticker instead of all of pixi.js --- client/src/scripts/managers/inputManager.ts | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/client/src/scripts/managers/inputManager.ts b/client/src/scripts/managers/inputManager.ts index ea6d45a3f..458514bd8 100644 --- a/client/src/scripts/managers/inputManager.ts +++ b/client/src/scripts/managers/inputManager.ts @@ -8,7 +8,7 @@ import { ItemType, type ItemDefinition } from "@common/utils/objectDefinitions"; import { Vec } from "@common/utils/vector"; import $ from "jquery"; import nipplejs, { type JoystickOutputData } from "nipplejs"; -import * as PIXI from "pixi.js"; +import { Ticker } from "pixi.js"; import { isMobile } from "pixi.js"; import { getTranslatedString } from "../../translations"; import { type Game } from "../game"; @@ -343,8 +343,7 @@ export class InputManager { shootOnRelease = false; }); } - const ticker = new PIXI.Ticker(); - ticker.stop(); + const ticker = new Ticker(); ticker.add(() => { const gamepads = navigator.getGamepads(); if (gamepads[0]) { @@ -360,13 +359,12 @@ export class InputManager { if (!rightJoystickMoving) { this.rotation = movementAngle; this.turning = true; - const activePlayer = game.activePlayer; if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { game.activePlayer.container.rotation = this.rotation; this.turning = true; } - if (!activePlayer) return; - activePlayer.images.aimTrail.alpha = 0; + if (!game.activePlayer) return; + game.activePlayer.images.aimTrail.alpha = 0; } } else { this.movement.moving = false; @@ -375,14 +373,11 @@ export class InputManager { if (rightJoystickMoving) { this.rotation = Math.atan2(gamepads[0].axes[3], gamepads[0].axes[2]); this.turning = true; - const activePlayer = game.activePlayer; - if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && activePlayer) { + if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { game.activePlayer.container.rotation = this.rotation; + game.activePlayer.images.aimTrail.alpha = 1; } - - if (!activePlayer) return; - activePlayer.images.aimTrail.alpha = 1; } } }); From 78dabadeedf1bf2e563ac872b6758a252557e7b5 Mon Sep 17 00:00:00 2001 From: Arman Date: Thu, 14 Nov 2024 22:16:33 -0600 Subject: [PATCH 003/205] refactor: named axe variables + one less indent --- client/src/scripts/managers/inputManager.ts | 57 +++++++++++---------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/client/src/scripts/managers/inputManager.ts b/client/src/scripts/managers/inputManager.ts index 458514bd8..8b33bcd55 100644 --- a/client/src/scripts/managers/inputManager.ts +++ b/client/src/scripts/managers/inputManager.ts @@ -346,38 +346,41 @@ export class InputManager { const ticker = new Ticker(); ticker.add(() => { const gamepads = navigator.getGamepads(); - if (gamepads[0]) { - const leftJoystickMoving = gamepads[0].axes[0] !== 0 || gamepads[0].axes[1] !== 0; - const rightJoystickMoving = gamepads[0].axes[2] !== 0 || gamepads[0].axes[3] !== 0; - // const rightJoystickDistance = Math.sqrt(gamepads[0].axes[2] * gamepads[0].axes[2] + gamepads[0].axes[3] * gamepads[0].axes[3]); - // distance formula for stuff like throwables, USAS-12, and M590M - if (leftJoystickMoving) { - const movementAngle = Math.atan2(gamepads[0].axes[1], gamepads[0].axes[0]); - this.movementAngle = movementAngle; - this.movement.moving = true; - // note: movement.moving only works on mobile - if (!rightJoystickMoving) { - this.rotation = movementAngle; + if (!gamepads[0]) return; + const leftJoystickX = gamepads[0].axes[0]; + const leftJoystickY = gamepads[0].axes[1]; + const rightJoystickX = gamepads[0].axes[2]; + const rightJoystickY = gamepads[0].axes[3]; + const leftJoystickMoving = leftJoystickX !== 0 || leftJoystickY !== 0; + const rightJoystickMoving = rightJoystickX !== 0 || rightJoystickY !== 0; + // const rightJoystickDistance = Math.sqrt(gamepads[0].axes[2] * gamepads[0].axes[2] + gamepads[0].axes[3] * gamepads[0].axes[3]); + // distance formula for stuff like throwables, USAS-12, and M590M + if (leftJoystickMoving) { + const movementAngle = Math.atan2(leftJoystickY, leftJoystickX); + this.movementAngle = movementAngle; + this.movement.moving = true; + // note: movement.moving only works on mobile + if (!rightJoystickMoving) { + this.rotation = movementAngle; + this.turning = true; + if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { + game.activePlayer.container.rotation = this.rotation; this.turning = true; - if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { - game.activePlayer.container.rotation = this.rotation; - this.turning = true; - } - if (!game.activePlayer) return; - game.activePlayer.images.aimTrail.alpha = 0; } - } else { - this.movement.moving = false; + if (!game.activePlayer) return; + game.activePlayer.images.aimTrail.alpha = 0; } + } else { + this.movement.moving = false; + } - if (rightJoystickMoving) { - this.rotation = Math.atan2(gamepads[0].axes[3], gamepads[0].axes[2]); - this.turning = true; + if (rightJoystickMoving) { + this.rotation = Math.atan2(rightJoystickY, rightJoystickX); + this.turning = true; - if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { - game.activePlayer.container.rotation = this.rotation; - game.activePlayer.images.aimTrail.alpha = 1; - } + if (game.console.getBuiltInCVar("cv_responsive_rotation") && !game.gameOver && game.activePlayer) { + game.activePlayer.container.rotation = this.rotation; + game.activePlayer.images.aimTrail.alpha = 1; } } }); From dfd54b8bda0a646f3020ae383813038f47430be1 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 15 Nov 2024 22:04:13 -0600 Subject: [PATCH 004/205] feat: added joystick sensitivity slider for people with stick drift --- client/index.html | 16 ++++++++++++++++ client/src/scripts/managers/inputManager.ts | 8 +++++--- client/src/scripts/ui.ts | 9 +++++++++ .../scripts/utils/console/defaultClientCVars.ts | 2 ++ 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/client/index.html b/client/index.html index bf50b0b1f..62c46f935 100644 --- a/client/index.html +++ b/client/index.html @@ -680,6 +680,7 @@

+ @@ -725,6 +726,21 @@

+
+ + +