proper gamepad support
default/mapgen/master There was a failure building this commit
Details
default/mapgen/master There was a failure building this commit
Details
This commit is contained in:
parent
35db50d61d
commit
bb88e63d58
|
@ -1,11 +1,7 @@
|
|||
retval = {}
|
||||
|
||||
# Select the previous choice
|
||||
retval.selectUp = (event, button, padid) ->
|
||||
if button != "dpad up" and button != "left stick up"
|
||||
return
|
||||
selectUp = (event, button, padid) ->
|
||||
if $(".options li").length == 0
|
||||
return selectUpLink(event, button, padid)
|
||||
return
|
||||
$(".options li").removeClass("active")
|
||||
count = $(".options li").length
|
||||
window.selectedoption--
|
||||
|
@ -14,11 +10,9 @@ retval.selectUp = (event, button, padid) ->
|
|||
$(".options li:nth-child(#{window.selectedoption}").addClass("active")
|
||||
|
||||
# Select the next choice
|
||||
retval.selectDown = (event, button, padid) ->
|
||||
if button != "dpad down" and button != "left stick down"
|
||||
return
|
||||
selectDown = (event, button, padid) ->
|
||||
if $(".options li").length == 0
|
||||
return selectDownLink(event, button, padid)
|
||||
return
|
||||
$(".options li").removeClass("active")
|
||||
window.selectedoption++
|
||||
count = $(".options li").length
|
||||
|
@ -26,25 +20,7 @@ retval.selectDown = (event, button, padid) ->
|
|||
window.selectedoption = 1
|
||||
$(".options li:nth-child(#{window.selectedoption})").addClass("active")
|
||||
|
||||
# Select the next link inside room text
|
||||
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) ->
|
||||
decreaseTabindex = (tabid) ->
|
||||
tabid--
|
||||
if tabid < 0
|
||||
# tabindex can't be negative, choosing maximum tabindex
|
||||
|
@ -54,31 +30,33 @@ retval.decreaseTabindex = (tabid) ->
|
|||
maxtab = $(element).attr("tabindex")
|
||||
tabid = maxtab
|
||||
if $("#current-room [tabindex='#{tabid}']").length == 0
|
||||
return salet.view.decreaseTabindex(tabid)
|
||||
return decreaseTabindex(tabid)
|
||||
return tabid
|
||||
|
||||
retval.increaseTabindex = (tabid, maxtab) ->
|
||||
increaseTabindex = (tabid, maxtab) ->
|
||||
if tabid < maxtab
|
||||
tabid++
|
||||
else
|
||||
tabid = 0
|
||||
if $("#current-room [tabindex='#{tabid}']").length == 0
|
||||
return salet.view.increaseTabindex(tabid)
|
||||
return increaseTabindex(tabid)
|
||||
return tabid
|
||||
|
||||
selectOption = (event, button) ->
|
||||
if button != "a"
|
||||
return
|
||||
selectOption = () ->
|
||||
$(".options li.active").click()
|
||||
|
||||
# enter the options room
|
||||
enterOptions = (event, button, padid) ->
|
||||
if button != "back" and button != "start"
|
||||
return
|
||||
if button == "start"
|
||||
return salet.goTo(salet.optionsRoom)
|
||||
if button == "back" and salet.currentRoom == salet.optionsRoom
|
||||
return salet.goBack()
|
||||
if salet.currentRoom != salet.optionsRoom
|
||||
return switchTab("options")
|
||||
else
|
||||
return switchTab("story")
|
||||
|
||||
enterMap = () ->
|
||||
if salet.currentRoom != salet.optionsRoom
|
||||
return switchTab("map")
|
||||
else
|
||||
return switchTab("story")
|
||||
|
||||
# Joystick check, fires events
|
||||
joystick = () ->
|
||||
|
@ -99,7 +77,7 @@ joystick = () ->
|
|||
$(document).trigger("axis", axisname, newval, padid)
|
||||
salet.view.gamepads[pad.id] = temp
|
||||
|
||||
$(document).on("view_init", () ->
|
||||
$(document).on("init", () ->
|
||||
# Connected gamepads (see Gamepad class)
|
||||
salet.view.gamepads = {}
|
||||
salet.view.gamepadmappings = mappings
|
||||
|
@ -113,9 +91,16 @@ $(document).on("view_init", () ->
|
|||
)
|
||||
|
||||
window.selectedoption ?= 1
|
||||
$(document).on("press", salet.view.selectUp)
|
||||
$(document).on("press", salet.view.selectDown)
|
||||
$(document).on("press", selectOption)
|
||||
$(document).on("press", enterOptions)
|
||||
|
||||
salet.gamepad = retval
|
||||
$(document).on("press", (event, button, padid) ->
|
||||
switch (button)
|
||||
when "dpad up", "left stick up"
|
||||
return selectUp(event, button, padid)
|
||||
when "dpad down", "left stick down"
|
||||
return selectDown(event, button, padid)
|
||||
when "a","x"
|
||||
return selectOption()
|
||||
when "back"
|
||||
return enterMap(event, button, padid)
|
||||
when "start"
|
||||
return enterOptions(event, button, padid)
|
||||
)
|
||||
|
|
|
@ -111,9 +111,12 @@ strings =
|
|||
<li><kbd>o</kbd>: настройки</li>
|
||||
</ul>
|
||||
<h5>Управление: контроллер</h5>
|
||||
<small>Поддержка экспериментальна. Нет гарантии, что именно ваша модель контроллера будет работать, и именно с этой схемой управления.</small>
|
||||
<p>Вы можете подключить несколько контроллеров, чтобы играть с друзьями. Будет странно, я обещаю.</p>
|
||||
<p>Поддержка экспериментальна. Не все геймпады могут работать. Пробуйте все кнопки.</p>
|
||||
<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>
|
||||
</ul>
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue