Small clean up of auto detect asset

This commit is contained in:
Malin E
2022-04-20 14:27:43 +02:00
parent 425b771d8d
commit 1d2011e7a2
+14 -20
View File
@@ -10,11 +10,21 @@ local function numItems(iTable)
end
asset.onInitialize(function()
local joysticks = openspace.navigation.listAllJoysticks()
local numJoysticks = numItems(joysticks)
local rawJoysticks = openspace.navigation.listAllJoysticks()
local numJoysticks = numItems(rawJoysticks)
local joystick = ""
-- Is any connected?
-- Remove the SpaceMouse emulator if it exists
local joysticks = {}
for _, joyStickName in ipairs(rawJoysticks) do
if joyStickName == "3Dconnexion KMJ Emulator" then
numJoysticks = numJoysticks - 1
else
table.insert(joysticks, joyStickName)
end
end
-- Is any joysticks connected?
if numJoysticks == 0 then
openspace.printWarning("Could not find any connected joysticks")
return
@@ -23,25 +33,9 @@ asset.onInitialize(function()
-- when only one joystick is connected
if numJoysticks == 1 then
local joyStickName = joysticks[1]
if joyStickName ~= "3Dconnexion KMJ Emulator" then -- Skip the SpaceMouse emulator
if joyStickName ~= nil then
joystick = joyStickName
end
-- When two joystics are connected, make sure the second one is not the SpaceMouse emulator
-- If so then it is essentially only one connected
elseif numJoysticks == 2 then
local onlyOne = false
for _, joyStickName in ipairs(joysticks) do
if joyStickName == "3Dconnexion KMJ Emulator" then -- Skip the SpaceMouse emulator
onlyOne = true
else
joystick = joyStickName
end
end
if onlyOne == false then
openspace.printWarning("Cannot auto detect and add several joysticks")
return
end
else
openspace.printWarning("Cannot auto detect and add several joysticks")
return