<commit_before>local propertyHelper = asset.require("../property_helper")
local joystickHelper = asset.require("./joystick_helper")

local function numItems(iTable)
  local counter = 0
  for k, v in ipairs(iTable) do
    counter = counter + 1
  end
  return counter
end

asset.onInitialize(function()
  local rawJoysticks = openspace.navigation.listAllJoysticks()
  local numJoysticks = numItems(rawJoysticks)
  local joystick = ""

  -- 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
  end

  -- when only one joystick is connected
  if numJoysticks == 1 then
    local joyStickName = joysticks[1]
    if joyStickName ~= nil then
      joystick = joyStickName
    end
  else
    openspace.printWarning("Cannot auto detect and add several joysticks")
    return
  end

  if joystick == "" then
    openspace.printWarning("Could not find any connected joysticks")
    return
  end

  if joystick == "Wireless Controller" then
    openspace.asset.add("./util/joysticks/ps4")
  elseif joystick == "Xbox Controller" then
    openspace.asset.add("./util/joysticks/xbox")
  elseif joystick == "Wireless Xbox Controller" then
    openspace.asset.add("./util/joysticks/xbox-wireless")
  elseif joystick == "SpaceNavigator" then
    openspace.asset.add("./util/joysticks/space-mouse-compact")
  elseif joystick == "SpaceMouse Enterprise" then
    openspace.asset.add("./util/joysticks/space-mouse-enterprise")
  elseif joystick == "3Dconnexion Universal Receiver" then
    openspace.printWarning("SpaceMouse in wireless mode cannot be automatically detected and added. Please add the matching asset file manually.")
  else
    openspace.printWarning("Could not find a matching asset for joystick: " .. joystick)
  end
end)<commit_msg>Add variable to add all detected joysticks or not<commit_after>local propertyHelper = asset.require("../property_helper")
local joystickHelper = asset.require("./joystick_helper")
local initializeAll = false

local function numItems(iTable)
  local counter = 0
  for k, v in ipairs(iTable) do
    counter = counter + 1
  end
  return counter
end

-- Add the asset cooresponding to the joystick name
local function addJoystickAsset(joystick)
  if joystick == "Wireless Controller" then
    openspace.asset.add("./util/joysticks/ps4")
  elseif joystick == "Xbox Controller" then
    openspace.asset.add("./util/joysticks/xbox")
  elseif joystick == "Wireless Xbox Controller" then
    openspace.asset.add("./util/joysticks/xbox-wireless")
  elseif joystick == "SpaceNavigator" then
    openspace.asset.add("./util/joysticks/space-mouse-compact")
  elseif joystick == "SpaceMouse Enterprise" then
    openspace.asset.add("./util/joysticks/space-mouse-enterprise")
  elseif joystick == "3Dconnexion Universal Receiver" then
    openspace.printWarning("SpaceMouse in wireless mode cannot be automatically detected and added. Please add the matching asset file manually.")
  else
    openspace.printWarning("Could not find a matching asset for joystick: " .. joystick)
  end
end

asset.onInitialize(function()
  local rawJoysticks = openspace.navigation.listAllJoysticks()
  local numJoysticks = numItems(rawJoysticks)
  local joystick = ""

  -- 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

  if numJoysticks == 0 then
    openspace.printWarning("Could not find any connected joysticks")
  elseif numJoysticks == 1 then
    addJoystickAsset(joysticks[1])
  elseif numJoysticks > 1 and initializeAll then
    for _, joyStickName in ipairs(joysticks) do
      addJoystickAsset(joyStickName)
    end
  else
    openspace.printWarning("Cannot auto detect and add several joysticks")
  end
end)

asset.onDeinitialize(function()
  if openspace.asset.isLoaded("./util/joysticks/ps4") then
    openspace.asset.remove("./util/joysticks/ps4")
  end

  if openspace.asset.isLoaded("./util/joysticks/xbox") then
    openspace.asset.remove("./util/joysticks/xbox")
  end

  if openspace.asset.isLoaded("./util/joysticks/xbox-wireless") then
    openspace.asset.remove("./util/joysticks/xbox-wireless")
  end

  if openspace.asset.isLoaded("./util/joysticks/space-mouse-compact") then
    openspace.asset.remove("./util/joysticks/space-mouse-compact")
  end

  if openspace.asset.isLoaded("./util/joysticks/space-mouse-enterprise") then
    openspace.asset.remove("./util/joysticks/space-mouse-enterprise")
  end
end)
{'fraction_non_alphanumeric': 0.09947218838814453, 'fraction_numerical': 0.004263093788063338, 'mean_word_length': 3.9617321248741186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991735', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1532, 'n_words': 399}