summaryrefslogtreecommitdiffhomepage
path: root/controller.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-12-20 06:05:56 +0100
committerGitHub <noreply@github.com>2016-12-20 06:05:56 +0100
commit493a89fb354ee6ce667d29a7b96bb4fdd0f6697f (patch)
treed862856d4b62a6c996ea16211ebd321206e236b4 /controller.lua
parented6ad6687aeb5359af48bc97c1dbf5dd66842c9c (diff)
parent73bcd524906c51d43b22b3ea68c64b38f130bea6 (diff)
downloadroflnauts-493a89fb354ee6ce667d29a7b96bb4fdd0f6697f.zip
roflnauts-493a89fb354ee6ce667d29a7b96bb4fdd0f6697f.tar.gz
roflnauts-493a89fb354ee6ce667d29a7b96bb4fdd0f6697f.tar.bz2
Merge pull request #16 from nthirtyone/menuv1.0-pre.4
Menu
Diffstat (limited to 'controller.lua')
-rw-r--r--controller.lua23
1 files changed, 16 insertions, 7 deletions
diff --git a/controller.lua b/controller.lua
index 513af45..e435d63 100644
--- a/controller.lua
+++ b/controller.lua
@@ -16,6 +16,7 @@ function Controller.controlreleased(set, action, key) end
-- Create new controls set.
function Controller.registerSet(left, right, up, down, attack, jump, joystick)
+ if not Controller.isJoystickUnique(joystick) then return end
local set = {}
set.left = left or "left"
set.right = right or "right"
@@ -29,6 +30,21 @@ function Controller.registerSet(left, right, up, down, attack, jump, joystick)
return set
end
+-- Get table of controls sets.
+function Controller.getSets()
+ return Controller.sets
+end
+
+-- Checks if given joystick is unique in current set of Controller sets
+function Controller.isJoystickUnique(joystick)
+ if joystick ~= nil then
+ for _,set in pairs(Controller.sets) do
+ if set.joystick == joystick then return false end
+ end
+ end
+ return true
+end
+
-- Tests all sets if they have control assigned to given key and joystick.
function Controller.testSets(key, joystick)
for i,set in pairs(Controller.sets) do
@@ -144,13 +160,6 @@ end
-- Load gamepad mappings from db file and init module
function Controller.load()
love.joystick.loadGamepadMappings("gamecontrollerdb.txt")
- Controller.registerSet("left", "right", "up", "down", "return", "rshift")
- Controller.registerSet("a", "d", "w", "s", "g", "h")
-end
-
--- Create new sets when new joystick is added
-function Controller.joystickadded(joystick)
- Controller.registerSet("axis:leftx-", "axis:leftx+", "axis:lefty-", "axis:lefty+", "a", "b", joystick)
end
-- Gamepad input callbacks