changeset 165:3be9cc6f7d20 v77

Updated for 8.2, initial essence support.
author yellowfive
date Tue, 25 Jun 2019 10:27:20 -0700
parents a6aa4fa7e2dd
children 3b3ec0693df8
files AskMrRobot-Serializer/AskMrRobot-Serializer.lua AskMrRobot.toc Constants.lua Core.lua Export.lua Gear.lua Import.lua
diffstat 7 files changed, 105 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/AskMrRobot-Serializer/AskMrRobot-Serializer.lua	Tue May 07 10:32:41 2019 -0700
+++ b/AskMrRobot-Serializer/AskMrRobot-Serializer.lua	Tue Jun 25 10:27:20 2019 -0700
@@ -1,6 +1,6 @@
 -- AskMrRobot-Serializer will serialize and communicate character data between users.
 
-local MAJOR, MINOR = "AskMrRobot-Serializer", 76
+local MAJOR, MINOR = "AskMrRobot-Serializer", 77
 local Amr, oldminor = LibStub:NewLibrary(MAJOR, MINOR)
 
 if not Amr then return end -- already loaded by something else
@@ -492,6 +492,10 @@
 	ret.Specs = {}
     ret.Talents = {}
 	readSpecs(ret)
+
+	-- these get updated later, since need to cache info for inactive specs
+	ret.UnlockedEssences = {}
+	ret.Essences = {}
 	
 	ret.Equipped = {}	
 	readEquippedItems(ret)
@@ -687,7 +691,15 @@
         if data.Specs[spec] and (complete or spec == data.ActiveSpec) then
             table.insert(fields, ".s" .. spec) -- indicates the start of a spec block
 			table.insert(fields, data.Specs[spec])
-            table.insert(fields, data.Talents[spec] or "")			
+			table.insert(fields, data.Talents[spec] or "")
+			
+			local essences = {}
+			if data.Essences and data.Essences[spec] then
+				for i, ess in ipairs(data.Essences[spec]) do
+					table.insert(essences, table.concat(ess, "."))
+				end
+			end
+			table.insert(fields, table.concat(essences, "_"))
         end
     end
     
@@ -707,6 +719,14 @@
             end
         end
 	end
+
+	-- export unlocked essences
+	if data.UnlockedEssences then
+		table.insert(fields, ".ess")
+		for i, ess in ipairs(data.UnlockedEssences) do
+			table.insert(fields, table.concat(ess, "_"))
+		end
+	end
     
     -- if doing a complete export, include bank/bag items too
 	if complete then
@@ -735,11 +755,13 @@
 
 end
 
+--[[
 -- Shortcut for the common use case: serialize the player's currently active setup with no extras.
 function Amr:SerializePlayer()
 	local data = self:GetPlayerData()
 	return self:SerializePlayerData(data)
 end
+]]
 
 --[[
 ----------------------------------------------------------------------------------------------------------------------
--- a/AskMrRobot.toc	Tue May 07 10:32:41 2019 -0700
+++ b/AskMrRobot.toc	Tue Jun 25 10:27:20 2019 -0700
@@ -1,7 +1,7 @@
-## Interface: 80100
+## Interface: 80200
 ## Title: Ask Mr. Robot
 ## Author: Team Robot, Inc.
-## Version: 76
+## Version: 77
 ## Notes: Gear import/export, combat logging, and more.
 ## URL: www.askmrrobot.com
 ## SavedVariables: AskMrRobotDb4
--- a/Constants.lua	Tue May 07 10:32:41 2019 -0700
+++ b/Constants.lua	Tue Jun 25 10:27:20 2019 -0700
@@ -2,7 +2,7 @@
 local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true)
 
 -- min import version that we will read from the website
-Amr.MIN_IMPORT_VERSION = 65
+Amr.MIN_IMPORT_VERSION = 77
 
 -- min addon version that we will support for inter-addon communication
 Amr.MIN_ADDON_VERSION = 65
--- a/Core.lua	Tue May 07 10:32:41 2019 -0700
+++ b/Core.lua	Tue Jun 25 10:27:20 2019 -0700
@@ -46,6 +46,8 @@
 			LastVersion = 0,           -- used to clean out old stuff	
 			FirstUse = true,           -- true if this is first time use, gets cleared after seeing the export help splash window
 			Talents = {},              -- for each spec, selected talents
+			Essences = {},             -- for each spec, selected essences
+			UnlockedEssences = {},     -- unlocked essences for this character
 			Equipped = {},             -- for each spec, slot id to item info
 			BagItems = {},             -- list of item info for bags
 			BankItems = {},            -- list of item info for bank
--- a/Export.lua	Tue May 07 10:32:41 2019 -0700
+++ b/Export.lua	Tue Jun 25 10:27:20 2019 -0700
@@ -259,6 +259,48 @@
 end
 ]]
 
