Skip to content

Commit

Permalink
Add gamepad support
Browse files Browse the repository at this point in the history
  • Loading branch information
krypciak committed Jun 12, 2024
1 parent 4e42708 commit 48c547a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/game-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion src/update-packet-gather.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -52,6 +58,7 @@ export class UpdatePacketGather {
this.relativeCursorPos()
this.gatherInput()
this.input()
this.gamepadInput()
} else {
this.state.paused = true
}
Expand Down

0 comments on commit 48c547a

Please sign in to comment.