GE Lua Documentation

Press F to search!

onGameplaySelectorGetDetails

Definition


-- @/lua/ge/extensions/ui/gameplaySelector/tileGenerators/levelTiles.lua:141


local function onGameplaySelectorGetDetails(itemDetails, details, buttonInstance, backend)
  local levelName, spawnPointObjectName = itemDetails.levelName, itemDetails.spawnPointObjectName
  if not levelName then
    return
  end
  local level, spawnPoint = core_levels.getLevelByName(levelName), nil
  if level then
    for _, s in ipairs(level.spawnPoints) do
      if s.objectname == spawnPointObjectName then
        spawnPoint = s
        break
      end
    end
  end
  local name = spawnPoint and spawnPoint.translationId or spawnPoint.name or spawnPoint.objectname or "Unnamed Spawnpoint"
  name = translate(name)
  if level.title then
    name = string.format("%s (%s)", name, translate(level.title))
  end

  local data = {
    headerTitle = name,
    description = translate(level.description),
    preview = spawnPoint.previews and spawnPoint.previews[1] or nil,
    isFavourite = backend.isFavourite(getKeyFromDetails(itemDetails)),
    buttonInfo = {},
    specifications = getLevelSpecifications(level),
    levelTitle = translate(level.title),
    tags = {},
  }

  -- Add tags for all sourceIcons
  if level.official then
    table.insert(data.tags, {icon = "beamNG", label = "BeamNG - Official"})
  end
  if level.authors == "BeamNG & Camshaft Software" then
    table.insert(data.tags, {svg = "/ui/assets/Original/camshaft_automation_logo.svg", label = "Camshaft Software"})
  end
  if level.isAuxiliary then
    table.insert(data.tags, {icon = "bug", label = "Auxiliary"})
  end

  -- Add mod information tags
  if level.modID then
    local mod = core_modmanager.getModNameFromID(level.modID)
    if mod then
      table.insert(data.tags, {icon = "puzzleModule", label = level.modTitle or level.modName, goToMod = mod.modID})
    end
  end

  if buttonInstance and backend then
    local defaultAction = backend.getUiData().displayData.defaultFreeroamAction or "startFreeroam"
    local startIsPrimary = defaultAction == "startFreeroam"

    table.insert(data.buttonInfo,
      buttonInstance.addButton(function()
        -- Track recent usage
        backend.trackRecent(itemDetails.key)
        -- Start freeroam
        freeroam_freeroam.startFreeroamByName(levelName, spawnPointObjectName)
      end, {
        label = "Start Freeroam",
        icon = "road",
        primary = startIsPrimary,
        isDoubleClickAction = startIsPrimary,
      }))
    table.insert(data.buttonInfo,
      buttonInstance.addButton(function()
        -- open freeroam configurator with current level and spawn point
        freeroam_freeroamConfigurator.setLevel(levelName, spawnPointObjectName)
        guihooks.trigger("ChangeState", "menu.freeroamconfigurator")
      end, {
        label = "Configure",
        icon = "adjust",
        primary = not startIsPrimary,
        isDoubleClickAction = not startIsPrimary,
    }))

    extensions.hook("onFreeroamSelectorGetDetails", data, level, spawnPointObjectName, buttonInstance, backend)
    local customButtons = backend.getCustomDetailsButtons()
    if customButtons and next(customButtons) then
      table.clear(data.buttonInfo)
      for _, button in ipairs(customButtons) do
        table.insert(data.buttonInfo, buttonInstance.addButton(function()
          button.callback(itemDetails.levelName, itemDetails.spawnPointObjectName, itemDetails.key)
          if button.meta.trackRecent then
            backend.trackRecent(itemDetails.key)
          end
        end, button.meta))
      end
    end
  end
  table.insert(details, data)
end

Callers

@/lua/ge/extensions/ui/gameplaySelector/tileGenerators/scenarioTiles.lua

local function onGameplaySelectorGetDetails(itemDetails, details, buttonInstance, backend)
  local scenarioSourceFile = itemDetails.scenarioSourceFile
@/lua/ge/extensions/ui/gameplaySelector/tileGenerators/campaignTiles.lua

local function onGameplaySelectorGetDetails(itemDetails, details, buttonInstance, backend)
  local campaignSourceFile = itemDetails.campaignSourceFile
@/lua/ge/extensions/freeroam/freeroamConfigurator.lua
  local success = pcall(function()
    ui_gameplaySelector_tileGenerators_levelTiles.onGameplaySelectorGetDetails(
      {levelName = levelName, spawnPointObjectName = spawnPointName},
@/lua/ge/extensions/ui/gameplaySelector/tileGenerators/missionTiles.lua

local function onGameplaySelectorGetDetails(itemDetails, details, buttonInstance, backend)
  local missionId = itemDetails.missionId