diff --git a/game/6_gamepadinit.coffee b/game/6_gamepadinit.coffee index b98680b..62f5ee4 100644 --- a/game/6_gamepadinit.coffee +++ b/game/6_gamepadinit.coffee @@ -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) +) diff --git a/game/translations/ru.coffee b/game/translations/ru.coffee index 25bd4f3..b116371 100644 --- a/game/translations/ru.coffee +++ b/game/translations/ru.coffee @@ -111,9 +111,12 @@ strings =
  • o: настройки
  • Управление: контроллер
    - Поддержка экспериментальна. Нет гарантии, что именно ваша модель контроллера будет работать, и именно с этой схемой управления. +

    Вы можете подключить несколько контроллеров, чтобы играть с друзьями. Будет странно, я обещаю.

    +

    Поддержка экспериментальна. Не все геймпады могут работать. Пробуйте все кнопки.

    """