+local function scanEssences()
+	if not C_AzeriteEssence then return end
+
+	-- read which essences this player has unlocked
+	Amr.db.char.UnlockedEssences = {}
+
+	local essences = C_AzeriteEssence.GetEssences()
+	if essences then
+		for i, essence in ipairs(essences) do
+			if essence.unlocked then
+				table.insert(Amr.db.char.UnlockedEssences, { essence.ID, essence.rank })
+			end
+		end 
+	end
+
+	local specPos = GetSpecialization()	
+	if not specPos or specPos < 1 or specPos > 4 then return end
+
+	if not Amr.db.char.Essences then
+		Amr.db.char.Essences = {}
+	end
+
+	Amr.db.char.Essences[specPos] = {}
+	local active = Amr.db.char.Essences[specPos]
+
+	local milestones = C_AzeriteEssence.GetMilestones()
+	if milestones then
+		for i, milestone in ipairs(milestones) do
+			-- if no slot, it corresponds to the stamina nodes, skip those
+			if milestone.slot ~= nil then
+				if milestone.unlocked then
+					local essenceId = C_AzeriteEssence.GetMilestoneEssence(milestone.ID)
+					if essenceId then
+						local essence = C_AzeriteEssence.GetEssenceInfo(essenceId)
+						table.insert(active, { milestone.slot, essence.ID, essence.rank })
+					end
+				end
+			end
+		end
+	end
+end
+
 local function scanTalents()	
 	local specPos = GetSpecialization()	
 	if not specPos or specPos < 1 or specPos > 4 then return end
@@ -302,8 +344,13 @@
 	
 	-- scan current spec's talents just before exporting
 	scanTalents()
+
+	-- scan current spec's essences just before exporting
+	scanEssences()
 	
 	data.Talents = Amr.db.char.Talents	
+	data.UnlockedEssences = Amr.db.char.UnlockedEssences
+	data.Essences = Amr.db.char.Essences
 	data.Equipped = Amr.db.char.Equipped	
 	data.BagItems = Amr.db.char.BagItems
 
@@ -337,3 +384,7 @@
 --Amr:AddEventHandler("VOID_STORAGE_UPDATE", scanVoid)
 
 Amr:AddEventHandler("PLAYER_TALENT_UPDATE", scanTalents)
+
+if C_AzeriteEssence then
+	Amr:AddEventHandler("AZERITE_ESSENCE_UPDATE", scanEssences)
+end
\ No newline at end of file
--- a/Gear.lua	Tue May 07 10:32:41 2019 -0700
+++ b/Gear.lua	Tue Jun 25 10:27:20 2019 -0700
@@ -223,11 +223,13 @@
 	local gear
 	local spec
 	local setupIndex
+	local essences
 	for i, setup in ipairs(Amr.db.char.GearSetups) do
 		if setup.Id == setupId then
 			setupIndex = i
 			gear = setup.Gear
 			spec = setup.SpecSlot
+			essences = setup.Essences
 			break
 		end
 	end
@@ -311,6 +313,7 @@
 			end
 
 			local isAzerite = optimalItem and C_AzeriteEmpoweredItem.IsAzeriteEmpoweredItemByID(optimalItem.id)
+			local isEssence = essences and optimalItem and optimalItem.id == 158075
 			
 			-- find the item in the player's inventory that best matches what the optimization wants to use
 			local matchItem = Amr:FindMatchingItem(optimalItem, player, usedItems)
@@ -370,7 +373,7 @@
 			-- modifications
 			if optimalItem then
 
-				-- gems or azerite powers
+				-- gems or azerite powers or essences
 				local prevSocket = nil
 
 				if isAzerite then
@@ -390,6 +393,8 @@
 							prevSocket = socketBorder
 						end
 					end
+				elseif isEssence then
+					-- TODO: render essence differences
 				else
 					for i = 1, #optimalItem.gemIds do
 						-- we rely on the fact that the gear sets coming back from the site will almost always have all sockets filled,
--- a/Import.lua	Tue May 07 10:32:41 2019 -0700
+++ b/Import.lua	Tue Jun 25 10:27:20 2019 -0700
@@ -246,6 +246,18 @@
     return importData
 end
 
+local function parseEssenceList(essenceString)
+    local ret = {}
+
+    local parts = { strsplit("_", essenceString) }
+    for i = 1, #parts do
+        local essence = { strsplit(".", parts[i]) }
+        table.insert(ret, { tonumber(essence[0]), tonumber(essence[1]), tonumber(essence[2]) })
+    end
+
+    return ret
+end
+
 --
 -- Import a character, returning nil on success, otherwise an error message, import result stored in the db.
 --
@@ -263,8 +275,7 @@
     
     if #specParts > 1 and specParts[1] == "_junk_" then
         -- if the string starts with "_junk_" then it is the junk list
-        Amr:ImportJunkList(specParts[2], currentPlayerData)
-        return
+        return Amr:ImportJunkList(specParts[2], currentPlayerData)
 
     elseif #specParts > 1 then
         -- clear out any previously-imported BiB setups when importing new ones (non-BiB will always be imported one at a time)
@@ -343,8 +354,10 @@
     
     -- if we make it this far, the data is valid, so read item information
 	local specSlot = tonumber(parts[11])
-	
-    local importData = parseItemList(parts, 16, "n/a", true)
+    
+    local essences = parseEssenceList(parts[15])
+
+    local importData = parseItemList(parts, 17, "n/a", true)
     
     -- extra information contains setup id, display label, then extra enchant info        
     parts = { strsplit("@", data1[3]) }
@@ -398,7 +411,8 @@
             SpecSlot = tonumber(specSlot),
             Id = setupId,
             Label = setupName,
-            Gear = importData
+            Gear = importData,
+            Essences = essences
         }
 
         if not result.IsBib then