diff Modules/ArtifactPower.lua @ 102:1e511e9aaca5

- clean up handler loading inconsistencies; exclude free frames from anchor cluster iterations, and remove extraneous PLAYER_LOGIN handling - added a Setup method to the handler template that creates and reconciles a SavedVariables table for that module
author Nenue
date Wed, 25 Jan 2017 23:11:27 -0500
parents f32b63c93275
children 8df154a2bfd6
line wrap: on
line diff
--- a/Modules/ArtifactPower.lua	Sat Jan 21 20:12:17 2017 -0500
+++ b/Modules/ArtifactPower.lua	Wed Jan 25 23:11:27 2017 -0500
@@ -74,16 +74,44 @@
 
 end
 
+
+local IsBagnonOpen = function()
+  return ((BagnonFramebank and BagnonFramebank:IsShown()) or (BagnonFrameinventory and BagnonFrameinventory:IsShown()))
+end
 local addonCompatibility = {
   ['Bagnon'] = {
     BagFrames = {'BagnonFrameinventory'},
     BankFrames = {'BagnonFramebank'},
+    FrameMethods = {
+      ['HideFrame'] = IsBagnonOpen,
+      ['ShowFrame'] = IsBagnonOpen
+    },
     PostHooks = {'ToggleAllBags', 'ToggleBackpack' },
     MethodClass = 'Bagnon',
-    MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'}
+    MethodHooks = {'BANK_OPENED', 'BANKFRAME_CLOSED'},
+
   }
 }
 
+local function AddFrameHooks(frame, args)
+  for funcName, func in pairs(args.FrameMethods) do
+    print('binding', frame:GetName(), funcName, 'to', tostring(func))
+    hooksecurefunc(frame, funcName, func)
+  end
+end
+local PENDING_HOOKS = {}
+
+local function RegisterInventoryFrame(name, listType, args)
+  print('register', name, 'as inventory frame type =', (listType == BAG_FRAMES) and 'bags' or 'bank')
+  tinsert(FRAME_LIST, name)
+  tinsert(listType, name)
+  if _G[name] then
+    AddFrameHooks(_G[name], args)
+  else
+    PENDING_HOOKS[name] = args
+  end
+end
+
 
 function ap:Setup()
   print(self:GetName()..':Setup()')
@@ -123,14 +151,15 @@
   -- todo: ArkInventory, Elv, etc
   for addon, args in pairs(addonCompatibility) do
     if IsAddOnLoaded(addon) then
+
       for _, name in ipairs(args.BagFrames) do
-        tinsert(FRAME_LIST, name)
-        tinsert(BAG_FRAMES, name)
+        RegisterInventoryFrame(name, BAG_FRAMES, args)
       end
       for _, name in ipairs(args.BankFrames) do
-        tinsert(FRAME_LIST, name)
-        tinsert(BAG_FRAMES, name)
+        RegisterInventoryFrame(name, BANK_FRAMES, args)
       end
+
+      -- should only specify non-secure functions in this table
       for _, name in ipairs(args.PostHooks) do
         local oFunc = _G[name]
         _G[name] = function(...)
@@ -217,13 +246,18 @@
 
 function ap:OnShow()
   print('|cFFFFFF00OnShow()|r')
+
+  for name, args in pairs(PENDING_HOOKS) do
+    if _G[name] then
+      AddFrameHooks(_G[name], args)
+      PENDING_HOOKS[name] = nil
+    end
+  end
+
+
   self.enabled = true
   self:ScanAllBags()
   self:Reanchor()
-  if not self.postShowSetup then
-    self.postShowSetup = true
-    hooksecurefunc("HideUIPanel", function() self:TryToShow() end)
-  end
 end
 function ap:OnHide()
   print('|cFF88FF00OnHide()|r')
@@ -506,7 +540,6 @@
             if itemAP then
               itemAP = itemAP / self.profile.knowledgeMultiplier
               self.cache[itemID] = itemAP
-              return itemAP
             end
           end
         end
@@ -518,7 +551,6 @@
         if fishingAP then
           self.cache[itemID] = fishingAP
           self.fishingCache[itemID] = true
-          return fishingAP, true
         end
       end
     else
@@ -553,20 +585,21 @@
       local name, _, quality, iLevel, reqLevel, class, subclass = GetItemInfo(link)
 
       if class == 'Consumable' and subclass == 'Other' then
-        print(GetItemInfo(link))
+        --print(GetItemInfo(link))
         local itemAP, isFishingAP = self:GetItemAP(itemID, link)
-        print(itemAP, isFishingAP)
-        if itemAP > 0 then
+        --print(itemAP, isFishingAP)
+        if itemAP and (itemAP > 0) then
+          local itemButton = self:GetItemButton(itemID, texture, itemAP)
+
           if isFishingAP then
             bagData.fishingItems = (bagData.fishingItems or 0) + 1
             bagData.fishingAP = (bagData.fishingAP or 0) + itemAP
           else
-
+            itemAP = itemAP * self.profile.knowledgeMultiplier
             bagData.numItems = (bagData.numItems or 0) + 1
             bagData.totalAP = (bagData.totalAP or 0) + itemAP
           end
           bagData.items[itemID] = (bagData.items[itemID] or 0) + 1
-          local itemButton = self:GetItemButton(itemID, texture, itemAP)
         end
       elseif self.profile.artifacts[itemID] then
         print('artfiact weapon', itemID, link, id, slotID)
@@ -665,6 +698,7 @@
   self.potentialLevel = potentialPoints
   self.potentialAdjustedXP = potentialXP
 
+  
 
   if index ~= 1 then
     self:ClearAllPoints()