changeset 23:e49efad51698 v1.0-rc7

* Run data scooping operations from the main Refresh block
author Nenue
date Mon, 24 Oct 2016 23:17:42 -0400
parents b3835b6b61f7
children dd9754daa08a
files ClassPlan.lua
diffstat 1 files changed, 59 insertions(+), 58 deletions(-) [+]
line wrap: on
line diff
--- a/ClassPlan.lua	Mon Oct 24 22:27:05 2016 -0400
+++ b/ClassPlan.lua	Mon Oct 24 23:17:42 2016 -0400
@@ -54,20 +54,19 @@
   end
 end
 
+
+
 MissionsHandler.GetPlayerData = function(self)
   if not self.profile then
     return
   end
   local items = C_Garrison.GetLandingPageItems(LE_GARRISON_TYPE_7_0)
-  print(#items)
-
   wipe(self.profile.missions)
   for index, data in ipairs(items) do
-    print('  ',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
+    print(' -',data.name, '|cFF00FF00'.. data.timeLeft .. '|r', date("%A %I:%m %p", data.missionEndTime))
     tinsert(self.profile.missions, data)
   end
-  print('items update pending')
-  self.isStale = true
+  ClassOrderPlan.isStale = true
 end
 
 MissionsHandler.OnGetItem = function(data)
@@ -198,7 +197,7 @@
     --DEFAULT_CHAT_FRAME:AddMessage(data.shipmentType ..' '.. tostring(data.name) ..' '.. tostring(data.creationTime) ..' '.. tostring(data.duration))
     tinsert(self.profile.shipments, data)
   end
-  self.isStale = true
+  ClassOrderPlan.isStale = true
 end
 
 function core:OnLoad ()
@@ -210,6 +209,7 @@
   self:AddHandler('missions', MissionsHandler)
   self:AddHandler('shipments', ShipmentsHandler)
   self:Reanchor()
+  C_Garrison.RequestLandingPageShipmentInfo();
 end
 
 local parentFrames = {'VeneerWorldState', 'OrderHallCommandBar'}
@@ -302,6 +302,7 @@
       self:Show()
     end
     self.initialized = true
+    self.isStale = true
   end
 end
 
@@ -405,21 +406,60 @@
 
   return totalHeight
 end
+
+
+local GI_profileKey, GI_profile, GI_isMine
+local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"}
+local DoItemList = function (source, dest, onGetItem)
+  local numItems = 0
+  for index, data in ipairs(source) do
+    data.classColor = GI_profile.classColor or defaultClassColor
+    data.profileKey = GI_profileKey
+    data.isMine = GI_isMine
+    if onGetItem then
+      onGetItem(data)
+    end
+    numItems = numItems + 1
+    tinsert(dest, data)
+  end
+  return numItems
+end
+
 local max = math.max
 function core:Refresh()
-  if self.isStale then
-    self:SortItems()
-  end
-  self.isStale = nil
+  print('|cFF00FFFFRefresh()|r')
+  self.currentHeight = 0
+  for name, ptype in pairs(self.prototypes) do
+    print(' |cFF00FF00'..name..'|r')
+    if self.isStale then
+      ptype.GetPlayerData(self)
+      self.sortedItems[name] = self.sortedItems[name] or {}
 
-  self.currentHeight = 0
-  for name, info in pairs(self.prototypes) do
-    local itemsHeight = self:RefreshItems(name, info)
+      wipe(self.sortedItems[name])
+        --print(  'object:', ptype)
+      for key, profile in pairs(self.data.characters) do
+        if profile[name] and #profile[name] >= 1 then
+          print(' ', #profile[name], key)
+          GI_profileKey = key
+          GI_profile = profile
+          GI_isMine = (profile == self.profile)
+          local results = DoItemList(profile[name], self.sortedItems[name], ptype.OnGetItem)
+        end
+
+      end
+
+      if ptype.SortHandler then
+        sort(self.sortedItems[name], ptype.SortHandler)
+      end
+    end
+
+    local itemsHeight = self:RefreshItems(name, ptype)
     self.currentHeight = max(itemsHeight, self.currentHeight)
   end
 
   self:Reanchor()
   self:SetHeight(self.currentHeight)
+  self.isStale = nil
 end
 
 function core:Toggle()
@@ -435,71 +475,32 @@
 end
 
 function core:OnUpdate()
-  if self.fadeTimer and self.fadeTimer < GetTime() then
-    self:Hide()
-  end
-
   if self.isStale then
-    print('updating items on show')
+    print('update requested internally')
     self:Refresh()
   end
 end
 
 function core:OnShow()
+  print('|cFF00FFFFShow()')
   if self.isStale then
-    print('updating items on show')
+    print('on-show update')
     self:Refresh()
   end
-  -- grab this at least once
-  C_Garrison.RequestLandingPageShipmentInfo();
   ClassPlanButton.Background:Show()
   ClassPlanButton.Grip:SetShown(true)
 end
 function core:OnHide()
+  print('|cFF00FFFFHide()')
   ClassPlanButton.Background:Hide()
   ClassPlanButton.Grip:SetShown(false)
 end
 
-local GI_profileKey, GI_profile, GI_isMine
-local defaultClassColor = {r = 0.7, g = 0.7, b =0.7, colorStr = "ffffffff"}
-local DoItemList = function (source, dest, onGetItem)
-  if not source then
-    return
-  end
-  local numItems = 0
-  for index, data in ipairs(source) do
-    data.classColor = GI_profile.classColor or defaultClassColor
-    data.profileKey = GI_profileKey
-    data.isMine = GI_isMine
-    if onGetItem then
-      onGetItem(data)
-    end
-    numItems = numItems + 1
-    tinsert(dest, data)
-  end
-  return numItems
-end
 
-function core:SortItems()
-  print('|cFF0088FFSortItems()|r')
+function core:SortItems(ptype)
+  print('|cFF0088FFSortItems('..tostring(ptype)..')|r')
   GI_currentTime = time()
 
-  for key, sortedItems in pairs(self.sortedItems) do
-    wipe(sortedItems)
-    local ptype = self.prototypes[key]
-    --print(  'object:', ptype)
-    for name, profile in pairs(self.data.characters) do
-      GI_profileKey = name
-      GI_profile = profile
-      GI_isMine = (profile == self.profile)
-      local results = DoItemList(profile[key], sortedItems, ptype.OnGetItem)
-      --print(' - ', name, results, 'items')
-    end
-
-    if ptype.SortHandler then
-      sort(sortedItems, ptype.SortHandler)
-    end
-  end
 end
 
 function MissionsHandler:OnComplete()