Skip to content

Commit

Permalink
Support for alternate ascendancies (#6882)
Browse files Browse the repository at this point in the history
* add basic support for Alternate Ascendancies

fix crash

* Fix Render

fix crash

* fix more crashes with converting trees

* Update PassiveSpec.lua

---------

Co-authored-by: LocalIdentity <[email protected]>
  • Loading branch information
Regisle and LocalIdentity authored Dec 4, 2023
1 parent 951bc64 commit 5fec870
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
65 changes: 54 additions & 11 deletions src/Classes/PassiveSpec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function PassiveSpecClass:Load(xml, dbFileName)
end
end
end
self:ImportFromNodeList(tonumber(xml.attrib.classId), tonumber(xml.attrib.ascendClassId), hashList, self.hashOverrides, masteryEffects)
self:ImportFromNodeList(tonumber(xml.attrib.classId), tonumber(xml.attrib.ascendClassId), tonumber(xml.attrib.secondaryAscendClassId or 0), hashList, self.hashOverrides, masteryEffects)
elseif url then
self:DecodeURL(url)
end
Expand All @@ -172,6 +172,7 @@ function PassiveSpecClass:Save(xml)
-- New format
classId = tostring(self.curClassId),
ascendClassId = tostring(self.curAscendClassId),
secondaryAscendClassId = tostring(self.curSecondaryAscendClassId),
nodes = table.concat(allocNodeIdList, ","),
masteryEffects = table.concat(masterySelections, ",")
}
Expand Down Expand Up @@ -214,7 +215,7 @@ function PassiveSpecClass:PostLoad()
end

