Skip to content

Commit 27995bf

Browse files
justjuanguijustjuanguiLocalIdentity
authored
Enhnace the save, load, import, convert process to support new classes, ascendacies (#1608)
* Update IntegerId field from Character.dat * Enhance passive spec loading and saving with internal class ID support * Add back old class format Until build sites are updated to use the new format. We'll keep the old one in place --------- Co-authored-by: justjuangui <servicios@juacarvajal.com> Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent f87dec6 commit 27995bf

26 files changed

Lines changed: 1391 additions & 1303 deletions

src/Classes/PassiveSpec.lua

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,42 @@ function PassiveSpecClass:Load(xml, dbFileName)
134134
end
135135
end
136136
if xml.attrib.nodes then
137+
local classId = -1
138+
local ascendClassId = -1
139+
-- Legacy format contain classId and ascendClassId as xml attributes
140+
if xml.attrib.classId then
141+
classId = tonumber(xml.attrib.classId)
142+
end
143+
if xml.attrib.ascendClassId then
144+
ascendClassId = tonumber(xml.attrib.ascendClassId)
145+
end
146+
137147
-- New format
138-
if not xml.attrib.classId then
139-
launch:ShowErrMsg("^1Error parsing '%s': 'Spec' element missing 'classId' attribute", dbFileName)
148+
if xml.attrib.classInternalId then
149+
local classInternalId = tonumber(xml.attrib.classInternalId)
150+
if self.tree.classIntegerIdMap[classInternalId] then
151+
classId = self.tree.classIntegerIdMap[classInternalId]
152+
end
153+
end
154+
if xml.attrib.ascendancyInternalId then
155+
local ascendancyInternalId = tostring(xml.attrib.ascendancyInternalId)
156+
if ascendancyInternalId == "" then
157+
ascendClassId = 0
158+
elseif self.tree.internalAscendNameMap[ascendancyInternalId] then
159+
ascendClassId = self.tree.internalAscendNameMap[ascendancyInternalId].ascendClassId
160+
end
161+
end
162+
163+
if classId == -1 then
164+
launch:ShowErrMsg("^1Error parsing '%s': 'Spec' element missing 'classId' / 'classInternalId' attribute", dbFileName)
140165
return true
141166
end
142-
if not xml.attrib.ascendClassId then
143-
launch:ShowErrMsg("^1Error parsing '%s': 'Spec' element missing 'ascendClassId' attribute", dbFileName)
167+
168+
if ascendClassId == -1 then
169+
launch:ShowErrMsg("^1Error parsing '%s': 'Spec' element missing 'ascendClassId' / 'ascendancyInternalId' attribute", dbFileName)
144170
return true
145171
end
172+
146173
local hashList = { }
147174
for hash in xml.attrib.nodes:gmatch("%d+") do
148175
t_insert(hashList, tonumber(hash))
@@ -174,7 +201,7 @@ function PassiveSpecClass:Load(xml, dbFileName)
174201
end
175202
end
176203
end
177-
self:ImportFromNodeList(nil, tonumber(xml.attrib.classId), tonumber(xml.attrib.ascendClassId), tonumber(xml.attrib.secondaryAscendClassId or 0), hashList, weaponSets, copyTable(self.hashOverrides, true), masteryEffects)
204+
self:ImportFromNodeList(nil, classId, ascendClassId, tonumber(xml.attrib.secondaryAscendClassId or 0), hashList, weaponSets, copyTable(self.hashOverrides, true), masteryEffects)
178205
elseif url then
179206
self:DecodeURL(url)
180207
end
@@ -198,12 +225,23 @@ function PassiveSpecClass:Save(xml)
198225
for mastery, effect in pairs(self.masterySelections) do
199226
t_insert(masterySelections, "{"..mastery..","..effect.."}")
200227
end
228+
229+
local classInternalId = self.tree.classes[self.curClassId].integerId
230+
local ascendancyInternalId = ""
231+
if self.curAscendClassId and self.tree.classes[self.curClassId].classes[self.curAscendClassId] then
232+
-- None ascendancy case will have no internalId
233+
ascendancyInternalId = self.tree.classes[self.curClassId].classes[self.curAscendClassId].internalId or ""
234+
end
235+
201236
xml.attrib = {
202237
title = self.title,
203238
treeVersion = self.treeVersion,
204-
-- New format
239+
-- TODO remove old class format
205240
classId = tostring(self.curClassId),
206241
ascendClassId = tostring(self.curAscendClassId),
242+
-- New format
243+
classInternalId = tostring(classInternalId),
244+
ascendancyInternalId = tostring(ascendancyInternalId),
207245
secondaryAscendClassId = tostring(self.curSecondaryAscendClassId),
208246
nodes = table.concat(allocNodeIdList, ","),
209247
masteryEffects = table.concat(masterySelections, ",")
@@ -2064,7 +2102,16 @@ function PassiveSpecClass:CreateUndoState()
20642102
for mastery, effect in pairs(self.masterySelections) do
20652103
selections[mastery] = effect
20662104
end
2105+
local classInternalId = self.tree.classes[self.curClassId].integerId
2106+
local ascendancyInternalId = ""
2107+
if self.curAscendClassId and self.tree.classes[self.curClassId].classes[self.curAscendClassId] then
2108+
-- None ascendancy doesn't have an internalId
2109+
ascendancyInternalId = self.tree.classes[self.curClassId].classes[self.curAscendClassId].internalId or ""
2110+
end
2111+
20672112
return {
2113+
classInternalId = classInternalId,
2114+
ascendancyInternalId = ascendancyInternalId,
20682115
classId = self.curClassId,
20692116
ascendClassId = self.curAscendClassId,
20702117
secondaryAscendClassId = self.secondaryAscendClassId,
@@ -2077,7 +2124,17 @@ function PassiveSpecClass:CreateUndoState()
20772124
end
20782125

20792126
function PassiveSpecClass:RestoreUndoState(state, treeVersion)
2080-
self:ImportFromNodeList(nil, state.classId, state.ascendClassId, state.secondaryAscendClassId, state.hashList, state.weaponSets, state.hashOverrides, state.masteryEffects, treeVersion or state.treeVersion)
2127+
local classId = state.classId
2128+
local ascendClassId = state.ascendClassId
2129+
if treeVersion ~= nil and treeVersion ~= state.treeVersion then
2130+
-- we are upgrading the tree view so in this case we use the classInternalId to find the correct classId
2131+
classId = self.tree.classIntegerIdMap[state.classInternalId]
2132+
ascendClassId = 0
2133+
if state.ascendancyInternalId and state.ascendancyInternalId ~= "" and self.tree.internalAscendNameMap[state.ascendancyInternalId] then
2134+
ascendClassId = self.tree.internalAscendNameMap[state.ascendancyInternalId].ascendClassId
2135+
end
2136+
end
2137+
self:ImportFromNodeList(nil, classId, ascendClassId, state.secondaryAscendClassId, state.hashList, state.weaponSets, state.hashOverrides, state.masteryEffects, treeVersion or state.treeVersion)
20812138
self:SetWindowTitleWithBuildClass()
20822139
end
20832140

src/Classes/PassiveTree.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ local PassiveTreeClass = newClass("PassiveTree", function(self, treeVersion)
8686
-- Build maps of class name -> class table
8787
self.classNameMap = { }
8888
self.ascendNameMap = { }
89+
self.classIntegerIdMap = { }
8990
self.internalAscendNameMap = { }
9091
self.classNotables = { }
9192

9293
for classId, class in pairs(self.classes) do
9394
class.classes = class.ascendancies
9495
class.classes[0] = { name = "None" }
9596
self.classNameMap[class.name] = classId
97+
self.classIntegerIdMap[class.integerId] = classId
9698
for ascendClassId, ascendClass in pairs(class.classes) do
9799
self.ascendNameMap[ascendClass.id or ascendClass.name] = {
98100
classId = classId,

src/Export/Scripts/passivetree.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ for i, classId in ipairs(psg.passives) do
643643
end
644644
local classDef = {
645645
["name"] = character.Name,
646+
["integerId"] = character.IntegerId,
646647
["base_str"] = character.BaseStrength,
647648
["base_dex"] = character.BaseDexterity,
648649
["base_int"] = character.BaseIntelligence,

src/TreeData/0_1/tree.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ return {
140140
["base_dex"]=15,
141141
["base_int"]=7,
142142
["base_str"]=7,
143+
integerId=2,
143144
name="Ranger"
144145
},
145146
[2]={
@@ -190,6 +191,7 @@ return {
190191
["base_dex"]=7,
191192
["base_int"]=7,
192193
["base_str"]=15,
194+
integerId=6,
193195
name="Warrior"
194196
},
195197
[3]={
@@ -240,6 +242,7 @@ return {
240242
["base_dex"]=11,
241243
["base_int"]=7,
242244
["base_str"]=11,
245+
integerId=9,
243246
name="Mercenary"
244247
},
245248
[4]={
@@ -290,6 +293,7 @@ return {
290293
["base_dex"]=7,
291294
["base_int"]=15,
292295
["base_str"]=7,
296+
integerId=1,
293297
name="Witch"
294298
},
295299
[5]={
@@ -340,6 +344,7 @@ return {
340344
["base_dex"]=7,
341345
["base_int"]=15,
342346
["base_str"]=7,
347+
integerId=7,
343348
name="Sorceress"
344349
},
345350
[6]={
@@ -390,6 +395,7 @@ return {
390395
["base_dex"]=11,
391396
["base_int"]=11,
392397
["base_str"]=7,
398+
integerId=10,
393399
name="Monk"
394400
}
395401
},

src/TreeData/0_2/tree.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ return {
140140
["base_dex"]=15,
141141
["base_int"]=7,
142142
["base_str"]=7,
143+
integerId=2,
143144
name="Ranger"
144145
},
145146
[2]={
@@ -190,6 +191,7 @@ return {
190191
["base_dex"]=15,
191192
["base_int"]=7,
192193
["base_str"]=7,
194+
integerId=8,
193195
name="Huntress"
194196
},
195197
[3]={
@@ -253,6 +255,7 @@ return {
253255
["base_dex"]=7,
254256
["base_int"]=7,
255257
["base_str"]=15,
258+
integerId=6,
256259
name="Warrior"
257260
},
258261
[4]={
@@ -316,6 +319,7 @@ return {
316319
["base_dex"]=11,
317320
["base_int"]=7,
318321
["base_str"]=11,
322+
integerId=9,
319323
name="Mercenary"
320324
},
321325
[5]={
@@ -379,6 +383,7 @@ return {
379383
["base_dex"]=7,
380384
["base_int"]=15,
381385
["base_str"]=7,
386+
integerId=1,
382387
name="Witch"
383388
},
384389
[6]={
@@ -429,6 +434,7 @@ return {
429434
["base_dex"]=7,
430435
["base_int"]=15,
431436
["base_str"]=7,
437+
integerId=7,
432438
name="Sorceress"
433439
},
434440
[7]={
@@ -479,6 +485,7 @@ return {
479485
["base_dex"]=11,
480486
["base_int"]=11,
481487
["base_str"]=7,
488+
integerId=10,
482489
name="Monk"
483490
}
484491
},

src/TreeData/0_3/tree.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ return {
140140
["base_dex"]=15,
141141
["base_int"]=7,
142142
["base_str"]=7,
143+
integerId=2,
143144
name="Ranger"
144145
},
145146
[2]={
@@ -190,6 +191,7 @@ return {
190191
["base_dex"]=15,
191192
["base_int"]=7,
192193
["base_str"]=7,
194+
integerId=8,
193195
name="Huntress"
194196
},
195197
[3]={
@@ -253,6 +255,7 @@ return {
253255
["base_dex"]=7,
254256
["base_int"]=7,
255257
["base_str"]=15,
258+
integerId=6,
256259
name="Warrior"
257260
},
258261
[4]={
@@ -316,6 +319,7 @@ return {
316319
["base_dex"]=11,
317320
["base_int"]=7,
318321
["base_str"]=11,
322+
integerId=9,
319323
name="Mercenary"
320324
},
321325
[5]={
@@ -394,6 +398,7 @@ return {
394398
["base_dex"]=7,
395399
["base_int"]=15,
396400
["base_str"]=7,
401+
integerId=1,
397402
name="Witch"
398403
},
399404
[6]={
@@ -444,6 +449,7 @@ return {
444449
["base_dex"]=7,
445450
["base_int"]=15,
446451
["base_str"]=7,
452+
integerId=7,
447453
name="Sorceress"
448454
},
449455
[7]={
@@ -494,6 +500,7 @@ return {
494500
["base_dex"]=11,
495501
["base_int"]=11,
496502
["base_str"]=7,
503+
integerId=10,
497504
name="Monk"
498505
}
499506
},
1.99 KB
Binary file not shown.
665 Bytes
Binary file not shown.
176 Bytes
Binary file not shown.
215 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)