1
1
Fork 0
mirror of https://gitlab.com/Oreolek/salet-gamepad-module.git synced 2024-04-25 13:49:45 +03:00

Options select

This commit is contained in:
Alexander Yakovlev 2017-09-21 22:55:53 +07:00
parent e63c6b5cec
commit 1d1ea665ef

View file

@ -18,3 +18,35 @@ $(document).on("viewinit", () ->
salet.view.gamepads[pad.index] = new Gamepad(pad) salet.view.gamepads[pad.index] = new Gamepad(pad)
}) })
) )
joystick = () ->
salet.view.gamepads = []
if typeof navigator.getGamepads == "function"
for pad in navigator.getGamepads()
if pad?
salet.view.gamepads[pad.index] = new Gamepad(pad)
gamepad = salet.view.gamepads[0]
if $(".options").length == 0
return
if gamepad.button("dpad up") or
gamepad.button("left stick up")
$(".options li").removeClass("active")
count = $(".options li").length
window.selectedoption ?= count + 1
window.selectedoption--
if window.selectedoption < 0
window.selectedoption = count
$(".options li:nth-child(#{window.selectedoption}").addClass("active")
if gamepad.button("dpad down") or
gamepad.button("left stick down")
$(".options li").removeClass("active")
window.selectedoption ?= -1
window.selectedoption++
count = $(".options li").length
if window.selectedoption > count
window.selectedoption = 1
$(".options li:nth-child(#{window.selectedoption})").addClass("active")
if gamepad.button("a")
$(".options li.active").click()
setInterval(joystick, 100)