GE Lua Documentation

Press F to search!

getMissionTiles

Definition


-- @/lua/ge/extensions/gameplay/missions/missionScreen.lua:859
local function getMissionTiles(ids)
  local tilesById = {}

  local groupsByKey = {}
  groupsByKey["all"] = {meta = {type = "all"}, sortingKey = "date", sortingDirection = "desc"}
  for _, diff in pairs(gameplay_missions_missions.getAdditionalAttributes().difficulty.valuesByKey) do
    groupsByKey["difficulty_"..diff.key] = {label = "Difficulty: " ..diff.translationKey, meta = {type = "difficulty"}}
  end



  for _, m in ipairs(gameplay_missions_missions.get()) do
    if not ids then
      if not m.careerSetup or not m.careerSetup.showInFreeroam  or not m.unlocks.visible  then goto continue end
    else
      if not ids[m.id] then goto continue end
    end

    local filterData = {
      groupTags = {},
      sortingValues = {},
    }
    tilesById[m.id] = makeMissionTile(m)

    -- all
    filterData.groupTags['all'] = true
    filterData.sortingValues['date'] = tonumber(m.date) or 0

    -- missionType
    filterData.groupTags['missionType_'..m.missionTypeLabel] = true
    if not groupsByKey['missionType_'..m.missionTypeLabel] then
      groupsByKey['missionType_'..m.missionTypeLabel] = {label = m.missionTypeLabel, meta = {type = "missionType"}}
    end

    -- branch/skill
    local branchSkill = "branchSkill_"..string.format("%s_%s", m.careerSetup.branch or "No Branch", m.careerSetup.skill or "No Skill")
    filterData.groupTags[branchSkill] = true
    if not groupsByKey[branchSkill] then
      groupsByKey[branchSkill] = {label = string.format("%s / %s", m.careerSetup.branch or "No Branch", m.careerSetup.skill or "No Skill"), meta = {type = "branchSkill"}}
    end

    -- difficulty
    if m.additionalAttributes.difficulty then
      filterData.groupTags['difficulty_'..m.additionalAttributes.difficulty] = true
      filterData.sortingValues['difficulty'] = difficultyValues[m.additionalAttributes.difficulty]
    end

    -- level
    local levelId = m.startTrigger and m.startTrigger.level
    local level = core_levels.getLevelByName(levelId)
    if not groupsByKey['level_'..levelId] then
      if level then
        groupsByKey['level_'..levelId] = {label = level.title, meta = {type = "level"}}
      end
    end
    filterData.groupTags['level_'..levelId] = true

   -- league
    if m._leagueId then
      local league = career_modules_branches_leagues.getLeagueById(m._leagueId)
      local key = "league_"..league.id
      filterData.groupTags[key] = true
      if league._missionOrderByMissionId then
        filterData.sortingValues['_missionOrderByMissionId'] = league._missionOrderByMissionId[m.id]
      else
        filterData.sortingValues['_missionOrderByMissionId'] = m.id
      end
      if not groupsByKey[key] then
        groupsByKey[key] = {
          label = league.name,
          order = league._order,
          sortingKey = '_missionOrderByMissionId',
          meta = {type = "league", leagueId = league.id},
        }
      end

    end

    tilesById[m.id].filterData = filterData

    ::continue::
  end

  -- TODO: scenarios and other non-missions

  -- build group lists (new groups might have been added)
  for key, group in pairs(groupsByKey) do
    group.tileIdsUnsorted = {}
    group.meta = group.meta or {type=group.type}
  end

  -- add tiles to groups
  for id, tile in pairs(tilesById) do
    for groupKey, _ in pairs(tile.filterData.groupTags) do
      if groupsByKey[groupKey] then
        table.insert(groupsByKey[groupKey].tileIdsUnsorted, id)
        if groupsByKey[groupKey].sortingKey then
          local sKey = groupsByKey[groupKey].sortingKey
          table.sort(groupsByKey[groupKey].tileIdsUnsorted, function(a, b) return tilesById[a].filterData.sortingValues[sKey] < tilesById[b].filterData.sortingValues[sKey] end)
        else
          table.sort(groupsByKey[groupKey].tileIdsUnsorted)
        end
        if groupsByKey[groupKey].sortingDirection and groupsByKey[groupKey].sortingDirection == "desc" then
          arrayReverse(groupsByKey[groupKey].tileIdsUnsorted)
        end
      end
    end
  end

  -- groupSets
  local groupSetsByKey = {}
  if career_career and career_career.isActive() then
    -- Group by leagues in career mode
    career_modules_branches_leagues.clearLeagueUnlockCache()
    for groupKey, group in pairs(groupsByKey) do
      if group.meta.type == "league" then
        local league = career_modules_branches_leagues.getLeagueById(group.meta.leagueId)
        local formatted = career_modules_branches_leagues.formatLeague(league)
        group.meta.formattedLeague = formatted
        table.insert(groupSetsByKey, groupKey)
      end
    end
  else
    -- Group by mission type outside career
    for groupKey, group in pairs(groupsByKey) do
      if group.meta.type == "all" then
        table.insert(groupSetsByKey, groupKey)
      end
    end
  end

  table.sort(groupSetsByKey, function(a,b)
    local ag, bg = groupsByKey[a], groupsByKey[b]
    return (ag.order or a) < (bg.order or b)
  end)

  return {
    tilesById = tilesById,
    groupsByKey = groupsByKey,
    groupKeys = groupSetsByKey,
  }

end

Callers

@/lua/ge/extensions/gameplay/missions/missionScreen.lua
        missions = missions,
        missionCards = M.getMissionTiles(ids), -- for some us test
        --isWalking = gameplay_walk.isWalking(),