Mercurial > wow > ouroloot
diff core.lua @ 6:df3e27edbd60
Much work on history tab.
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Wed, 15 Jun 2011 03:59:13 +0000 |
parents | 7adbc59de8fe |
children | 30ba1f35e164 |
line wrap: on
line diff
--- a/core.lua Wed Apr 27 04:02:02 2011 +0000 +++ b/core.lua Wed Jun 15 03:59:13 2011 +0000 @@ -18,7 +18,7 @@ ------ Saved variables ------ Constants ------ Addon member data ------- Locals +------ Globals ------ Expiring caches ------ Ace3 framework stuff ------ Event handlers @@ -84,7 +84,7 @@ local flib = LibStub("LibFarmbuyer") addon.author_debug = flib.author_debug --- Play cute games with namespaces here just to save typing. +-- Play cute games with namespaces here just to save typing. WTB Lua 5.2 PST. do local _G = _G setfenv (1, addon) revision = 15 @@ -149,7 +149,7 @@ "AceTimer-3.0", "AceComm-3.0", "AceConsole-3.0", "AceEvent-3.0") ------- Locals +------ Globals local g_loot = nil local g_restore_p = nil local g_saved_tmp = nil -- restoring across a clear @@ -326,7 +326,7 @@ end end option_defaults = nil - -- transition/remove old options + -- transition&remove old options opts["forum_use_itemid"] = nil if opts["forum_format"] then opts.forum["Custom..."] = opts["forum_format"] @@ -348,13 +348,14 @@ local r = assert(GetRealmName()) self.history_all[r] = self:_prep_new_history_category (self.history_all[r], r) self.history = self.history_all[r] - OuroLootSV_hist = nil + --OuroLootSV_hist = nil _init(self) self.OnInitialize = nil end function addon:OnEnable() + --if not OuroLootSV_hist.PLAYER_LOGOUT then print"did not safely logout?" end; OuroLootSV_hist.PLAYER_LOGOUT = nil self:RegisterEvent "PLAYER_LOGOUT" self:RegisterEvent "RAID_ROSTER_UPDATE" @@ -405,17 +406,18 @@ then g_loot.autoshard = self.sharder g_loot.threshold = self.threshold - --OuroLootSV = g_loot - --for i,e in ipairs(OuroLootSV) do for i,e in ipairs(g_loot) do e.cols = nil end OuroLootSV = g_loot end - self.history.kind = nil - self.history.st = nil - self.history.byname = nil + for r,t in pairs(self.history_all) do if type(t) == 'table' then + t.realm = nil + t.st = nil + t.byname = nil + end end OuroLootSV_hist = self.history_all + --OuroLootSV_hist.PLAYER_LOGOUT = true end function addon:RAID_ROSTER_UPDATE (event) @@ -446,12 +448,17 @@ -- Recent loot cache addon.recent_loot = create_new_cache ('loot', comm_cleanup_ttl) - local GetItemInfo = GetItemInfo + local GetItemInfo, GetItemIcon = GetItemInfo, GetItemIcon -- 'from' and onwards only present if this is triggered by a broadcast function addon:_do_loot (local_override, recipient, itemid, count, from, extratext) - local iname, ilink, iquality, _,_,_,_,_,_, itexture = GetItemInfo(itemid) - if not iname then return end -- sigh + local itexture = GetItemIcon(itemid) + --local iname, ilink, iquality, _,_,_,_,_,_, itexture = GetItemInfo(itemid) + local iname, ilink, iquality = GetItemInfo(itemid) + if (not iname) or (not itexture) then + iname, ilink, iquality, itexture = + UNKNOWN..': '..itemid, 'item:6948', ITEM_QUALITY_COMMON, [[ICONS\INV_Misc_QuestionMark]] + end self.dprint('loot',">>_do_loot, R:", recipient, "I:", itemid, "C:", count, "frm:", from, "ex:", extratext) local i @@ -1171,6 +1178,9 @@ -- ["OtherRealm"] = ...... -- } do + local tsort = table.sort + local comp = function(L,R) return L.when > R.when end + -- Builds the map of names to array indices, using passed table or -- self.history, and stores the result into its 'byname' field. Also -- called from the GUI code at least once. @@ -1187,8 +1197,9 @@ function addon:_prep_new_history_category (prev_table, realmname) local t = prev_table or { --kind = 'realm', - realm = realmname, + --realm = realmname, } + t.realm = realmname --[[ t.cols = setmetatable({ @@ -1204,6 +1215,7 @@ end -- Maps a name to an array index, creating new tables if needed. Returns + -- the index and the table at that index. function addon:get_loot_history (name) local i i = self.history.byname[name] @@ -1212,18 +1224,52 @@ self.history[i] = { name=name } self.history.byname[name] = i end - return self.history[i] + return i, self.history[i] end function addon:_addHistoryEntry (lootindex) local e = g_loot[lootindex] - local h = self:get_loot_history(e.person) + if e.kind ~= 'loot' then return end + + local i,h = self:get_loot_history(e.person) local n = { id = e.id, when = self:format_timestamp (g_today, e), count = e.count, } - h[#h+1] = n + tinsert (h, 1, n) + end + + function addon:rewrite_history (realmname) + local r = assert(realmname) + self.history_all[r] = self:_prep_new_history_category (nil, r) + self.history = self.history_all[r] + + local g_today_real = g_today + for i,e in ipairs(g_loot) do + if e.kind == 'time' then + g_today = e + elseif e.kind == 'loot' then + self:_addHistoryEntry(i) + end + end + g_today = g_today_real + self.hist_clean = nil + + -- safety measure: resort players' tables based on formatted timestamp + for i,h in ipairs(self.history) do + tsort (h, comp) + end + end + + function addon:preen_history (realmname) + local r = assert(realmname) + for i,h in ipairs(self.history) do + tsort (h, comp) + while #h > 1 do + tremove (h) + end + end end end