-- Import passive spec from the provided class IDs and node hash list
function PassiveSpecClass:ImportFromNodeList(classId, ascendClassId, hashList, hashOverrides, masteryEffects, treeVersion)
function PassiveSpecClass:ImportFromNodeList(classId, ascendClassId, secondaryAscendClassId, hashList, hashOverrides, masteryEffects, treeVersion)
if hashOverrides == nil then hashOverrides = {} end
if treeVersion and treeVersion ~= self.treeVersion then
self:Init(treeVersion)
Expand Down Expand Up @@ -259,6 +260,7 @@ function PassiveSpecClass:ImportFromNodeList(classId, ascendClassId, hashList, h
end
end
self:SelectAscendClass(ascendClassId)
self:SelectSecondaryAscendClass(secondaryAscendClassId)
end

function PassiveSpecClass:AllocateDecodedNodes(nodes, isCluster, endian)
Expand Down Expand Up @@ -527,19 +529,21 @@ function PassiveSpecClass:SelectClass(classId)
end

function PassiveSpecClass:SelectAscendClass(ascendClassId)
if self.curAscendClassId then
-- Deallocate the current ascendancy class's start node
local ascendClass = self.curClass.classes[self.curAscendClassId] or self.curClass.classes[0]
local oldStartNodeId = ascendClass.startNodeId
if oldStartNodeId then
self.nodes[oldStartNodeId].alloc = false
self.allocNodes[oldStartNodeId] = nil
end
end

self.curAscendClassId = ascendClassId
local ascendClass = self.curClass.classes[ascendClassId] or self.curClass.classes[0]
self.curAscendClass = ascendClass
self.curAscendClassName = ascendClass.name

-- Deallocate any allocated ascendancy nodes that don't belong to the new ascendancy class
for id, node in pairs(self.allocNodes) do
if node.ascendancyName and node.ascendancyName ~= ascendClass.name then
node.alloc = false
self.allocNodes[id] = nil
end
end

if ascendClass.startNodeId then
-- Allocate the new ascendancy class's start node
local startNode = self.nodes[ascendClass.startNodeId]
Expand All @@ -551,6 +555,44 @@ function PassiveSpecClass:SelectAscendClass(ascendClassId)
self:BuildAllDependsAndPaths()
end

function PassiveSpecClass:SelectSecondaryAscendClass(ascendClassId)
-- if Secondary Ascendency does not exist on this tree version
if not self.tree.alternate_ascendancies then
return
end
if self.curSecondaryAscendClassId then
-- Deallocate the current ascendancy class's start node
local ascendClass = self.tree.alternate_ascendancies[self.curSecondaryAscendClassId]
if ascendClass then
local oldStartNodeId = ascendClass.startNodeId
if oldStartNodeId then
self.nodes[oldStartNodeId].alloc = false
self.allocNodes[oldStartNodeId] = nil
end
end
end

self.curSecondaryAscendClassId = ascendClassId
if ascendClassId == 0 then
self.curSecondaryAscendClass = nil
self.curSecondaryAscendClassName = "None"
elseif self.tree.alternate_ascendancies[self.curSecondaryAscendClassId] then
local ascendClass = self.tree.alternate_ascendancies[self.curSecondaryAscendClassId]
self.curSecondaryAscendClass = ascendClass
self.curSecondaryAscendClassName = ascendClass.name

if ascendClass.startNodeId then
-- Allocate the new ascendancy class's start node
local startNode = self.nodes[ascendClass.startNodeId]
startNode.alloc = true
self.allocNodes[startNode.id] = startNode
end
end

-- Rebuild all the node paths and dependencies
self:BuildAllDependsAndPaths()
end

-- Determines if the given class's start node is connected to the current class's start node
-- Attempts to find a path between the nodes which doesn't pass through any ascendancy nodes (i.e. Ascendant)
function PassiveSpecClass:IsClassConnected(classId)
Expand Down Expand Up @@ -1719,6 +1761,7 @@ function PassiveSpecClass:CreateUndoState()
return {
classId = self.curClassId,
ascendClassId = self.curAscendClassId,
secondaryAscendClassId = self.secondaryAscendClassId,
hashList = allocNodeIdList,
hashOverrides = self.hashOverrides,
masteryEffects = selections,
Expand All @@ -1727,7 +1770,7 @@ function PassiveSpecClass:CreateUndoState()
end

function PassiveSpecClass:RestoreUndoState(state, treeVersion)
self:ImportFromNodeList(state.classId, state.ascendClassId, state.hashList, state.hashOverrides, state.masteryEffects, treeVersion or state.treeVersion)
self:ImportFromNodeList(state.classId, state.ascendClassId, state.secondaryAscendClassId, state.hashList, state.hashOverrides, state.masteryEffects, treeVersion or state.treeVersion)
self:SetWindowTitleWithBuildClass()
end

Expand Down
1 change: 1 addition & 0 deletions src/Classes/PassiveSpecListControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local PassiveSpecListClass = newClass("PassiveSpecListControl", "ListControl", f
local newSpec = new("PassiveSpec", treeTab.build, latestTreeVersion)
newSpec:SelectClass(treeTab.build.spec.curClassId)
newSpec:SelectAscendClass(treeTab.build.spec.curAscendClassId)
newSpec:SelectSecondaryAscendClass(treeTab.build.spec.curSecondaryAscendClassId)
self:RenameSpec(newSpec, "New Tree", true)
end)
self:UpdateItemsTabPassiveTreeDropdown()
Expand Down
2 changes: 1 addition & 1 deletion src/Classes/PassiveTreeView.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function PassiveTreeViewClass:Draw(build, viewPort, inputEvents)
local scrX, scrY = treeToScreen(group.x, group.y)
if group.ascendancyName then
if group.isAscendancyStart then
if group.ascendancyName ~= spec.curAscendClassName then
if group.ascendancyName ~= spec.curAscendClassName and (not spec.curSecondaryAscendClass or group.ascendancyName ~= spec.curSecondaryAscendClass.id) then
SetDrawColor(1, 1, 1, 0.25)
end
self:DrawAsset(tree.assets["Classes"..group.ascendancyName], scrX, scrY, scale)
Expand Down
8 changes: 8 additions & 0 deletions src/Modules/Build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ function buildMode:Init(dbFileName, buildName, buildXML, convertBuild)
self.spec:SetWindowTitleWithBuildClass()
self.buildFlag = true
end)
self.controls.secondaryAscendDrop = new("DropDownControl", {"LEFT",self.controls.ascendDrop,"RIGHT"}, 8, 0, 120, 20, nil, function(index, value)
self.spec:SelectSecondaryAscendClass(value.ascendClassId)
self.spec:AddUndoState()
self.spec:SetWindowTitleWithBuildClass()
self.buildFlag = true
end)

-- List of display stats
-- This defines the stats in the side bar, and also which stats show in node/item comparisons
Expand Down Expand Up @@ -1001,6 +1007,8 @@ function buildMode:OnFrame(inputEvents)
self.controls.classDrop:SelByValue(self.spec.curClassId, "classId")
self.controls.ascendDrop.list = self.controls.classDrop:GetSelValue("ascendancies")
self.controls.ascendDrop:SelByValue(self.spec.curAscendClassId, "ascendClassId")
self.controls.secondaryAscendDrop.list = {{label = "None", ascendClassId = 0}, {label = "Warden", ascendClassId = 1}, {label = "Warlock", ascendClassId = 2}, {label = "Primalist", ascendClassId = 3}}
self.controls.secondaryAscendDrop:SelByValue(self.spec.curSecondaryAscendClassId, "ascendClassId")

local checkFabricatedGroups = self.buildFlag
if self.buildFlag then
Expand Down

0 comments on commit 5fec870

Please sign in to comment.