Browse Source

Options select

master
Alexander Yakovlev 5 years ago
parent
commit
1d1ea665ef
  1. 32
      src/init.coffee

32
src/init.coffee

@ -18,3 +18,35 @@ $(document).on("viewinit", () ->
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)

Loading…
Cancel
Save