2017-09-22 10:44:37 +03:00
|
|
|
# Select the previous choice
|
|
|
|
selectUp = (event, button) ->
|
|
|
|
if button != "dpad up" and button != "left stick up"
|
|
|
|
return
|
|
|
|
if $(".options li").length == 0
|
|
|
|
return
|
|
|
|
$(".options li").removeClass("active")
|
|
|
|
count = $(".options li").length
|
|
|
|
window.selectedoption--
|
2017-09-22 10:48:23 +03:00
|
|
|
if window.selectedoption <= 0
|
2017-09-22 10:44:37 +03:00
|
|
|
window.selectedoption = count
|
2017-09-22 10:48:23 +03:00
|
|
|
console.log window.selectedoption
|
2017-09-22 10:44:37 +03:00
|
|
|
$(".options li:nth-child(#{window.selectedoption}").addClass("active")
|
|
|
|
|
|
|
|
# Select the next choice
|
|
|
|
selectDown = (event, button) ->
|
|
|
|
if button != "dpad down" and button != "left stick down"
|
|
|
|
return
|
|
|
|
if $(".options li").length == 0
|
|
|
|
return
|
|
|
|
$(".options li").removeClass("active")
|
|
|
|
window.selectedoption++
|
|
|
|
count = $(".options li").length
|
|
|
|
if window.selectedoption > count
|
|
|
|
window.selectedoption = 1
|
2017-09-22 10:48:23 +03:00
|
|
|
console.log window.selectedoption
|
2017-09-22 10:44:37 +03:00
|
|
|
$(".options li:nth-child(#{window.selectedoption})").addClass("active")
|
|
|
|
|
|
|
|
selectOption = (event, button) ->
|
|
|
|
if button != "a"
|
|
|
|
return
|
|
|
|
$(".options li.active").click()
|
|
|
|
|
|
|
|
# Joystick check, fires events
|
|
|
|
joystick = () ->
|
|
|
|
if typeof navigator.getGamepads == "function"
|
|
|
|
for pad in navigator.getGamepads()
|
|
|
|
if pad?
|
|
|
|
temp = new Gamepad(pad)
|
|
|
|
if temp.pressed?
|
2017-09-22 10:48:23 +03:00
|
|
|
if salet.view.gamepads[pad.id].pressed != temp.pressed
|
|
|
|
$(document).trigger("press", temp.pressed)
|
2017-09-22 10:44:37 +03:00
|
|
|
salet.view.gamepads[pad.id] = temp
|
|
|
|
|
2017-09-20 14:49:45 +03:00
|
|
|
$(document).on("viewinit", () ->
|
2017-09-22 10:44:37 +03:00
|
|
|
# Connected gamepads (see Gamepad class)
|
|
|
|
salet.view.gamepads = {}
|
2017-09-22 11:00:42 +03:00
|
|
|
salet.view.gamepadmappings = mappings
|
|
|
|
window.addEventListener("gamepadconnected", (e) ->
|
|
|
|
salet.view.gamepads[e.gamepad.id] = new Gamepad(e.gamepad)
|
|
|
|
)
|
|
|
|
window.addEventListener("gamepaddisconnected", (e) ->
|
|
|
|
salet.view.gamepads[e.gamepad.id] = undefined
|
|
|
|
)
|
|
|
|
setInterval(joystick, 50) # 50 = 1000 / 20 fps
|
2017-09-20 14:49:45 +03:00
|
|
|
)
|
2017-09-21 18:55:53 +03:00
|
|
|
|
2017-09-22 10:48:23 +03:00
|
|
|
window.selectedoption ?= 1
|
2017-09-22 10:44:37 +03:00
|
|
|
$(document).on("press", selectUp)
|
|
|
|
$(document).on("press", selectDown)
|
|
|
|
$(document).on("press", selectOption)
|