You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

61 lines
1.9 KiB

# 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--
if window.selectedoption <= 0
window.selectedoption = count
console.log window.selectedoption
$(".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
console.log window.selectedoption
$(".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?
if salet.view.gamepads[pad.id].pressed != temp.pressed
$(document).trigger("press", temp.pressed)
salet.view.gamepads[pad.id] = temp
$(document).on("viewinit", () ->
# Connected gamepads (see Gamepad class)
salet.view.gamepads = {}
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
)
window.selectedoption ?= 1
$(document).on("press", selectUp)
$(document).on("press", selectDown)
$(document).on("press", selectOption)