proper gamepad support
Some checks failed
default/mapgen/master There was a failure building this commit

This commit is contained in:
Alexander Yakovlev 2018-10-28 01:53:27 +07:00
parent 35db50d61d
commit bb88e63d58
2 changed files with 38 additions and 50 deletions

View file

@ -1,11 +1,7 @@
retval = {}
# Select the previous choice # Select the previous choice
retval.selectUp = (event, button, padid) -> selectUp = (event, button, padid) ->
if button != "dpad up" and button != "left stick up"
return
if $(".options li").length == 0 if $(".options li").length == 0
return selectUpLink(event, button, padid) return
$(".options li").removeClass("active") $(".options li").removeClass("active")
count = $(".options li").length count = $(".options li").length
window.selectedoption-- window.selectedoption--
@ -14,11 +10,9 @@ retval.selectUp = (event, button, padid) ->
$(".options li:nth-child(#{window.selectedoption}").addClass("active") $(".options li:nth-child(#{window.selectedoption}").addClass("active")
# Select the next choice # Select the next choice
retval.selectDown = (event, button, padid) -> selectDown = (event, button, padid) ->
if button != "dpad down" and button != "left stick down"
return
if $(".options li").length == 0 if $(".options li").length == 0
return selectDownLink(event, button, padid) return
$(".options li").removeClass("active") $(".options li").removeClass("active")
window.selectedoption++ window.selectedoption++
count = $(".options li").length count = $(".options li").length
@ -26,25 +20,7 @@ retval.selectDown = (event, button, padid) ->
window.selectedoption = 1 window.selectedoption = 1
$(".options li:nth-child(#{window.selectedoption})").addClass("active") $(".options li:nth-child(#{window.selectedoption})").addClass("active")
# Select the next link inside room text decreaseTabindex = (tabid) ->
selectDownLink = (event, button, padid) ->
tabid = $("#current-room .active").first().attr("tabindex")
$("#current-room .active").removeClass("active")
maxtab = 0
for element in $("#current-room [tabindex]")
if maxtab < $(element).attr("tabindex")
maxtab = $(element).attr("tabindex")
tabid = salet.view.increaseTabindex(tabid, maxtab)
$("#current-room [tabindex='#{tabid}']").addClass("active")
# Select the previous link inside room text
selectUpLink = (event, button, padid) ->
tabid = $("#current-room .active").attr("tabindex")
$("#current-room .active").removeClass("active")
tabid = salet.view.decreaseTabindex(tabid)
$("#current-room [tabindex='#{tabid}']").addClass("active")
retval.decreaseTabindex = (tabid) ->
tabid-- tabid--
if tabid < 0 if tabid < 0
# tabindex can't be negative, choosing maximum tabindex # tabindex can't be negative, choosing maximum tabindex
@ -54,31 +30,33 @@ retval.decreaseTabindex = (tabid) ->
maxtab = $(element).attr("tabindex") maxtab = $(element).attr("tabindex")
tabid = maxtab tabid = maxtab
if $("#current-room [tabindex='#{tabid}']").length == 0 if $("#current-room [tabindex='#{tabid}']").length == 0
return salet.view.decreaseTabindex(tabid) return decreaseTabindex(tabid)
return tabid return tabid
retval.increaseTabindex = (tabid, maxtab) -> increaseTabindex = (tabid, maxtab) ->
if tabid < maxtab if tabid < maxtab
tabid++ tabid++
else else
tabid = 0 tabid = 0
if $("#current-room [tabindex='#{tabid}']").length == 0 if $("#current-room [tabindex='#{tabid}']").length == 0
return salet.view.increaseTabindex(tabid) return increaseTabindex(tabid)
return tabid return tabid
selectOption = (event, button) -> selectOption = () ->
if button != "a"
return
$(".options li.active").click() $(".options li.active").click()
# enter the options room # enter the options room
enterOptions = (event, button, padid) -> enterOptions = (event, button, padid) ->
if button != "back" and button != "start" if salet.currentRoom != salet.optionsRoom
return return switchTab("options")
if button == "start" else
return salet.goTo(salet.optionsRoom) return switchTab("story")
if button == "back" and salet.currentRoom == salet.optionsRoom
return salet.goBack() enterMap = () ->
if salet.currentRoom != salet.optionsRoom
return switchTab("map")
else
return switchTab("story")
# Joystick check, fires events # Joystick check, fires events
joystick = () -> joystick = () ->
@ -99,7 +77,7 @@ joystick = () ->
$(document).trigger("axis", axisname, newval, padid) $(document).trigger("axis", axisname, newval, padid)
salet.view.gamepads[pad.id] = temp salet.view.gamepads[pad.id] = temp
$(document).on("view_init", () -> $(document).on("init", () ->
# Connected gamepads (see Gamepad class) # Connected gamepads (see Gamepad class)
salet.view.gamepads = {} salet.view.gamepads = {}
salet.view.gamepadmappings = mappings salet.view.gamepadmappings = mappings
@ -113,9 +91,16 @@ $(document).on("view_init", () ->
) )
window.selectedoption ?= 1 window.selectedoption ?= 1
$(document).on("press", salet.view.selectUp) $(document).on("press", (event, button, padid) ->
$(document).on("press", salet.view.selectDown) switch (button)
$(document).on("press", selectOption) when "dpad up", "left stick up"
$(document).on("press", enterOptions) return selectUp(event, button, padid)
when "dpad down", "left stick down"
salet.gamepad = retval return selectDown(event, button, padid)
when "a","x"
return selectOption()
when "back"
return enterMap(event, button, padid)
when "start"
return enterOptions(event, button, padid)
)

View file

@ -111,9 +111,12 @@ strings =
<li><kbd>o</kbd>: настройки</li> <li><kbd>o</kbd>: настройки</li>
</ul> </ul>
<h5>Управление: контроллер</h5> <h5>Управление: контроллер</h5>
<small>Поддержка экспериментальна. Нет гарантии, что именно ваша модель контроллера будет работать, и именно с этой схемой управления.</small> <p>Вы можете подключить несколько контроллеров, чтобы играть с друзьями. Будет странно, я обещаю.</p>
<p>Поддержка экспериментальна. Не все геймпады могут работать. Пробуйте все кнопки.</p>
<ul><li>Крестовина или левый стик: выбор варианта (без выполнения)</li> <ul><li>Крестовина или левый стик: выбор варианта (без выполнения)</li>
<li><kbd>A</kbd>, <kbd><span class="oi oi-x"><span class="sr-only">крест</span></span></kbd>, <kbd>1</kbd>: выполнение варианта</li> <li><kbd>Start</kbd>: настройки (ещё раз, чтобы вернуться к игре)</li>
<li><kbd>Select</kbd>: карта (ещё раз, чтобы вернуться к игре)</li>
<li><kbd>A</kbd>, <kbd>X</kbd>, <kbd><span class="oi oi-x"><span class="sr-only">крест</span></span></kbd>, <kbd>1</kbd>: выполнение варианта</li>
<li>Верхние курки: переключение вкладок</li> <li>Верхние курки: переключение вкладок</li>
</ul> </ul>
""" """