Mercurial > wow > askmrrobot
comparison Import.lua @ 139:c229c759a125 v65
Update to support multiple setups per spec.
author | yellowfive |
---|---|
date | Mon, 05 Nov 2018 16:06:00 -0800 |
parents | a0894ffebd15 |
children | cc82eeeec1c8 |
comparison
equal
deleted
inserted
replaced
138:45e467335a1b | 139:c229c759a125 |
---|---|
12 if msg then | 12 if msg then |
13 _lblError:SetText(msg) | 13 _lblError:SetText(msg) |
14 _txtImport:SetFocus(true) | 14 _txtImport:SetFocus(true) |
15 else | 15 else |
16 Amr:HideCover() | 16 Amr:HideCover() |
17 Amr:RefreshGearTab() | 17 Amr:RefreshGearDisplay() |
18 end | 18 end |
19 end | 19 end |
20 | 20 |
21 local function onImportCancelClick(widget) | 21 local function onImportCancelClick(widget) |
22 Amr:HideCover() | 22 Amr:HideCover() |
122 ---------------------------------------------------------------------------- | 122 ---------------------------------------------------------------------------- |
123 | 123 |
124 -- | 124 -- |
125 -- Import a character, returning nil on success, otherwise an error message, import result stored in the db. | 125 -- Import a character, returning nil on success, otherwise an error message, import result stored in the db. |
126 -- | 126 -- |
127 function Amr:ImportCharacter(data, isTest) | 127 function Amr:ImportCharacter(data, isTest, isChild) |
128 | 128 |
129 -- make sure all data is up to date before importing and get a local copy of player's current state | 129 -- make sure all data is up to date before importing and get a local copy of player's current state |
130 local currentPlayerData = self:ExportCharacter() | 130 local currentPlayerData = self:ExportCharacter() |
131 | 131 |
132 if data == nil or string.len(data) == 0 then | 132 if data == nil or string.len(data) == 0 then |
133 return L.ImportErrorEmpty | 133 return L.ImportErrorEmpty |
134 end | 134 end |
135 | 135 |
136 -- if multiple specs are included in the data, parse each individually, then quit | 136 -- if multiple setups are included in the data, parse each individually, then quit |
137 local specParts = { strsplit("\n", data) } | 137 local specParts = { strsplit("\n", data) } |
138 if #specParts > 1 then | 138 if #specParts > 1 then |
139 -- clear out any previously-imported BiB setups when importing new ones (non-BiB will always be imported one at a time) | |
140 for i = #Amr.db.char.GearSetups, 1, -1 do | |
141 if Amr.db.char.GearSetups[i].IsBib then | |
142 table.remove(Amr.db.char.GearSetups, i) | |
143 end | |
144 end | |
145 | |
139 for i = 1, #specParts do | 146 for i = 1, #specParts do |
140 local err = self:ImportCharacter(specParts[i], isTest) | 147 local err = self:ImportCharacter(specParts[i], isTest, true) |
141 if err ~= nil then | 148 if err ~= nil then |
142 return err | 149 return err |
143 end | 150 end |
144 end | 151 end |
145 return | 152 |
153 -- ensure that all BiB setups are sorted to the top | |
154 local nonBib = {} | |
155 for i = #Amr.db.char.GearSetups, 1, -1 do | |
156 if not Amr.db.char.GearSetups[i].IsBib then | |
157 table.insert(nonBib, Amr.db.char.GearSetups[i]) | |
158 table.remove(Amr.db.char.GearSetups, i) | |
159 end | |
160 end | |
161 for i, setup in ipairs(nonBib) do | |
162 table.insert(Amr.db.char.GearSetups, setup) | |
163 end | |
164 | |
165 return | |
146 end | 166 end |
147 | 167 |
148 local data1 = { strsplit("$", data) } | 168 local data1 = { strsplit("$", data) } |
149 if #data1 ~= 3 then | 169 if #data1 ~= 3 then |
150 return L.ImportErrorFormat | 170 return L.ImportErrorFormat |
300 obj.azerite = azerite | 320 obj.azerite = azerite |
301 end | 321 end |
302 end | 322 end |
303 end | 323 end |
304 | 324 |
305 -- now read any extra display information | 325 -- extra information contains setup id, display label, then extra enchant info |
306 parts = { strsplit("@", data1[3]) } | 326 parts = { strsplit("@", data1[3]) } |
307 for i = 1, #parts do | 327 |
328 local setupId = parts[2] | |
329 local setupName = parts[3] | |
330 | |
331 for i = 4, #parts do | |
308 local infoParts = { strsplit("\\", parts[i]) } | 332 local infoParts = { strsplit("\\", parts[i]) } |
309 | 333 |
310 if infoParts[1] == "e" then | 334 if infoParts[1] == "e" then |
311 | 335 |
312 local enchObj = {} | 336 local enchObj = {} |
342 print("bad item: " .. v.id) | 366 print("bad item: " .. v.id) |
343 end | 367 end |
344 end | 368 end |
345 else | 369 else |
346 -- we have succeeded, record the result | 370 -- we have succeeded, record the result |
347 Amr.db.char.GearSets[specSlot] = importData | 371 local result = { |
372 IsBib = string.sub(setupId, 1, 3) ~= "AMR", | |
373 SpecSlot = tonumber(specSlot), | |
374 Id = setupId, | |
375 Label = setupName, | |
376 Gear = importData | |
377 } | |
378 | |
379 if not result.IsBib then | |
380 -- replace if this setup already exists | |
381 local key = -1 | |
382 for i,setup in ipairs(Amr.db.char.GearSetups) do | |
383 if setup.Id == result.Id then | |
384 key = i | |
385 break | |
386 end | |
387 end | |
388 | |
389 if key ~= -1 then | |
390 Amr.db.char.GearSetups[key] = result | |
391 else | |
392 table.insert(Amr.db.char.GearSetups, result) | |
393 end | |
394 | |
395 if not isChild then | |
396 -- if doing a single import of a setup, make it active | |
397 Amr:SetActiveSetupId(setupId) | |
398 end | |
399 else | |
400 table.insert(Amr.db.char.GearSetups, result) | |
401 end | |
348 | 402 |
349 for k,v in pairs(enchantInfo) do | 403 for k,v in pairs(enchantInfo) do |
350 Amr.db.char.ExtraEnchantData[k] = v | 404 Amr.db.char.ExtraEnchantData[k] = v |
351 end | 405 end |
352 | 406 |