fix lua error when research status not found and add support function for Trainer

Leandro Silva [03-22-20 - 10:41]
fix lua error when research status not found and add support function for Trainer
Filename
LeoAltholic.txt
LeoAltholicInit.lua
LeoAltholic_API.lua
diff --git a/LeoAltholic.txt b/LeoAltholic.txt
index bf18473..deb28dd 100644
--- a/LeoAltholic.txt
+++ b/LeoAltholic.txt
@@ -1,7 +1,7 @@
 ## Title: Leo's Altholic
 ## APIVersion: 100029 100030
-## Version: 1.7.8
-## AddOnVersion: 178
+## Version: 1.7.9
+## AddOnVersion: 179
 ## Author: |c39B027@LeandroSilva|r
 ## SavedVariables: LeoAltholicSavedVariables LeoAltholicCharVariables
 ## DependsOn: LibFeedback LibAddonMenu-2.0
diff --git a/LeoAltholicInit.lua b/LeoAltholicInit.lua
index 9b903b0..e259488 100644
--- a/LeoAltholicInit.lua
+++ b/LeoAltholicInit.lua
@@ -6,7 +6,7 @@ LeoAltholicToolbarUI = LeoAltholicToolbarUI or {}

 LeoAltholic.name = "LeoAltholic"
 LeoAltholic.displayName = "Leo's Altholic"
-LeoAltholic.version = "1.7.8"
+LeoAltholic.version = "1.7.9"
 LeoAltholic.chatPrefix = "|c39B027" .. LeoAltholic.name .. "|r: "

 LeoAltholic.TAB_BIO = "Bio"
diff --git a/LeoAltholic_API.lua b/LeoAltholic_API.lua
index d5bd893..9e935a9 100644
--- a/LeoAltholic_API.lua
+++ b/LeoAltholic_API.lua
@@ -1,4 +1,10 @@

+local function get(tbl, k, ...)
+    if tbl == nil or tbl[k] == nil then return nil end
+    if select('#', ...) == 0 then return tbl[k] end
+    return get(tbl[k], ...)
+end
+
 --[[
 Return the timestamp from today's reset (specifically for craft writs)
 ]]
@@ -135,7 +141,7 @@ function LeoAltholic.GetNumMissingTraitsFor(craft, charName)
     for line = 1, GetNumSmithingResearchLines(craft) do
         local _, _, numTraits = GetSmithingResearchLineInfo(craft, line)
         for trait = 1, numTraits do
-            if not char.research.done[craft][line][trait] then
+            if not LeoAltholic.CharKnowsTrait(craft, line, trait) then
                 missing = missing + 1
             end
         end
@@ -143,15 +149,29 @@ function LeoAltholic.GetNumMissingTraitsFor(craft, charName)
     return missing
 end

-function LeoAltholic.CharKnowsTrait(craft, line, trait, charName)
+function LeoAltholic.CharKnowsTrait(craftSkill, line, trait, charName)
     if not charName then charName = LeoAltholic.CharName end
     local char = LeoAltholic.globalData.CharList[charName]
     if not char then return end
     if not char.research.done then return false end
-    if not char.research.done[craft] then return false end
-    if not char.research.done[craft][line] then return false end
-    if not char.research.done[craft][line][trait] then return false end
-    return true
+    return get(char.research.done, craftSkill, line, trait) == true
+end
+
+function LeoAltholic.ResearchStatus(craftSkill, line, trait, charName)
+    if not charName then charName = LeoAltholic.CharName end
+    local char = LeoAltholic.globalData.CharList[charName]
+
+    local isKnown = LeoAltholic.CharKnowsTrait(craftSkill, line, trait, charName)
+    local isResearching = false
+
+    for _, researching in pairs(char.research.doing[craftSkill]) do
+        if researching.line == line and researching.trait == trait then
+            isResearching = researching.doneAt < GetTimeStamp()
+            break
+        end
+    end
+
+    return isKnown, isResearching
 end

 function LeoAltholic.GetNumTraitKnownPerLine(charName)