<commit_before>local tableLength = function(table)
  local count = 0
  for _ in pairs(table) do count = count + 1 end
  return count
end


local registerSpiceKernels = function (spiceAsset, kernels)
  spiceAsset.onInitialize(function ()
    for i, kernel in ipairs(kernels) do
      openspace.spice.loadKernel(kernel)
    end
  end)
  spiceAsset.onDeinitialize(function ()
    for i = #kernels, 1, -1 do
      local kernel = kernels[i]
      openspace.spice.unloadKernel(kernel) 
    end
  end)
end

local registerSceneGraphNodes = function (sceneAsset, nodes, override)
  override = override or false
  if not override then
    if tableLength(nodes) == 0 then
      openspace.printWarning(sceneAsset.filePath .. ": Register function was called with an empty node list. Pass 'true' as third argument to silence this warning.")
      return
    end
  end


  sceneAsset.onInitialize(function ()
    for i, node in ipairs(nodes) do
      openspace.addSceneGraphNode(node)
    end
  end)
  sceneAsset.onDeinitialize(function ()
    for i = #nodes, 1, -1 do
      node = nodes[i]
      openspace.removeSceneGraphNode(node.Identifier)
    end
  end)
end


local registerScreenSpaceRenderables = function (sceneAsset, renderables, override)
  override = override or false
  if not override then
    if tableLength(renderables) == 0 then
      openspace.printWarning(sceneAsset.filePath .. ": Register function was called with an empty node list. Pass 'true' as third argument to silence this warning.")
      return
    end
  end

  sceneAsset.onInitialize(function ()
    for i, node in ipairs(renderables) do
      openspace.addScreenSpaceRenderable(node)
    end
  end)
  sceneAsset.onDeinitialize(function ()
    for i = #renderables, 1, -1 do
      renderable = renderables[i]
      openspace.removeScreenSpaceRenderable(renderable.Identifier)
    end
  end)
end

local registerDashboardItems = function (dashboardAsset, items)
  dashboardAsset.onInitialize(
    function ()
      for i, item in ipairs(items) do
        openspace.dashboard.addDashboardItem(item)
      end
    end
  )
  dashboardAsset.onDeinitialize(function ()
    for i = #items, 1, -1 do
      local item = items[i]
      openspace.dashboard.removeDashboardItem(item.Identifier)
    end
  end)
end

local registerSceneGraphNodesAndExport = function (sceneAsset, nodes, override)
  override = override or false
  if not override then
    if tableLength(nodes) == 0 then
      openspace.printWarning(sceneAsset.filePath .. ": Register function was called with an empty node list. Pass 'true' as third argument to silence this warning.")
      return
    end
  end

  for i, node in ipairs(nodes) do
    if not node.Identifier then
      openspace.printError("Could not load asset as Identifier was missing")
    end
  end

  sceneAsset.onInitialize(function ()
    for i, node in ipairs(nodes) do
      openspace.addSceneGraphNode(node)
    end
  end)
  sceneAsset.onDeinitialize(function ()
    for i = #nodes, 1, -1 do
      local node = nodes[i]
      openspace.removeSceneGraphNode(node.Identifier)
    end
  end)

  for i, node in ipairs(nodes) do
    sceneAsset.export(node.Identifier, node)
  end
end

local requireAll = function (sceneAsset, directory)
  function string.ends(String,End)
    return End=='' or string.sub(String,-string.len(End))==End
  end

  local result = {}

  local files = openspace.walkDirectoryFiles(sceneAsset.localResource('') .. directory, true)
  for _, file in pairs(files) do
    if file:ends('.asset') then
      openspace.printDebug("Requiring: " .. file:sub(file:find(directory), -7))
      local exports = sceneAsset.require(file:sub(1, -7))
      table.insert(result, exports)
    end
  end

  return result
end

local getDefaultLightSources = function (solarSystemBarycenterIdentifier)
  local sourceList = {
    {
      Type = "SceneGraphLightSource",
      Identifier = "Sun",
      Node = solarSystemBarycenterIdentifier,
      Intensity = 1.0
    },
    {
      Identifier = "Camera",
      Type = "CameraLightSource",
      Intensity = 0.5
    }
  }
  return sourceList
end


local createModelPart = function (parent, sunLightSourceNode, models, geometry, texture, performShading)
  local lightSources = {}
  if performShading then
    lightSources[1] = {
        Type = "SceneGraphLightSource",
        Identifier = "Sun",
        Node = sunLightSourceNode,
        Intensity = 1.0
    }
  end
  return {
    Identifier = parent .. "-" .. geometry,
    Parent = parent,
    Renderable = {
      Type = "RenderableModel",
      GeometryFile =  models .. "/" .. geometry .. ".obj",
      LightSources = lightSources,
      PerformShading = performShading,
      DisableFaceCulling = true 
    },
    GUI = {
      Hidden = true
    }
  }
end

asset.export("registerSceneGraphNodes", registerSceneGraphNodes)
asset.export("registerSceneGraphNodesAndExport", registerSceneGraphNodesAndExport)
asset.export("registerScreenSpaceRenderables", registerScreenSpaceRenderables)<commit_msg>Update assethelper to new version<commit_after>local tableLength = function(table)
  local count = 0
  for _ in pairs(table) do count = count + 1 end
  return count
