Wait for LeoAltholic finish its initialization and consider already finish research but not logged in user as available

Leandro Silva [10-11-18 - 14:49]
Wait for LeoAltholic finish its initialization and consider already finish research but not logged in user as available
Filename
LeoTrainer.lua
LeoTrainer.txt
LeoTrainerConst.lua
LeoTrainerUI.lua
diff --git a/LeoTrainer.lua b/LeoTrainer.lua
index 346f6ab..1aec81c 100644
--- a/LeoTrainer.lua
+++ b/LeoTrainer.lua
@@ -269,21 +269,27 @@ local function OnSettingsControlsCreated(panel)
     LeoTrainer_Settings:OnSettingsControlsCreated(panel)
 end

-function LeoTrainer.OnAddOnLoaded(event, addonName)
-    if addonName == LeoTrainer.name then
-        EVENT_MANAGER:UnregisterForEvent(LeoTrainer.name, EVENT_ADD_ON_LOADED)
-        SCENE_MANAGER:RegisterTopLevel(LeoTrainerWindow, false)
+local function onLeoAltholicInitialized()
+    CALLBACK_MANAGER:UnregisterCallback("LeoAltholicInitialized", onLeoAltholicInitialized)
+    SCENE_MANAGER:RegisterTopLevel(LeoTrainerWindow, false)
+
+    LeoTrainer.Initialize()

-        LeoTrainer.Initialize()
+    EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFTING_STATION_INTERACT, LeoTrainer.stationEnter)
+    EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_END_CRAFTING_STATION_INTERACT, LeoTrainer.stationExit)
+    EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFT_COMPLETED, LeoTrainer.OnCraftComplete)
+    EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFT_FAILED, LeoTrainer.OnCraftFailed)
+    CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", OnSettingsControlsCreated)

-        EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFTING_STATION_INTERACT, LeoTrainer.stationEnter)
-        EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_END_CRAFTING_STATION_INTERACT, LeoTrainer.stationExit)
-        EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFT_COMPLETED, LeoTrainer.OnCraftComplete)
-        EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_CRAFT_FAILED, LeoTrainer.OnCraftFailed)
-        CALLBACK_MANAGER:RegisterCallback("LAM-PanelControlsCreated", OnSettingsControlsCreated)
+    LeoTrainer.log("started.")
+end

-        LeoTrainer.log("started.")
+function LeoTrainer.OnAddOnLoaded(event, addonName)
+    if addonName == LeoTrainer.name then
+        EVENT_MANAGER:UnregisterForEvent(LeoTrainer.name, EVENT_ADD_ON_LOADED)
+        onLeoAltholicInitialized()
     end
 end

-EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_ADD_ON_LOADED, LeoTrainer.OnAddOnLoaded)
+CALLBACK_MANAGER:RegisterCallback("LeoAltholicInitialized", onLeoAltholicInitialized)
+--EVENT_MANAGER:RegisterForEvent(LeoTrainer.name, EVENT_ADD_ON_LOADED, LeoTrainer.OnAddOnLoaded)
diff --git a/LeoTrainer.txt b/LeoTrainer.txt
index 7ecc02e..57456fa 100644
--- a/LeoTrainer.txt
+++ b/LeoTrainer.txt
@@ -1,6 +1,6 @@
 ## Title: Leo's Trainer
 ## APIVersion: 100024 100025
-## Version: 1.0.1
+## Version: 1.0.2
 ## Author: |c39B027@LeandroSilva|r
 ## SavedVariables: LeoTrainerSavedVariables
 ## DependsOn: LeoAltholic
diff --git a/LeoTrainerConst.lua b/LeoTrainerConst.lua
index 45c193b..2ca79d7 100644
--- a/LeoTrainerConst.lua
+++ b/LeoTrainerConst.lua
@@ -2,7 +2,7 @@
 LeoTrainer = {}
 LeoTrainer.name = "LeoTrainer"
 LeoTrainer.displayName = "Leo's Trainer"
-LeoTrainer.version = "1.0.1"
+LeoTrainer.version = "1.0.2"
 LeoTrainer.chatPrefix = "|c39B027" .. LeoTrainer.name .. "|r: "
 LeoTrainer.setting = nil
 LeoTrainer.hidden = true
diff --git a/LeoTrainerUI.lua b/LeoTrainerUI.lua
index 932cda5..23e34a7 100644
--- a/LeoTrainerUI.lua
+++ b/LeoTrainerUI.lua
@@ -322,9 +322,9 @@ function LeoTrainer.FillSlots()
                             local _, known, unknown, all = LeoTrainer.GetCharKnowsTrait(craft, line, trait)
                             traitsKnown[craft][line][trait] = known
                         end
-                        if type(traitData) == 'number' then
+                        if type(traitData) == 'number' and GetDiffBetweenTimeStamps(traitData, GetTimeStamp()) > 0 then
                             researching = researching + 1
-                        elseif traitData == true then
+                        elseif (type(traitData) == 'number' and GetDiffBetweenTimeStamps(traitData, GetTimeStamp()) <= 0) or traitData == true then
                             knownCount[char.bio.name][craft][line] = knownCount[char.bio.name][craft][line] + 1
                         elseif traitData == false and firstUnknownTrait.id == 0 then
                             firstUnknownTrait.id = trait