comparison Core.lua @ 81:0515882856f1 v38

updated for 7.0
author yellowfive
date Tue, 19 Jul 2016 10:05:32 -0700
parents a892c863c86a
children b8e9664d3229
comparison
equal deleted inserted replaced
80:8f235b016212 81:0515882856f1
49 local function initializeDb() 49 local function initializeDb()
50 50
51 local defaults = { 51 local defaults = {
52 char = { 52 char = {
53 FirstUse = true, -- true if this is first time use, gets cleared after seeing the export help splash window 53 FirstUse = true, -- true if this is first time use, gets cleared after seeing the export help splash window
54 SubSpecs = {}, -- last seen subspecs for this character, used to deal with some ambiguous specs 54 Talents = {}, -- for each spec, selected talents
55 Equipped = {}, -- for each spec group (1 or 2), slot id to item link 55 Artifacts = {}, -- for each spec, artifact info
56 Equipped = {}, -- for each spec, slot id to item link
56 BagItems = {}, -- list of item links for bag 57 BagItems = {}, -- list of item links for bag
57 BankItems = {}, -- list of item links for bank 58 BankItems = {}, -- list of item links for bank
58 VoidItems = {}, -- list of item links for void storage 59 VoidItems = {}, -- list of item links for void storage
59 BagItemsAndCounts = {}, -- used mainly for the shopping list 60 BagItemsAndCounts = {}, -- used mainly for the shopping list
60 BankItemsAndCounts = {}, -- used mainly for the shopping list 61 BankItemsAndCounts = {}, -- used mainly for the shopping list
123 byDiff[difficultyId] = false 124 byDiff[difficultyId] = false
124 end 125 end
125 end 126 end
126 end 127 end
127 128
128 Amr.db = LibStub("AceDB-3.0"):New("AskMrRobotDb2", defaults) 129 Amr.db = LibStub("AceDB-3.0"):New("AskMrRobotDb3", defaults)
129 130
130 Amr.db.RegisterCallback(Amr, "OnProfileChanged", "RefreshConfig") 131 Amr.db.RegisterCallback(Amr, "OnProfileChanged", "RefreshConfig")
131 Amr.db.RegisterCallback(Amr, "OnProfileCopied", "RefreshConfig") 132 Amr.db.RegisterCallback(Amr, "OnProfileCopied", "RefreshConfig")
132 Amr.db.RegisterCallback(Amr, "OnProfileReset", "RefreshConfig") 133 Amr.db.RegisterCallback(Amr, "OnProfileReset", "RefreshConfig")
133 end 134 end
173 end 174 end
174 end 175 end
175 176
176 function Amr:OnEnable() 177 function Amr:OnEnable()
177 178
179 --[[
178 -- listen for changes to the snapshot enable state, and always make sure it is enabled if using the core AskMrRobot addon 180 -- listen for changes to the snapshot enable state, and always make sure it is enabled if using the core AskMrRobot addon
179 self:RegisterMessage("AMR_SNAPSHOT_STATE_CHANGED", function(eventName, isEnabled) 181 self:RegisterMessage("AMR_SNAPSHOT_STATE_CHANGED", function(eventName, isEnabled)
180 if not isEnabled then 182 if not isEnabled then
181 -- immediately re-enable on any attempt to disable 183 -- immediately re-enable on any attempt to disable
182 Amr.Serializer:EnableSnapshots() 184 Amr.Serializer:EnableSnapshots()
183 end 185 end
184 end) 186 end)
185 self.Serializer:EnableSnapshots() 187 self.Serializer:EnableSnapshots()
188 ]]
186 189
187 -- update based on current configuration whenever enabled 190 -- update based on current configuration whenever enabled
188 self:RefreshConfig() 191 self:RefreshConfig()
189 192
190 -- if we have fully entered the world, do initialization; otherwise wait for PLAYER_ENTERING_WORLD to continue 193 -- if we have fully entered the world, do initialization; otherwise wait for PLAYER_ENTERING_WORLD to continue
494 -- could not find or ambiguous 497 -- could not find or ambiguous
495 return nil 498 return nil
496 end 499 end
497 500
498 501
499 -- scanning tooltip b/c for some odd reason the api has no way to get basic item properties...
500 -- so you have to generate a fake item tooltip and search for pre-defined strings in the display text
501 local _scanTt
502 function Amr:GetScanningTooltip()
503 if not _scanTt then
504 _scanTt = CreateFrame("GameTooltip", "AmrUiScanTooltip", nil, "GameTooltipTemplate")
505 _scanTt:SetOwner(UIParent, "ANCHOR_NONE")
506 end
507 return _scanTt
508 end
509
510 local function scanTooltipHelper(txt, ...)
511 for i = 1, select("#", ...) do
512 local region = select(i, ...)
513 if region and region:GetObjectType() == "FontString" then
514 local text = region:GetText() -- string or nil
515 print(text)
516 end
517 end
518 end
519
520 -- search the tooltip for txt, returns true if it is encountered on any line 502 -- search the tooltip for txt, returns true if it is encountered on any line
521 function Amr:IsTextInTooltip(tt, txt) 503 function Amr:IsTextInTooltip(tt, txt)
522 local regions = { tt:GetRegions() } 504 local regions = { tt:GetRegions() }
523 for i, region in ipairs(regions) do 505 for i, region in ipairs(regions) do
524 if region and region:GetObjectType() == "FontString" then 506 if region and region:GetObjectType() == "FontString" then
530 return false 512 return false
531 end 513 end
532 514
533 -- helper to determine if we can equip an item (it is already soulbound or account bound) 515 -- helper to determine if we can equip an item (it is already soulbound or account bound)
534 function Amr:CanEquip(bagId, slotId) 516 function Amr:CanEquip(bagId, slotId)
535 local tt = self:GetScanningTooltip() 517 local tt = Amr.GetItemTooltip(bagId, slotId)
536 tt:ClearLines()
537 if bagId then
538 tt:SetBagItem(bagId, slotId)
539 else
540 tt:SetInventoryItem("player", slotId)
541 end
542 if self:IsTextInTooltip(tt, ITEM_SOULBOUND) then return true end 518 if self:IsTextInTooltip(tt, ITEM_SOULBOUND) then return true end
543 if self:IsTextInTooltip(tt, ITEM_BNETACCOUNTBOUND) then return true end 519 if self:IsTextInTooltip(tt, ITEM_BNETACCOUNTBOUND) then return true end
544 if self:IsTextInTooltip(tt, ITEM_ACCOUNTBOUND) then return true end 520 if self:IsTextInTooltip(tt, ITEM_ACCOUNTBOUND) then return true end
545 end 521 end
546 522
547 -- helper to determine if an item has a unique constraint 523 -- helper to determine if an item has a unique constraint
548 function Amr:IsUnique(bagId, slotId) 524 function Amr:IsUnique(bagId, slotId)
549 local tt = self:GetScanningTooltip() 525 local tt = Amr.GetItemTooltip(bagId, slotId)
550 tt:ClearLines()
551 if bagId then
552 tt:SetBagItem(bagId, slotId)
553 else
554 tt:SetInventoryItem("player", slotId)
555 end
556 if self:IsTextInTooltip(tt, ITEM_UNIQUE_EQUIPPABLE) then return true end 526 if self:IsTextInTooltip(tt, ITEM_UNIQUE_EQUIPPABLE) then return true end
557 if self:IsTextInTooltip(tt, ITEM_UNIQUE) then return true end 527 if self:IsTextInTooltip(tt, ITEM_UNIQUE) then return true end
558 return false 528 return false
559 end 529 end
560 530