From 48c547a7f43ff5aab7fe5b26720463ff83cdd832 Mon Sep 17 00:00:00 2001 From: krypek Date: Wed, 12 Jun 2024 14:28:23 +0200 Subject: [PATCH] Add gamepad support --- src/game-loop.ts | 1 - src/update-packet-gather.ts | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/game-loop.ts b/src/game-loop.ts index 4a6b318..92a1c53 100644 --- a/src/game-loop.ts +++ b/src/game-loop.ts @@ -16,7 +16,6 @@ ig.System.inject({ if (window.requestAnimationFrame) { window.requestAnimationFrame(drawLoop) } - console.log(client.serverSettings?.globalTps) if (client.isConnected()) { const tps = 1e3 / client.serverSettings!.globalTps this.intervalId = setInterval(this.run.bind(this), tps) as unknown as number diff --git a/src/update-packet-gather.ts b/src/update-packet-gather.ts index 874b9a3..9b339aa 100644 --- a/src/update-packet-gather.ts +++ b/src/update-packet-gather.ts @@ -1,4 +1,4 @@ -import { getDummyUpdateInputFromIgInput, type FromClientUpdatePacket } from 'cc-multibakery/src/api' +import { getDummyUpdateGamepadInputFromIgGamepadManager, getDummyUpdateInputFromIgInput, type FromClientUpdatePacket } from 'cc-multibakery/src/api' export class UpdatePacketGather { private state!: FromClientUpdatePacket @@ -28,6 +28,12 @@ export class UpdatePacketGather { this.state.input = getDummyUpdateInputFromIgInput(ig.input) } + private gamepadInput() { + if (!ig?.gamepad) return + if (this.state.paused) throw new Error() + + this.state.gamepadInput = getDummyUpdateGamepadInputFromIgGamepadManager(ig.gamepad) + } private gatherInput() { if (this.state.paused) throw new Error() if (!ig.game?.playerEntity) return @@ -52,6 +58,7 @@ export class UpdatePacketGather { this.relativeCursorPos() this.gatherInput() this.input() + this.gamepadInput() } else { this.state.paused = true }