diff Export.lua @ 114:4cd98aa90d78 v53

Small update to crucible export.
author yellowfive
date Wed, 04 Oct 2017 01:08:56 -0700
parents 57c6cac5143c
children bccce18e12cb
line wrap: on
line diff
--- a/Export.lua	Mon Aug 28 19:33:28 2017 -0700
+++ b/Export.lua	Wed Oct 04 01:08:56 2017 -0700
@@ -284,6 +284,7 @@
 			talents = C_ArtifactRelicForgeUI.GetSocketedRelicTalents(i)
 			
 			--[[
+			-- test data
 			if i == 1 then
 				talents = {}
 				table.insert(talents, {
@@ -368,18 +369,87 @@
 		if not dataz.Crucible then
 			dataz.Crucible = {
 				Equipped = {},
-				Inventory = {}
+				Previewed = {}
 			}
 		end		
 		
 		local crucible = dataz.Crucible		
 		crucible.Equipped = equipped
 		if preview then
-			crucible.Inventory[preview.ItemLink] = preview
+			local previewKey = {}
+			table.insert(previewKey, preview.ItemLink)
+			for i,v in ipairs(preview.Powers) do
+				table.insert(previewKey, v .. "=" .. tostring(preview.Active[i]))
+			end			
+			previewKey = table.concat(previewKey, "_")
+			
+			crucible.Previewed[previewKey] = preview
 		end
 	end
 end
 
+local function pruneCrucible()
+	if not Amr.db or not Amr.db.char or not Amr.db.char.Artifacts then return end
+	
+	local spec = GetSpecialization()
+	local dataz = Amr.db.char.Artifacts[spec]
+	if not dataz or not dataz.Crucible then return end
+	
+	local crucible = dataz.Crucible
+	
+	-- this was old format, transform to new format
+	if crucible.Inventory then
+		if not crucible.Previewed then
+			crucible.Previewed = {}
+		end
+		
+		for link,preview in pairs(crucible.Inventory) do
+			local previewKey = {}
+			table.insert(previewKey, preview.ItemLink)
+			for i,v in ipairs(preview.Powers) do
+				table.insert(previewKey, v .. "=" .. tostring(preview.Active[i]))
+			end			
+			previewKey = table.concat(previewKey, "_")
+			
+			crucible.Previewed[previewKey] = preview
+		end
+		
+		crucible.Inventory = nil
+	end
+	
+	-- get a hash of every owned, but not-equipped item
+	local ownedItems = {}
+	if Amr.db.char.BagItems then
+		for i,link in ipairs(Amr.db.char.BagItems) do
+			ownedItems[link] = true
+		end
+	end
+	if Amr.db.char.BankItems then
+		for i,link in ipairs(Amr.db.char.BankItems) do
+			ownedItems[link] = true
+		end
+	end
+	if Amr.db.char.VoidItems then
+		for i,link in ipairs(Amr.db.char.VoidItems) do
+			ownedItems[link] = true
+		end
+	end
+	
+	-- prune out any previewed relics that the player no longer owns
+	if crucible.Previewed then
+		local toRemove = {}
+		for k,v in pairs(crucible.Previewed) do
+			if not ownedItems[v.ItemLink] then
+				table.insert(toRemove, k)
+			end
+		end
+		for i,v in ipairs(toRemove) do
+			crucible.Previewed[v] = nil
+		end
+	end
+	
+end
+
 local function scanArtifact()
 	if not Amr.db or not Amr.db.char or not Amr.db.char.Artifacts then return end
 	
@@ -454,6 +524,9 @@
 	-- scan current spec's talents just before exporting
 	scanTalents()
 	
+	-- prune crucible info just before each time we export
+	pruneCrucible()
+	
 	data.Talents = Amr.db.char.Talents
 	data.Artifacts = Amr.db.char.Artifacts
 	data.Equipped = Amr.db.char.Equipped