From b739e555026471db11e24cb4a92f55509e717761 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 06:43:11 +0200 Subject: Unique joysticks for sets --- controller.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'controller.lua') diff --git a/controller.lua b/controller.lua index 5ed7dd2..fde63c1 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" @@ -34,6 +35,16 @@ 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 -- cgit v1.1