Quantcast

Database now updates before checking for indirectly known appearances

Salvatore Lopiparo [07-25-16 - 02:07]
Database now updates before checking for indirectly known appearances
Filename
code.lua
database.lua
diff --git a/code.lua b/code.lua
index d0bd8bd..80b32ea 100644
--- a/code.lua
+++ b/code.lua
@@ -415,6 +415,8 @@ end

 function CanIMogIt:PlayerKnowsTransmog(itemLink)
 	-- Returns whether this item's appearance is already known by the player.
+	local appearanceID = CanIMogIt:GetAppearanceID(itemLink)
+	if appearanceID then self.Database:AddAppearanceSources(appearanceID) end
 	appearanceTable = self.Database:GetAppearanceTable(itemLink)
 	if not appearanceTable then return false end
 	if CanIMogIt:IsItemArmor(itemLink) then
diff --git a/database.lua b/database.lua
index b88c94b..0a8bfd8 100644
--- a/database.lua
+++ b/database.lua
@@ -128,6 +128,7 @@ end
 function Database:AddAppearanceSources(appearanceID)
     -- Adds the sources (the items) of the appearance to the database.
     local sources = C_TransmogCollection.GetAppearanceSources(appearanceID)
+    if not sources then return end
     for i, source in pairs(sources) do
         if source.isCollected then
             self:AddItemBySourceID(source.sourceID, appearanceID)
@@ -136,6 +137,14 @@ function Database:AddAppearanceSources(appearanceID)
 end


+function Database:UpdateFromKnownSources(knownSources, appearanceID)
+    -- Updates the items given from knownSources.
+    for sourceID, source in pairs(knownSources) do
+        self:AddItemBySourceID(sourceID, appearanceID)
+    end
+end
+
+
 function Database:UpdateItem(itemLink, hasTransmogFromItem)
     -- Updates the status of the item in the database.
     if hasTransmogFromItem then