GE Lua Documentation

Press F to search!

onGetUnlockFlagDefinitions

Definition


-- @/lua/ge/extensions/career/branches.lua:507

local function onGetUnlockFlagDefinitions(flagDefinitions)

  for id, branch in pairs(getBranches()) do
    -- for levels
    for lvl, lvlData in pairs(branch.levels or {}) do
      local unlockFlags = lvlData.unlockFlags or {}
      table.insert(unlockFlags, branch.id.."-level-"..lvl)
      for _, flag in ipairs(unlockFlags) do
        flagDefinitions[flag] = {
          label = { txt = "ui.career.branchLevel", context = {branch = branch.name, lvl = lvl}},
          level = lvl,
          unlockedFunction = function()
            local hasLevel =  getBranchLevel(id) >= lvl
            local isUnlocked = getBranchById(id).unlocked
            return hasLevel and isUnlocked
          end,
          unlockInfo = {
            type = "minLevel", icon = branch.icon,
            longLabel = { txt = "ui.career.requiresBranchLevel", context = {branch = branch.name, lvl = lvl}},
            shortLabel = { txt = "ui.career.lvlShort", context = {lvl = lvl}},
          },
          lockedReason = {
            type = "locked", icon = branch.icon, level = lvl, label = { txt = "ui.career.requiresBranchLevel", context = {branch = branch.name, lvl = lvl}}
          }
        }
      end
    end

    -- for certifications
    for _, certification in ipairs(branch.certifications or {}) do
      local mission = gameplay_missions_missions.getMissionById(certification.requiredMissionsToPass)
      local missionName = mission and mission.name or "?Unknown Challenge?"
      flagDefinitions[certification.unlockFlag] = {
        label = certification.name,
        color = branch.color,
        unlockedFunction = function()
          if not mission then return false end
          local pKeys = tableKeysSorted(mission.saveData.progress)
          local met = false
          for _, key in ipairs(pKeys) do
            if mission.saveData.progress[key] and mission.saveData.progress[key].aggregate then
              met = met or mission.saveData.progress[key].aggregate.passed
            end
          end
          return met
        end,
        icon = certification.icon or branch.icon,

        unlockInfo = {
          type = "certification",
          icon = certification.icon or branch.icon,
          whatToDoLabel = { txt = "ui.career.certification.whatToDoLabel", context = {missionName = missionName}},
          longLabel = { txt = "ui.career.certification.requiresLabel", context = {certification = certification.name}},
        }
      }
    end
  end
end

Callers