From 212ed347c525f736da96da50a5f54d1f94ce3d50 Mon Sep 17 00:00:00 2001 From: Joseph Collins Date: Wed, 30 Jan 2013 01:41:04 -0800 Subject: [PATCH] Loads bug-free! --- Character.lua | 159 ++++++++++++--------------------------------------- ChillEffectAlts.lua | 69 +++++++++++++--------- 2 files changed, 80 insertions(+), 148 deletions(-) diff --git a/Character.lua b/Character.lua index 51beeb6..39f9de6 100644 --- a/Character.lua +++ b/Character.lua @@ -4,6 +4,8 @@ local addonName, addonTable = ...; Usage note: The methods of this object manipulate the Blizzard APIs to populate the fields of the Character object. To retrieve the final data, access the tables directly. + + Rather than getter+setter, I've gone with updater+getter here. I feel like it makes sense. --]] local Character = {}; Character.__index = Character; @@ -60,46 +62,20 @@ function Character:new(db) setmetatable(self, Character); self.db = db; - self.db.currencies = {}; -- - self.db.heirlooms = {}; -- - self.db.conveyable = {}; -- - self.miscData = {}; -- - - - - -- Subtle bug averted here. If these functions are defined using colon syntax, it creates conflicting "self" references as written - local function UpdateCurrencies() - self:GetCurrencyData(); - self.db.char.currency = self.currencies; - addon:RedrawCurrencyFrame() - end - - local function UpdateItems() - self:GetHeirloomData(1); - self:GetConveyableData(1); - if self.isBankOpen then - -- print("Scanning bank too!") - self:GetHeirloomData(0); - self:GetConveyableData(0); - end - self.db.char.heirloom = self.heirlooms - self.db.char.conveyable = self.conveyable - end + -- self.db.currencies = {}; -- + -- self.db.heirlooms = {}; -- + -- self.db.conveyable = {}; -- + -- self.miscData = {}; -- return self; end -function Character:GetName() - return GetUnitName("player") -end - --[[ Collects the names and quantities of the character's Currencies. NOTE: Includes gold as well, though this is not considered a Currency by Blizzard - @return currencies - an associative array mapping currency names to their quantities --]] -function Character:GetCurrencyData() - local currencies = {}; +function Character:UpdateCurrencies() + wipe(self.db.currencies) self:ExpandCurrencyHeaders(); @@ -108,15 +84,12 @@ function Character:GetCurrencyData() local name, isHeader, isExpanded, isUnused, isWatched, count, extraCurrencyType, icon, itemID = GetCurrencyListInfo(i); if (not isHeader) then - currencies[name] = count; + self.db.currencies[name] = count; end end -- Using a global string, en-US "Money", as key. - currencies[MONEY] = GetMoney(); - - self.currencies = currencies; - return currencies; + self.db.currencies[MONEY] = GetMoney(); end --[[ @@ -139,106 +112,50 @@ function Character:ExpandCurrencyHeaders() end --[[ - Collects a list of the heirloom items the character possesses, and their general locations (bank, bags, equipped). - NOTE: Will fail to detect any heirlooms currently in a mailbox. - @params location - 1 for bags, 2 for bank - @return heirlooms - an associative array mapping heirloom itemIDs to their general location --]] function Character:GetHeirloomData(location) - local heirlooms = {}; - - local link - if location == 1 then - for bag = 0, NUM_BAG_SLOTS do - for slot = 1, GetContainerNumSlots(bag) do - link = GetContainerItemLink(bag, slot) - if link then - ItemScanner:AddToItemPool(link, function(link) - local name, id, rarity = GetItemInfo(link) - if rarity == 7 then - heirlooms[name] = {bag, slot} - end - end) - end - end - end - else - for bag = NUM_BAG_SLOTS, NUM_BAG_SLOTS+NUM_BANKBAGSLOTS do - if bag == NUM_BAG_SLOTS then bag = 0 end -- a little hackish; the main bank inventory is slot 0 and bank bags start at NUM_BAG_SLOTS+1 - for slot = 1, GetContainerNumSlots(bag) do - link = GetContainerItemLink(bag, slot) - if link then - ItemScanner:AddToItemPool(link, function(link) - local name, id, rarity = GetItemInfo(link) - if rarity == 7 then - heirlooms[name] = {bag, slot} - end - end) - end - end - end - end - self.heirlooms = heirlooms; - return heirlooms; end +function Character:GetBags() + +end --[[ - Collects the names and quantities of conveyable items the character possesses, and their general locations (bank, bags, equipped). - Conveyable is defined as any item that is not soulbound or an heirloom. - @params location - 1 for bags, 2 for bank - @return conveyables - an associative array mapping conveyable itemIDs to their general locations --]] -function Character:UpdateBags(location) - local conveyables = {}; +function Character:UpdateBags() + wipe(self.db.bags) local link, name, link, rarity, count - if location == 1 then - for bag = 0, NUM_BAG_SLOTS do - for slot = 1, GetContainerNumSlots(bag) do - link = GetContainerItemLink(bag, slot) - if link then - ItemScanner:AddToItemPool(link, function(link) - -- local name, id, rarity = GetItemInfo(link) - -- if rarity > 1 and rarity < 7 and not IsSoulboundItem(bag, slot) then -- skip heirlooms and vendor trash - -- count = select(2, GetContainerItemInfo(bag, slot)) - -- if not conveyables[name] then - -- conveyables[name] = count - -- else - -- conveyables[name] = conveyables[name] +count - -- end - -- end - - end) - end + + for bag = 0, NUM_BAG_SLOTS do + for slot = 1, GetContainerNumSlots(bag) do + link = GetContainerItemLink(bag, slot) + if link then + ItemScanner:AddToItemPool(link, function(link) + tinsert(self.db.bags, {bag, slot, link, count}) + end) end end - else - for bag = NUM_BAG_SLOTS, NUM_BAG_SLOTS+NUM_BANKBAGSLOTS do - if bag == NUM_BAG_SLOTS then bag = 0 end -- a little hackish; the main bank inventory is slot 0 and bank bags start at NUM_BAG_SLOTS+1 - for slot = 1, GetContainerNumSlots(bag) do - link = GetContainerItemLink(bag, slot) - if link then - ItemScanner:AddToItemPool(link, function(link) - local name, id, rarity = GetItemInfo(link) - if rarity > 1 and rarity < 7 and not IsSoulboundItem(bag, slot) then -- skip heirlooms and vendor trash - count = select(2, GetContainerItemInfo(bag, slot)) - if not conveyables[name] then - conveyables[name] = count - else - conveyables[name] = conveyables[name] +count - end - end - end) - end + end +end + +function Character:UpdateBank() + wipe(self.db.bank) + + local link, name, link, rarity, count + for bag = NUM_BAG_SLOTS, NUM_BAG_SLOTS+NUM_BANKBAGSLOTS do + if bag == NUM_BAG_SLOTS then bag = 0 end -- a little hackish; the main bank inventory is slot 0 and bank bags start at NUM_BAG_SLOTS+1 + for slot = 1, GetContainerNumSlots(bag) do + link = GetContainerItemLink(bag, slot) + if link then + ItemScanner:AddToItemPool(link, function(link) + tinsert(self.db.bank, {bag, slot, link, count}) + end) end end end - - self.conveyables = conveyables; - return conveyables; end --[[ diff --git a/ChillEffectAlts.lua b/ChillEffectAlts.lua index f2bb6b4..d230c9a 100644 --- a/ChillEffectAlts.lua +++ b/ChillEffectAlts.lua @@ -1,6 +1,9 @@ local addonName, addonTable = ...; ChillEffectAlts = LibStub("AceAddon-3.0"):NewAddon("ChillEffectAlts", "AceEvent-3.0") local L = LibStub("AceLocale-3.0"):GetLocale("ChillEffectAlts", true) +local CurrenciesModule = addonTable.Currencies +local CharacterModule = addonTable.Character +local Character function ChillEffectAlts:OnInitialize() local defaults = { @@ -10,7 +13,7 @@ function ChillEffectAlts:OnInitialize() inventory = {}, }, } - self.db = LibStub("AceDB-3.0"):New("CEAltsDB") + self.db = LibStub("AceDB-3.0"):New("CEAltsDB", defaults) SLASH_ChillEffectAlts1 = "/alt" SlashCmdList["ChillEffectAlts"] = function() @@ -82,41 +85,53 @@ function ChillEffectAlts:OnInitialize() end) end +local function UpdateCurrencies() + assert(Character) + Character:UpdateCurrencies() + CurrenciesModule:RedrawCurrencyFrame() +end + +local function UpdateBags() + assert(Character) + Character:UpdateBags() +end + +local function UpdateBank() + assert(Character) + Character:UpdateBank() +end + +local function UpdateVoidStorage() + assert(Character) + Character:UpdateVoidStorage() +end + +function ChillEffectAlts:BANKFRAME_OPENED() + self.isBankOpen = true + self:UpdateBank() +end + +function ChillEffectAlts:BANKFRAME_CLOSED() + self.isBankOpen = false +end + local gui_built = false function ChillEffectAlts:OnEnable() if not gui_built then - addonTable.Currencies:CreateCurrencyFrame() + CurrenciesModule:CreateCurrencyFrame() end - local character = addonTable.Character:new(self.db.char) - function self:RedrawCurrencyFrame(self, currencyOrder) - addonTable.Currencies:RedrawCurrencyFrame(currencyOrder) - end + Character = CharacterModule:new(self.db.char) -- Track the open state of the bank. Can't check for IsShown, because addons self.isBankOpen = false; - addon:RegisterEvent("BANKFRAME_OPENED", function() self.isBankOpen = true self.UpdateItems() end) - addon:RegisterEvent("BANKFRAME_CLOSED", function() self.isBankOpen = false end) - - local function UpdateCurrencies() - character.UpdateCurrencies() - self.db.char.currencies = character.GetCurrencies() - self:RedrawCurrencyFrame() - end + self:RegisterEvent("BANKFRAME_OPENED") + self:RegisterEvent("BANKFRAME_CLOSED") - local function UpdateBags() - character.UpdateBags() - self.db.char.bags = character.GetBags() - self.db.char.heirlooms = character.GetHeirlooms() - end - - local function UpdateInventory() - - end - addon:RegisterEvent("PLAYER_ENTERING_WORLD", UpdateCurrencies) - addon:RegisterEvent("PLAYER_MONEY", UpdateCurrencies) - addon:RegisterEvent("CURRENCY_DISPLAY_UPDATE", UpdateCurrencies) + self:RegisterEvent("PLAYER_ENTERING_WORLD", UpdateCurrencies) + self:RegisterEvent("PLAYER_MONEY", UpdateCurrencies) + self:RegisterEvent("CURRENCY_DISPLAY_UPDATE", UpdateCurrencies) - addon:RegisterEvent("BAG_UPDATE_DELAYED", UpdateBags) + self:RegisterEvent("BAG_UPDATE_DELAYED", UpdateBags) end \ No newline at end of file -- 1.7.9.5