getBranches
Definition
-- @/lua/ge/extensions/career/branches.lua:158
-- gets all branches in a dict by ID
local function getBranches()
if not branchesById then
branchesById = {}
branchesByAttributeKey = {}
branchesByPath = {}
-- First collect all branches
local allBranches = {}
for _, filePath in ipairs(FS:findFiles(branchesDir, 'info.json', -1, false, true)) do
local fileInfo = jsonReadFile(filePath)
if not fileInfo.ignore then
sanitizeBranch(fileInfo, filePath)
table.insert(allBranches, fileInfo)
end
end
-- First get all domains and sort them by order
local domains = {}
for _, branch in ipairs(allBranches) do
if branch.isDomain then
table.insert(domains, branch)
end
end
table.sort(domains, function(a,b) return (a.order or 0) < (b.order or 0) end)
-- Build sorted list by traversing hierarchy
local sortedList = {}
local remaining = {}
for _, branch in ipairs(allBranches) do
if not branch.isDomain then
remaining[branch.id] = branch
end
end
-- Helper to find children of a parent
local function getChildren(parentId)
local children = {}
for id, branch in pairs(remaining) do
if branch.parentId == parentId then
table.insert(children, branch)
remaining[id] = nil
end
end
table.sort(children, function(a,b) return (a.order or 0) < (b.order or 0) end)
return children
end
-- Process domains and their children recursively
local function processChildren(parent)
local children = getChildren(parent.id)
for _, child in ipairs(children) do
table.insert(sortedList, child)
processChildren(child) -- Recursively process any children of this child
end
end
-- Process domains
for _, domain in ipairs(domains) do
table.insert(sortedList, domain)
processChildren(domain)
end
-- Add to lookup tables preserving hierarchical order
for i, fileInfo in ipairs(sortedList) do
branchesById[fileInfo.id] = fileInfo
branchesByAttributeKey[fileInfo.attributeKey] = fileInfo
branchesByPath[fileInfo.pathId] = fileInfo
order[fileInfo.attributeKey] = i
branchNameOrder[fileInfo.id] = fileInfo.order
--log('I', 'branches', fileInfo.id)
end
-- Recursively get color from parent chain
local function getInheritedColor(branch, colorType)
if not branch then return nil end
if branch[colorType] then return branch[colorType] end
local parent = branch.parentId and branchesById[branch.parentId]
return parent and getInheritedColor(parent, colorType)
end
-- Now that all branches are loaded, handle color inheritance
for _, branch in pairs(branchesById) do
branch.color = branch.color or getInheritedColor(branch, 'color')
branch.accentColor = branch.accentColor or getInheritedColor(branch, 'accentColor') or branch.color
end
end
return branchesById
end
Callers
@/lua/ge/extensions/career/branches.lua
local function getBranchByPath(pathId)
getBranches()
local branch = branchesByPath[pathId]
local function getBranchByDomainBranchSkill(domainId, branchId, skillId)
getBranches()
local pathId = domainId
if not sortedBranches then
getBranches()
sortedBranches = {}
local saveData = { }
for id, branch in pairs(getBranches()) do
saveData[id] = {}
local data = (savePath and not outdated and jsonReadFile(savePath .. "/career/"..saveFile)) or {}
for id, branch in pairs(getBranches()) do
for k, v in pairs(data[id] or {}) do
local function checkUnlocks()
for id, branch in pairs(getBranches()) do
branch.unlocked = true
for id, branch in pairs(getBranches()) do
-- for levels
@/lua/ge/extensions/career/modules/delivery/progress.lua
}
for skill, _ in pairs(career_branches.getBranches()) do
unlockStatus.skillLevels[skill] = career_branches.getBranchLevel(skill)
@/lua/ge/extensions/career/modules/branches/leagues.lua
local validSkills = {}
for _, skill in pairs(career_branches.getBranches()) do
if skill.parentBranch == condition.branchId then