From 1d1ea665ef3a0d16eed67a7760fb760995425e03 Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Thu, 21 Sep 2017 22:55:53 +0700 Subject: [PATCH] Options select --- src/init.coffee | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/init.coffee b/src/init.coffee index 060caae..656b7eb 100644 --- a/src/init.coffee +++ b/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)