changeset 128:b06147ded0bc

Added recording of blacklisted battlegrounds.
author James D. Callahan III <jcallahan@curse.com>
date Wed, 19 Sep 2012 09:29:56 -0500
parents 6f48d374cda5
children e0550c57972d
files Main.lua
diffstat 1 files changed, 37 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Main.lua	Tue Sep 18 14:51:46 2012 -0500
+++ b/Main.lua	Wed Sep 19 09:29:56 2012 -0500
@@ -35,6 +35,7 @@
 
 
 local DATABASE_DEFAULTS = {
+    char = {},
     global = {
         items = {},
         npcs = {},
@@ -116,7 +117,8 @@
 -----------------------------------------------------------------------
 local anvil_spell_ids = {}
 local currently_drunk
-local db
+local char_db
+local global_db
 local durability_timer_handle
 local faction_standings = {}
 local forge_spell_ids = {}
@@ -201,11 +203,11 @@
     if not data_type or not unit_id then
         return
     end
-    local unit = db[data_type][unit_id]
+    local unit = global_db[data_type][unit_id]
 
     if not unit then
-        db[data_type][unit_id] = {}
-        unit = db[data_type][unit_id]
+        global_db[data_type][unit_id] = {}
+        unit = global_db[data_type][unit_id]
     end
     return unit
 end
@@ -289,6 +291,25 @@
 end -- do-block
 
 
+local function UpdateBlacklistMaps()
+    local empty_count = 0
+
+    for index = 1, _G.MAX_BLACKLIST_BATTLEGROUNDS do
+        local map_id = _G.GetBlacklistMap(index)
+        char_db.bg_blacklist = char_db.bg_blacklist or {}
+        char_db.bg_blacklist[index] = map_id
+
+        if map_id < 0 then
+            empty_count = empty_count + 1
+        end
+    end
+
+    if empty_count == _G.MAX_BLACKLIST_BATTLEGROUNDS then
+        char_db.bg_blacklist = nil
+    end
+end
+
+
 local function UpdateDBEntryLocation(entry_type, identifier)
     if not identifier then
         return
@@ -526,7 +547,9 @@
 -- Methods.
 -----------------------------------------------------------------------
 function WDP:OnInitialize()
-    db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default").global
+    local db = LibStub("AceDB-3.0"):New("WoWDBProfilerData", DATABASE_DEFAULTS, "Default")
+    global_db = db.global
+    char_db = db.char
 
     local raw_db = _G["WoWDBProfilerData"]
     local build_num = tonumber(private.build_num)
@@ -535,7 +558,7 @@
     --    if raw_db.build_num and raw_db.build_num < build_num then
     if raw_db.version and raw_db.version < DB_VERSION then
         for entry in pairs(DATABASE_DEFAULTS.global) do
-            db[entry] = {}
+            global_db[entry] = {}
         end
     end
     raw_db.build_num = build_num
@@ -568,8 +591,12 @@
         local _, item_link = _G.GetItemInfo(identifier)
         HandleItemUse(item_link)
     end)
+    SetCurrentAreaID()
 
-    SetCurrentAreaID()
+    _G.hooksecurefunc("SetBlacklistMap", UpdateBlacklistMaps)
+    _G.hooksecurefunc("ClearBlacklistMap", UpdateBlacklistMaps)
+
+    UpdateBlacklistMaps()
 end
 
 
@@ -578,10 +605,10 @@
         return
     end
 
-    if not db.items[item_id] then
-        db.items[item_id] = {}
+    if not global_db.items[item_id] then
+        global_db.items[item_id] = {}
     end
-    db.items[item_id].durability = durability
+    global_db.items[item_id].durability = durability
 end
 
 
@@ -1597,7 +1624,6 @@
             end
         end
     end
-
     -- Reset the filters to what they were before
     _G.SetTrainerServiceTypeFilter("available", available or 0)
     _G.SetTrainerServiceTypeFilter("unavailable", unavailable or 0)