end


local registerSpiceKernels = function (spiceAsset, kernels)
  spiceAsset.onInitialize(function ()
    for i, kernel in ipairs(kernels) do
      openspace.spice.loadKernel(kernel)
    end
  end)
  spiceAsset.onDeinitialize(function ()
    for i = #kernels, 1, -1 do
      local kernel = kernels[i]
      openspace.spice.unloadKernel(kernel)
    end
  end)
end

local registerSceneGraphNodes = function (sceneAsset, nodes, override)
  override = override or false
  if not override then
    if tableLength(nodes) == 0 then
      openspace.printWarning(sceneAsset.filePath .. ": Register function was called with an empty node list. Pass 'true' as third argument to silence this warning.")
      return
    end
  end


  sceneAsset.onInitialize(function ()
    for i, node in ipairs(nodes) do
      openspace.addSceneGraphNode(node)
    end
  end)
  sceneAsset.onDeinitialize(function ()
    for i = #nodes, 1, -1 do
      node = nodes[i]
      openspace.removeSceneGraphNode(node.Identifier)
    end
  end)
end


local registerScreenSpaceRenderables = function (sceneAsset, renderables, override)
  override = override or false
  if not override then
    if tableLength(renderables) == 0 then
      openspace.printWarning(sceneAsset.filePath .. ": Register function was called with an empty node list. Pass 'true' as third argument to silence this warning.")
      return
    end
  end

  sceneAsset.onInitialize(function ()
    for i, node in ipairs(renderables) do
      openspace.addScreenSpaceRenderable(node)
    end
  end)
  sceneAsset.onDeinitialize(function ()
    for i = #renderables, 1, -1 do
      local renderable = renderables[i]
      openspace.removeScreenSpaceRenderable(renderable.Identifier)
    end
  end)
end

local registerDashboardItems = function (dashboardAsset, items)
  dashboardAsset.onInitialize(
    function ()
      for i, item in ipairs(items) do
        openspace.dashboard.addDashboardItem(item)
      end
    end
  )
  dashboardAsset.onDeinitialize(function ()
    for i = #items, 1, -1 do
      local item = items[i]
      openspace.dashboard.removeDashboardItem(item.Identifier)
    end
  end)
end

local registerSceneGraphNodesAndExport = function (sceneAsset, nodes, override)
  override = override or false
  if not override then
    if tableLength(nodes) == 0 then
      openspace.printWarning(sceneAsset.filePath .. ": Register function was called with an empty node list. Pass 'true' as third argument to silence this warning.")
      return
    end
  end

  for i, node in ipairs(nodes) do
    if not node.Identifier then
      openspace.printError("Could not load asset as Identifier was missing")
    end
  end

  sceneAsset.onInitialize(function ()
    for i, node in ipairs(nodes) do
      openspace.addSceneGraphNode(node)
    end
  end)
  sceneAsset.onDeinitialize(function ()
    for i = #nodes, 1, -1 do
      local node = nodes[i]
      openspace.removeSceneGraphNode(node.Identifier)
    end
  end)

  for i, node in ipairs(nodes) do
    sceneAsset.export(node.Identifier, node)
  end
end

local requireAll = function (sceneAsset, directory)
  function string.ends(String,End)
    return End=='' or string.sub(String,-string.len(End))==End
  end

  local result = {}

  local files = openspace.walkDirectoryFiles(sceneAsset.localResource('') .. directory, true)
  for _, file in pairs(files) do
    if file:ends('.asset') then
      openspace.printDebug("Requiring: " .. file:sub(file:find(directory), -7))
      local exports = sceneAsset.require(file:sub(1, -7))
      table.insert(result, exports)
    end
  end

  return result
end

local getDefaultLightSources = function (solarSystemBarycenterIdentifier)
  local sourceList = {
    {
      Type = "SceneGraphLightSource",
      Identifier = "Sun",
      Node = solarSystemBarycenterIdentifier,
      Intensity = 1.0
    },
    {
      Identifier = "Camera",
      Type = "CameraLightSource",
      Intensity = 0.5
    }
  }
  return sourceList
end


local createModelPart = function (parent, sunLightSourceNode, models, geometry, texture, performShading)
  local lightSources = {}
  if performShading then
    lightSources[1] = {
        Type = "SceneGraphLightSource",
        Identifier = "Sun",
        Node = sunLightSourceNode,
        Intensity = 1.0
    }
  end
  return {
    Identifier = parent .. "-" .. geometry,
    Parent = parent,
    Renderable = {
      Type = "RenderableModel",
      GeometryFile =  models .. "/" .. geometry .. ".obj",
      LightSources = lightSources,
      PerformShading = performShading,
      DisableFaceCulling = true
    },
    GUI = {
      Hidden = true
    }
  }
end

asset.export("registerSceneGraphNodes", registerSceneGraphNodes)
asset.export("registerSceneGraphNodesAndExport", registerSceneGraphNodesAndExport)
asset.export("registerScreenSpaceRenderables", registerScreenSpaceRenderables)
{'fraction_non_alphanumeric': 0.0890397284887203, 'fraction_numerical': 0.004991016170892394, 'mean_word_length': 3.2489397794741306, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '4494271', 'n_tokens_mistral': 2967, 'n_tokens_neox': 2913, 'n_words': 828}