|
2 | 2 | -- as of 10.1.0, most data will be loaded (and cached) from blizzard's APIs when the Lib loads |
3 | 3 | -- @curseforge-project-slug: libtalenttree@ |
4 | 4 |
|
5 | | -local MAJOR, MINOR = "LibTalentTree-1.0", 8 |
| 5 | +local MAJOR, MINOR = "LibTalentTree-1.0", 9 |
6 | 6 | --- @class LibTalentTree |
7 | 7 | local LibTalentTree = LibStub:NewLibrary(MAJOR, MINOR) |
8 | 8 |
|
9 | 9 | if not LibTalentTree then return end -- No upgrade needed |
10 | 10 |
|
| 11 | +local MAX_LEVEL = 70; |
11 | 12 | LibTalentTree.dataVersion = 0 -- overwritten in LibTalentTree-1.0_data.lua |
12 | 13 |
|
13 | 14 | ---@alias edgeType |
@@ -128,7 +129,7 @@ local function getGridLineFromCoordinate(start, spacing, halfwayEnabled, coordin |
128 | 129 | end |
129 | 130 |
|
130 | 131 | local function buildCache() |
131 | | - local level = 70; |
| 132 | + local level = MAX_LEVEL; |
132 | 133 | local configID = Constants.TraitConsts.VIEW_TRAIT_CONFIG_ID; |
133 | 134 |
|
134 | 135 | LibTalentTree.cache = {}; |
@@ -350,7 +351,8 @@ function LibTalentTree:IsNodeVisibleForSpec(specId, nodeId) |
350 | 351 | assert(type(specId) == 'number', 'specId must be a number'); |
351 | 352 | assert(type(nodeId) == 'number', 'nodeId must be a number'); |
352 | 353 |
|
353 | | - local class = LibTalentTree.specMap[specId]; |
| 354 | + local specMap = useCache and self.cache.specMap or self.specMap; |
| 355 | + local class = specMap[specId]; |
354 | 356 | assert(class, 'Unknown specId: ' .. specId); |
355 | 357 |
|
356 | 358 | local treeId = self:GetClassTreeId(class); |
@@ -399,7 +401,8 @@ function LibTalentTree:IsNodeGrantedForSpec(specId, nodeId) |
399 | 401 | assert(type(specId) == 'number', 'specId must be a number'); |
400 | 402 | assert(type(nodeId) == 'number', 'nodeId must be a number'); |
401 | 403 |
|
402 | | - local class = LibTalentTree.specMap[specId]; |
| 404 | + local specMap = useCache and self.cache.specMap or self.specMap; |
| 405 | + local class = specMap[specId]; |
403 | 406 | assert(class, 'Unknown specId: ' .. specId); |
404 | 407 |
|
405 | 408 | local treeId = self:GetClassTreeId(class); |
@@ -540,16 +543,20 @@ function LibTalentTree:GetGates(specId) |
540 | 543 | assert(type(specId) == 'number', 'specId must be a number'); |
541 | 544 |
|
542 | 545 | if (gateCache[specId]) then return deepCopy(gateCache[specId]); end |
543 | | - local class = LibTalentTree.specMap[specId]; |
| 546 | + local specMap = useCache and self.cache.specMap or self.specMap; |
| 547 | + local class = specMap[specId]; |
544 | 548 | assert(class, 'Unknown specId: ' .. specId); |
545 | 549 |
|
546 | 550 | local treeId = self:GetClassTreeId(class); |
547 | 551 | local gates = {}; |
548 | 552 |
|
549 | 553 | local nodesByConditions = {}; |
550 | | - local conditions = self.gateData[treeId]; |
| 554 | + local gateData = useCache and self.cache.gateData or self.gateData; |
| 555 | + local conditions = gateData[treeId]; |
551 | 556 |
|
552 | | - for nodeId, nodeInfo in pairs(self.nodeData[treeId]) do |
| 557 | + local nodeData = useCache and self.cache.nodeData or self.nodeData; |
| 558 | + |
| 559 | + for nodeId, nodeInfo in pairs(nodeData[treeId]) do |
553 | 560 | if (#nodeInfo.conditionIDs > 0 and self:IsNodeVisibleForSpec(specId, nodeId)) then |
554 | 561 | for _, conditionId in pairs(nodeInfo.conditionIDs) do |
555 | 562 | if conditions[conditionId] then |
|
0 commit comments