comparison 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
comparison
equal deleted inserted replaced
5:7adbc59de8fe 6:df3e27edbd60
16 user-facing code, ones with lowercase names are "one step removed", and 16 user-facing code, ones with lowercase names are "one step removed", and
17 names with leading underscores are strictly internal helper functions. 17 names with leading underscores are strictly internal helper functions.
18 ------ Saved variables 18 ------ Saved variables
19 ------ Constants 19 ------ Constants
20 ------ Addon member data 20 ------ Addon member data
21 ------ Locals 21 ------ Globals
22 ------ Expiring caches 22 ------ Expiring caches
23 ------ Ace3 framework stuff 23 ------ Ace3 framework stuff
24 ------ Event handlers 24 ------ Event handlers
25 ------ Slash command handler 25 ------ Slash command handler
26 ------ On/off 26 ------ On/off
82 82
83 ------ Addon member data 83 ------ Addon member data
84 local flib = LibStub("LibFarmbuyer") 84 local flib = LibStub("LibFarmbuyer")
85 addon.author_debug = flib.author_debug 85 addon.author_debug = flib.author_debug
86 86
87 -- Play cute games with namespaces here just to save typing. 87 -- Play cute games with namespaces here just to save typing. WTB Lua 5.2 PST.
88 do local _G = _G setfenv (1, addon) 88 do local _G = _G setfenv (1, addon)
89 89
90 revision = 15 90 revision = 15
91 ident = "OuroLoot2" 91 ident = "OuroLoot2"
92 identTg = "OuroLoot2Tg" 92 identTg = "OuroLoot2Tg"
147 147
148 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Ouro Loot", 148 addon = LibStub("AceAddon-3.0"):NewAddon(addon, "Ouro Loot",
149 "AceTimer-3.0", "AceComm-3.0", "AceConsole-3.0", "AceEvent-3.0") 149 "AceTimer-3.0", "AceComm-3.0", "AceConsole-3.0", "AceEvent-3.0")
150 150
151 151
152 ------ Locals 152 ------ Globals
153 local g_loot = nil 153 local g_loot = nil
154 local g_restore_p = nil 154 local g_restore_p = nil
155 local g_saved_tmp = nil -- restoring across a clear 155 local g_saved_tmp = nil -- restoring across a clear
156 local g_wafer_thin = nil -- for prompting for additional rebroadcasters 156 local g_wafer_thin = nil -- for prompting for additional rebroadcasters
157 local g_today = nil -- "today" entry in g_loot 157 local g_today = nil -- "today" entry in g_loot
324 if opts[opt] == nil then 324 if opts[opt] == nil then
325 opts[opt] = default 325 opts[opt] = default
326 end 326 end
327 end 327 end
328 option_defaults = nil 328 option_defaults = nil
329 -- transition/remove old options 329 -- transition&remove old options
330 opts["forum_use_itemid"] = nil 330 opts["forum_use_itemid"] = nil
331 if opts["forum_format"] then 331 if opts["forum_format"] then
332 opts.forum["Custom..."] = opts["forum_format"] 332 opts.forum["Custom..."] = opts["forum_format"]
333 opts["forum_format"] = nil 333 opts["forum_format"] = nil
334 end 334 end
346 346
347 self.history_all = self.history_all or OuroLootSV_hist or {} 347 self.history_all = self.history_all or OuroLootSV_hist or {}
348 local r = assert(GetRealmName()) 348 local r = assert(GetRealmName())
349 self.history_all[r] = self:_prep_new_history_category (self.history_all[r], r) 349 self.history_all[r] = self:_prep_new_history_category (self.history_all[r], r)
350 self.history = self.history_all[r] 350 self.history = self.history_all[r]
351 OuroLootSV_hist = nil 351 --OuroLootSV_hist = nil
352 352
353 _init(self) 353 _init(self)
354 self.OnInitialize = nil 354 self.OnInitialize = nil
355 end 355 end
356 356
357 function addon:OnEnable() 357 function addon:OnEnable()
358 --if not OuroLootSV_hist.PLAYER_LOGOUT then print"did not safely logout?" end; OuroLootSV_hist.PLAYER_LOGOUT = nil
358 self:RegisterEvent "PLAYER_LOGOUT" 359 self:RegisterEvent "PLAYER_LOGOUT"
359 self:RegisterEvent "RAID_ROSTER_UPDATE" 360 self:RegisterEvent "RAID_ROSTER_UPDATE"
360 361
361 -- Cribbed from Talented. I like the way jerry thinks: the first argument 362 -- Cribbed from Talented. I like the way jerry thinks: the first argument
362 -- can be a format spec for the remainder of the arguments. (The new 363 -- can be a format spec for the remainder of the arguments. (The new
403 or (g_loot.forum and g_loot.forum ~= "") 404 or (g_loot.forum and g_loot.forum ~= "")
404 or (g_loot.attend and g_loot.attend ~= "") 405 or (g_loot.attend and g_loot.attend ~= "")
405 then 406 then
406 g_loot.autoshard = self.sharder 407 g_loot.autoshard = self.sharder
407 g_loot.threshold = self.threshold 408 g_loot.threshold = self.threshold
408 --OuroLootSV = g_loot
409 --for i,e in ipairs(OuroLootSV) do
410 for i,e in ipairs(g_loot) do 409 for i,e in ipairs(g_loot) do
411 e.cols = nil 410 e.cols = nil
412 end 411 end
413 OuroLootSV = g_loot 412 OuroLootSV = g_loot
414 end 413 end
415 self.history.kind = nil 414 for r,t in pairs(self.history_all) do if type(t) == 'table' then
416 self.history.st = nil 415 t.realm = nil
417 self.history.byname = nil 416 t.st = nil
417 t.byname = nil
418 end end
418 OuroLootSV_hist = self.history_all 419 OuroLootSV_hist = self.history_all
420 --OuroLootSV_hist.PLAYER_LOGOUT = true
419 end 421 end
420 422
421 function addon:RAID_ROSTER_UPDATE (event) 423 function addon:RAID_ROSTER_UPDATE (event)
422 if GetNumRaidMembers() > 0 then 424 if GetNumRaidMembers() > 0 then
423 local inside,whatkind = IsInInstance() 425 local inside,whatkind = IsInInstance()
444 -- helper for CHAT_MSG_LOOT handler 446 -- helper for CHAT_MSG_LOOT handler
445 do 447 do
446 -- Recent loot cache 448 -- Recent loot cache
447 addon.recent_loot = create_new_cache ('loot', comm_cleanup_ttl) 449 addon.recent_loot = create_new_cache ('loot', comm_cleanup_ttl)
448 450
449 local GetItemInfo = GetItemInfo 451 local GetItemInfo, GetItemIcon = GetItemInfo, GetItemIcon
450 452
451 -- 'from' and onwards only present if this is triggered by a broadcast 453 -- 'from' and onwards only present if this is triggered by a broadcast
452 function addon:_do_loot (local_override, recipient, itemid, count, from, extratext) 454 function addon:_do_loot (local_override, recipient, itemid, count, from, extratext)
453 local iname, ilink, iquality, _,_,_,_,_,_, itexture = GetItemInfo(itemid) 455 local itexture = GetItemIcon(itemid)
454 if not iname then return end -- sigh 456 --local iname, ilink, iquality, _,_,_,_,_,_, itexture = GetItemInfo(itemid)
457 local iname, ilink, iquality = GetItemInfo(itemid)
458 if (not iname) or (not itexture) then
459 iname, ilink, iquality, itexture =
460 UNKNOWN..': '..itemid, 'item:6948', ITEM_QUALITY_COMMON, [[ICONS\INV_Misc_QuestionMark]]
461 end
455 self.dprint('loot',">>_do_loot, R:", recipient, "I:", itemid, "C:", count, "frm:", from, "ex:", extratext) 462 self.dprint('loot',">>_do_loot, R:", recipient, "I:", itemid, "C:", count, "frm:", from, "ex:", extratext)
456 463
457 local i 464 local i
458 itemid = tonumber(ilink:match("item:(%d+)")) 465 itemid = tonumber(ilink:match("item:(%d+)"))
459 if local_override or ((iquality >= self.threshold) and not opts.itemfilter[itemid]) then 466 if local_override or ((iquality >= self.threshold) and not opts.itemfilter[itemid]) then
1169 -- }, ...... 1176 -- }, ......
1170 -- }, 1177 -- },
1171 -- ["OtherRealm"] = ...... 1178 -- ["OtherRealm"] = ......
1172 -- } 1179 -- }
1173 do 1180 do
1181 local tsort = table.sort
1182 local comp = function(L,R) return L.when > R.when end
1183
1174 -- Builds the map of names to array indices, using passed table or 1184 -- Builds the map of names to array indices, using passed table or
1175 -- self.history, and stores the result into its 'byname' field. Also 1185 -- self.history, and stores the result into its 'byname' field. Also
1176 -- called from the GUI code at least once. 1186 -- called from the GUI code at least once.
1177 function addon:_build_history_names (opt_hist) 1187 function addon:_build_history_names (opt_hist)
1178 local hist = opt_hist or self.history 1188 local hist = opt_hist or self.history
1185 1195
1186 -- Prepares and returns table to be used as self.history. 1196 -- Prepares and returns table to be used as self.history.
1187 function addon:_prep_new_history_category (prev_table, realmname) 1197 function addon:_prep_new_history_category (prev_table, realmname)
1188 local t = prev_table or { 1198 local t = prev_table or {
1189 --kind = 'realm', 1199 --kind = 'realm',
1190 realm = realmname, 1200 --realm = realmname,
1191 } 1201 }
1202 t.realm = realmname
1192 1203
1193 --[[ 1204 --[[
1194 t.cols = setmetatable({ 1205 t.cols = setmetatable({
1195 { value = realmname }, 1206 { value = realmname },
1196 }, self.time_column1_used_mt) 1207 }, self.time_column1_used_mt)
1202 1213
1203 return t 1214 return t
1204 end 1215 end
1205 1216
1206 -- Maps a name to an array index, creating new tables if needed. Returns 1217 -- Maps a name to an array index, creating new tables if needed. Returns
1218 -- the index and the table at that index.
1207 function addon:get_loot_history (name) 1219 function addon:get_loot_history (name)
1208 local i 1220 local i
1209 i = self.history.byname[name] 1221 i = self.history.byname[name]
1210 if not i then 1222 if not i then
1211 i = #self.history + 1 1223 i = #self.history + 1
1212 self.history[i] = { name=name } 1224 self.history[i] = { name=name }
1213 self.history.byname[name] = i 1225 self.history.byname[name] = i
1214 end 1226 end
1215 return self.history[i] 1227 return i, self.history[i]
1216 end 1228 end
1217 1229
1218 function addon:_addHistoryEntry (lootindex) 1230 function addon:_addHistoryEntry (lootindex)
1219 local e = g_loot[lootindex] 1231 local e = g_loot[lootindex]
1220 local h = self:get_loot_history(e.person) 1232 if e.kind ~= 'loot' then return end
1233
1234 local i,h = self:get_loot_history(e.person)
1221 local n = { 1235 local n = {
1222 id = e.id, 1236 id = e.id,
1223 when = self:format_timestamp (g_today, e), 1237 when = self:format_timestamp (g_today, e),
1224 count = e.count, 1238 count = e.count,
1225 } 1239 }
1226 h[#h+1] = n 1240 tinsert (h, 1, n)
1241 end
1242
1243 function addon:rewrite_history (realmname)
1244 local r = assert(realmname)
1245 self.history_all[r] = self:_prep_new_history_category (nil, r)
1246 self.history = self.history_all[r]
1247
1248 local g_today_real = g_today
1249 for i,e in ipairs(g_loot) do
1250 if e.kind == 'time' then
1251 g_today = e
1252 elseif e.kind == 'loot' then
1253 self:_addHistoryEntry(i)
1254 end
1255 end
1256 g_today = g_today_real
1257 self.hist_clean = nil
1258
1259 -- safety measure: resort players' tables based on formatted timestamp
1260 for i,h in ipairs(self.history) do
1261 tsort (h, comp)
1262 end
1263 end
1264
1265 function addon:preen_history (realmname)
1266 local r = assert(realmname)
1267 for i,h in ipairs(self.history) do
1268 tsort (h, comp)
1269 while #h > 1 do
1270 tremove (h)
1271 end
1272 end
1227 end 1273 end
1228 end 1274 end
1229 1275
1230 1276
1231 ------ Player communication 1277 ------ Player communication