Mercurial > wow > ouroloot
comparison core.lua @ 107:35b55c6f5551
Cleanups and reminders to myself.
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Mon, 06 Aug 2012 13:14:38 -0400 |
| parents | 095ee38508e8 |
| children | 04ccd12c2a41 |
comparison
equal
deleted
inserted
replaced
| 106:095ee38508e8 | 107:35b55c6f5551 |
|---|---|
| 374 local opts = nil | 374 local opts = nil |
| 375 | 375 |
| 376 local error = addon.error | 376 local error = addon.error |
| 377 local assert = addon.assert | 377 local assert = addon.assert |
| 378 | 378 |
| 379 -- for speeding up local loads, not because I think _G will change | 379 local type, select, next, pairs, ipairs, tinsert, tremove, tostring, tonumber, wipe = |
| 380 local _G = _G | 380 type, select, next, pairs, ipairs, table.insert, table.remove, tostring, tonumber, table.wipe |
| 381 local type = _G.type | |
| 382 local select = _G.select | |
| 383 local pairs = _G.pairs | |
| 384 local ipairs = _G.ipairs | |
| 385 local tinsert = _G.table.insert | |
| 386 local tremove = _G.table.remove | |
| 387 local tostring = _G.tostring | |
| 388 local tonumber = _G.tonumber | |
| 389 local wipe = _G.table.wipe | |
| 390 | 381 |
| 391 local pprint, tabledump = addon.pprint, flib.tabledump | 382 local pprint, tabledump = addon.pprint, flib.tabledump |
| 392 local CopyTable = _G.CopyTable | 383 local CopyTable = CopyTable |
| 393 local GetNumRaidMembers = _G.GetNumGroupMembers or _G.GetNumRaidMembers | 384 local GetNumRaidMembers = GetNumGroupMembers or GetNumRaidMembers |
| 394 local IsInRaid = _G.IsInRaid or (function() return GetNumRaidMembers() > 0 end) | 385 local IsInRaid = IsInRaid or (function() return GetNumRaidMembers() > 0 end) |
| 395 -- En masse forward decls of symbols defined inside local blocks | 386 -- En masse forward decls of symbols defined inside local blocks |
| 396 local _register_bossmod, makedate, create_new_cache, _init, _log, _do_loot_metas | 387 local _register_bossmod, makedate, create_new_cache, _init, _log, _do_loot_metas |
| 397 local _history_by_loot_id, _setup_unique_replace, _unavoidable_collision | 388 local _history_by_loot_id, _setup_unique_replace, _unavoidable_collision |
| 398 local _notify_about_change | 389 local _notify_about_change |
| 399 | 390 |
| 421 | 412 |
| 422 -- Hypertext support, inspired by DBM broadcast pizza timers | 413 -- Hypertext support, inspired by DBM broadcast pizza timers |
| 423 do | 414 do |
| 424 local hypertext_format_str = "|HOuroLoot:%d|h%s[%s]|r|h" | 415 local hypertext_format_str = "|HOuroLoot:%d|h%s[%s]|r|h" |
| 425 local func_map = {} --_G.setmetatable({}, {__mode = 'k'}) | 416 local func_map = {} --_G.setmetatable({}, {__mode = 'k'}) |
| 426 local text_map = {} _G.setmetatable({}, {__mode = 'v'}) | 417 local text_map = setmetatable({}, {__mode = 'v'}) |
| 427 local base = _G.newproxy(true) | 418 local base = newproxy(true) |
| 428 _G.getmetatable(base).__tostring = function(ud) return text_map[ud] end | 419 getmetatable(base).__tostring = function(ud) return text_map[ud] end |
| 429 --@debug@ | 420 --@debug@ |
| 430 -- auto collecting these tokens is an interesting micro-optimization but not yet | 421 -- auto collecting these tokens is an interesting micro-optimization but not yet |
| 431 _G.getmetatable(base).__index = { | 422 getmetatable(base).__index = { |
| 432 ['done'] = function (ud) | 423 ['done'] = function (ud) |
| 433 text_map[ud] = nil | 424 text_map[ud] = nil |
| 434 func_map[ud] = nil | 425 func_map[ud] = nil |
| 435 end, | 426 end, |
| 436 } | 427 } |
| 437 _G.getmetatable(base).__gc = function(ud) | 428 getmetatable(base).__gc = function(ud) |
| 438 print("Collecting hyperlink object <",tostring(ud),">") | 429 print("Collecting hyperlink object <",tostring(ud),">") |
| 439 end | 430 end |
| 440 --@end-debug@ | 431 --@end-debug@ |
| 441 | 432 |
| 442 -- TEXT will automatically be surrounded by brackets | 433 -- TEXT will automatically be surrounded by brackets |
| 448 -- in chat. The MethodName and raw function callbacks will both be | 439 -- in chat. The MethodName and raw function callbacks will both be |
| 449 -- passed the addon table and the same matching number. | 440 -- passed the addon table and the same matching number. |
| 450 -- | 441 -- |
| 451 -- This is largely an excuse to fool around with Lua data constructs. | 442 -- This is largely an excuse to fool around with Lua data constructs. |
| 452 function addon.format_hypertext (text, color, func) | 443 function addon.format_hypertext (text, color, func) |
| 453 local ret = _G.newproxy(base) | 444 local ret = newproxy(base) |
| 454 local num = #text_map + 1 | 445 local num = #text_map + 1 |
| 455 text_map[ret] = hypertext_format_str:format (num, | 446 text_map[ret] = hypertext_format_str:format (num, |
| 456 type(color)=='number' and ITEM_QUALITY_COLORS[color].hex or color, | 447 type(color)=='number' and ITEM_QUALITY_COLORS[color].hex or color, |
| 457 text) | 448 text) |
| 458 text_map[num] = ret | 449 text_map[num] = ret |
| 466 mousebutton: "LeftButton", "MiddleButton", "RightButton" | 457 mousebutton: "LeftButton", "MiddleButton", "RightButton" |
| 467 | 458 |
| 468 amusingly, print()'ing the fullstring below as a debugging aid yields | 459 amusingly, print()'ing the fullstring below as a debugging aid yields |
| 469 another clickable link, yay data reproducability | 460 another clickable link, yay data reproducability |
| 470 ]] | 461 ]] |
| 471 local strsplit = _G.strsplit | 462 local strsplit = strsplit |
| 472 DEFAULT_CHAT_FRAME:HookScript("OnHyperlinkClick", function(self, link, fullstring, mousebutton) | 463 DEFAULT_CHAT_FRAME:HookScript("OnHyperlinkClick", function(self, link, fullstring, mousebutton) |
| 473 local ltype, arg = strsplit(":",link) | 464 local ltype, arg = strsplit(":",link) |
| 474 if ltype ~= "OuroLoot" then return end | 465 if ltype ~= "OuroLoot" then return end |
| 475 arg = tonumber(arg) | 466 arg = tonumber(arg) |
| 476 local f = func_map[text_map[arg]] | 467 local f = func_map[text_map[arg]] |
| 620 | 611 |
| 621 -- If unique keys ever change into objects instead of strings, change | 612 -- If unique keys ever change into objects instead of strings, change |
| 622 -- this into a weakly-keyed table. | 613 -- this into a weakly-keyed table. |
| 623 mt = { __metatable = 'Should be using setmode.' } | 614 mt = { __metatable = 'Should be using setmode.' } |
| 624 | 615 |
| 625 g_uniques = _G.setmetatable (m_reset{}, mt) | 616 g_uniques = setmetatable (m_reset{}, mt) |
| 626 end | 617 end |
| 627 | 618 |
| 628 | 619 |
| 629 ------ Expiring caches | 620 ------ Expiring caches |
| 630 --[[ | 621 --[[ |
| 646 end | 637 end |
| 647 end | 638 end |
| 648 ]] | 639 ]] |
| 649 do | 640 do |
| 650 local caches = {} | 641 local caches = {} |
| 651 local cleanup_group = _G.AnimTimerFrame:CreateAnimationGroup() | 642 local cleanup_group = AnimTimerFrame:CreateAnimationGroup() |
| 652 local time, next = _G.time, _G.next | 643 local time, next = time, next |
| 653 local new, del = flib.new, flib.del | 644 local new, del = flib.new, flib.del |
| 654 cleanup_group:SetLooping("REPEAT") | 645 cleanup_group:SetLooping("REPEAT") |
| 655 cleanup_group:SetScript("OnLoop", function(cg) | 646 cleanup_group:SetScript("OnLoop", function(cg) |
| 656 addon.dprint('cache',"OnLoop firing") | 647 addon.dprint('cache',"OnLoop firing") |
| 657 local now = time() | 648 local now = time() |
| 731 function addon:OnInitialize() | 722 function addon:OnInitialize() |
| 732 if self.author_debug then | 723 if self.author_debug then |
| 733 _G.OL = self | 724 _G.OL = self |
| 734 _G.g_uniques = g_uniques | 725 _G.g_uniques = g_uniques |
| 735 end | 726 end |
| 736 _log = _G.OuroLootSV_log | 727 _log = OuroLootSV_log |
| 737 | 728 |
| 738 -- VARIABLES_LOADED has fired by this point; test if we're doing something like | 729 -- VARIABLES_LOADED has fired by this point; test if we're doing something like |
| 739 -- relogging during a raid and already have collected loot data | 730 -- relogging during a raid and already have collected loot data |
| 740 local OuroLootSV = _G.OuroLootSV | 731 local OuroLootSV = OuroLootSV |
| 741 g_restore_p = OuroLootSV ~= nil | 732 g_restore_p = OuroLootSV ~= nil |
| 742 self.dprint('flow', "oninit sets restore as", g_restore_p) | 733 self.dprint('flow', "oninit sets restore as", g_restore_p) |
| 743 | 734 |
| 744 -- Primarily for plugins, but can be of use to me also... | 735 -- Primarily for plugins, but can be of use to me also... |
| 745 self.callbacks = _G.LibStub("CallbackHandler-1.0"):New(self) | 736 self.callbacks = LibStub("CallbackHandler-1.0"):New(self) |
| 746 --function self.callbacks:OnUsed (target_aka_self, eventname) end | 737 --function self.callbacks:OnUsed (target_aka_self, eventname) end |
| 747 --function self.callbacks:OnUnused (target_aka_self, eventname) end | 738 --function self.callbacks:OnUnused (target_aka_self, eventname) end |
| 748 | 739 |
| 749 if _G.OuroLootOptsDB == nil then | 740 if _G.OuroLootOptsDB == nil then |
| 750 local vclick = self.format_hypertext ([[click here]], ITEM_QUALITY_UNCOMMON, 'help') | 741 local vclick = self.format_hypertext ([[click here]], ITEM_QUALITY_UNCOMMON, 'help') |
| 759 virgin = nil | 750 virgin = nil |
| 760 end,10,self) | 751 end,10,self) |
| 761 else | 752 else |
| 762 virgin = nil | 753 virgin = nil |
| 763 end | 754 end |
| 764 self.db = _G.LibStub("AceDB-3.0"):New("OuroLootOptsDB", option_defaults , --[[Default=]]true) | 755 self.db = LibStub("AceDB-3.0"):New("OuroLootOptsDB", option_defaults , --[[Default=]]true) |
| 765 self.db.RegisterCallback (self, "OnNewProfile", function() | 756 self.db.RegisterCallback (self, "OnNewProfile", function() |
| 766 self:Print(new_profile_warning) | 757 self:Print(new_profile_warning) |
| 767 end) | 758 end) |
| 768 self.db.RegisterCallback (self, "OnProfileChanged", "DBProfileRefresh") | 759 self.db.RegisterCallback (self, "OnProfileChanged", "DBProfileRefresh") |
| 769 self.db.RegisterCallback (self, "OnProfileCopied", "DBProfileRefresh") | 760 self.db.RegisterCallback (self, "OnProfileCopied", "DBProfileRefresh") |
| 788 n = n + 1 | 779 n = n + 1 |
| 789 end | 780 end |
| 790 end | 781 end |
| 791 | 782 |
| 792 self.history_all = self.history_all or _G.OuroLootSV_hist or {} | 783 self.history_all = self.history_all or _G.OuroLootSV_hist or {} |
| 793 local r = self:load_assert (_G.GetRealmName(), "how the freak does GetRealmName() fail?") | 784 local r = self:load_assert (GetRealmName(), "how the freak does GetRealmName() fail?") |
| 794 self.history_all[r] = self:_prep_new_history_category (self.history_all[r], r) | 785 self.history_all[r] = self:_prep_new_history_category (self.history_all[r], r) |
| 795 self.history = self.history_all[r] | 786 self.history = self.history_all[r] |
| 796 | 787 |
| 797 local histformat = self.history_all.HISTFORMAT | 788 local histformat = self.history_all.HISTFORMAT |
| 798 self.history_all.HISTFORMAT = nil -- don't keep this in live data | 789 self.history_all.HISTFORMAT = nil -- don't keep this in live data |
| 958 | 949 |
| 959 ??? do something with LOOT_ITEM_WHILE_PLAYER_INELIGIBLE for locked LFRs? | 950 ??? do something with LOOT_ITEM_WHILE_PLAYER_INELIGIBLE for locked LFRs? |
| 960 ]] | 951 ]] |
| 961 | 952 |
| 962 -- LOOT_ITEM = "%s receives loot: %s." --> (.+) receives loot: (.+)%. | 953 -- LOOT_ITEM = "%s receives loot: %s." --> (.+) receives loot: (.+)%. |
| 963 g_LOOT_ITEM_ss = _G.LOOT_ITEM:gsub('%.$','%%.'):gsub('%%s','(.+)') | 954 g_LOOT_ITEM_ss = LOOT_ITEM:gsub('%.$','%%.'):gsub('%%s','(.+)') |
| 964 | 955 |
| 965 -- LOOT_ITEM_MULTIPLE = "%s receives loot: %sx%d." --> (.+) receives loot: (.+)(x%d+)%. | 956 -- LOOT_ITEM_MULTIPLE = "%s receives loot: %sx%d." --> (.+) receives loot: (.+)(x%d+)%. |
| 966 g_LOOT_ITEM_MULTIPLE_sss = _G.LOOT_ITEM_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)') | 957 g_LOOT_ITEM_MULTIPLE_sss = LOOT_ITEM_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)') |
| 967 | 958 |
| 968 -- LOOT_ITEM_SELF = "You receive loot: %s." --> You receive loot: (.+)%. | 959 -- LOOT_ITEM_SELF = "You receive loot: %s." --> You receive loot: (.+)%. |
| 969 g_LOOT_ITEM_SELF_s = _G.LOOT_ITEM_SELF:gsub('%.$','%%.'):gsub('%%s','(.+)') | 960 g_LOOT_ITEM_SELF_s = LOOT_ITEM_SELF:gsub('%.$','%%.'):gsub('%%s','(.+)') |
| 970 | 961 |
| 971 -- LOOT_ITEM_SELF_MULTIPLE = "You receive loot: %sx%d." --> You receive loot: (.+)(x%d+)%. | 962 -- LOOT_ITEM_SELF_MULTIPLE = "You receive loot: %sx%d." --> You receive loot: (.+)(x%d+)%. |
| 972 g_LOOT_ITEM_SELF_MULTIPLE_ss = _G.LOOT_ITEM_SELF_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)') | 963 g_LOOT_ITEM_SELF_MULTIPLE_ss = LOOT_ITEM_SELF_MULTIPLE:gsub('%.$','%%.'):gsub('%%s','(.+)'):gsub('x%%d','(x%%d+)') |
| 973 | 964 |
| 974 --[[ | 965 --[[ |
| 975 Stick something in the Blizzard addons options list, where most users | 966 Stick something in the Blizzard addons options list, where most users |
| 976 will probably look these days. Try to be conservative about needless | 967 will probably look these days. Try to be conservative about needless |
| 977 frame creation. | 968 frame creation. |
| 981 bliz:SetScript("OnShow", function(_b) | 972 bliz:SetScript("OnShow", function(_b) |
| 982 local button = CreateFrame("Button",nil,_b,"UIPanelButtonTemplate") | 973 local button = CreateFrame("Button",nil,_b,"UIPanelButtonTemplate") |
| 983 button:SetWidth(150) | 974 button:SetWidth(150) |
| 984 button:SetHeight(22) | 975 button:SetHeight(22) |
| 985 button:SetScript("OnClick", function() | 976 button:SetScript("OnClick", function() |
| 986 _G.InterfaceOptionsFrameCancel:Click() | 977 InterfaceOptionsFrameCancel:Click() |
| 987 _G.HideUIPanel(GameMenuFrame) | 978 HideUIPanel(GameMenuFrame) |
| 988 addon:OpenMainDisplayToTab"Options" | 979 addon:OpenMainDisplayToTab"Options" |
| 989 end) | 980 end) |
| 990 button:SetText('"/ouroloot opt"') | 981 button:SetText('"/ouroloot opt"') |
| 991 button:SetPoint("TOPLEFT",20,-20) | 982 button:SetPoint("TOPLEFT",20,-20) |
| 992 _b:SetScript("OnShow",nil) | 983 _b:SetScript("OnShow",nil) |
| 993 end) | 984 end) |
| 994 _G.InterfaceOptions_AddCategory(bliz) | 985 InterfaceOptions_AddCategory(bliz) |
| 995 | 986 |
| 996 -- Maybe load up g_uniques now? | 987 -- Maybe load up g_uniques now? |
| 997 if opts.precache_history_uniques then | 988 if opts.precache_history_uniques then |
| 998 self:_cache_history_uniques() | 989 self:_cache_history_uniques() |
| 999 end | 990 end |
| 1153 -- etc. So firing a callback is delayed ever so briefly by human scales. | 1144 -- etc. So firing a callback is delayed ever so briefly by human scales. |
| 1154 -- | 1145 -- |
| 1155 -- For data safety, we replace any table arguments with read-only proxies | 1146 -- For data safety, we replace any table arguments with read-only proxies |
| 1156 -- before passing them to the callbacks. The goal is to prevent accidents, | 1147 -- before passing them to the callbacks. The goal is to prevent accidents, |
| 1157 -- not fraud. | 1148 -- not fraud. |
| 1158 local unpack, setmetatable = _G.unpack, _G.setmetatable | 1149 local unpack, setmetatable = unpack, setmetatable |
| 1159 local mtnewindex = function() --[[local]]error("This table is read-only", 3) end | 1150 local mtnewindex = function() --[[local]]error("This table is read-only", 3) end |
| 1160 local function make_readonly (t) | 1151 local function make_readonly (t) |
| 1161 return setmetatable({}, { | 1152 return setmetatable({}, { |
| 1162 __newindex = mtnewindex, | 1153 __newindex = mtnewindex, |
| 1163 __index = t, | 1154 __index = t, |
| 1189 _G.OuroLootSV = nil | 1180 _G.OuroLootSV = nil |
| 1190 _G.OuroLootSV_saved = nil | 1181 _G.OuroLootSV_saved = nil |
| 1191 _G.OuroLootOptsDB = nil | 1182 _G.OuroLootOptsDB = nil |
| 1192 _G.OuroLootSV_hist = nil | 1183 _G.OuroLootSV_hist = nil |
| 1193 _G.OuroLootSV_log = nil | 1184 _G.OuroLootSV_log = nil |
| 1194 _G.ReloadUI() | 1185 ReloadUI() |
| 1195 end | 1186 end |
| 1196 function addon:PLAYER_LOGOUT() | 1187 function addon:PLAYER_LOGOUT() |
| 1197 self:UnregisterEvent(RAID_ROSTER_UPDATE_EVENT) | 1188 self:UnregisterEvent(RAID_ROSTER_UPDATE_EVENT) |
| 1198 self:UnregisterEvent("PLAYER_ENTERING_WORLD") | 1189 self:UnregisterEvent("PLAYER_ENTERING_WORLD") |
| 1199 | 1190 |
| 1200 local worth_saving = #g_loot > 0 or _G.next(g_loot.raiders) | 1191 local worth_saving = #g_loot > 0 or next(g_loot.raiders) |
| 1201 if not worth_saving then for text in self:registered_textgen_iter() do | 1192 if not worth_saving then for text in self:registered_textgen_iter() do |
| 1202 worth_saving = worth_saving or g_loot.printed[text] > 0 | 1193 worth_saving = worth_saving or g_loot.printed[text] > 0 |
| 1203 end end | 1194 end end |
| 1204 if worth_saving then | 1195 if worth_saving then |
| 1205 opts.autoshard = self.sharder | 1196 opts.autoshard = self.sharder |
| 1413 if not g_unique_replace then _setup_unique_replace() end | 1404 if not g_unique_replace then _setup_unique_replace() end |
| 1414 g_unique_replace.new_entry (g_unique_replace.me, existing, replace, 'improv') | 1405 g_unique_replace.new_entry (g_unique_replace.me, existing, replace, 'improv') |
| 1415 addon:vbroadcast('improv', g_unique_replace.me, existing, replace) | 1406 addon:vbroadcast('improv', g_unique_replace.me, existing, replace) |
| 1416 end | 1407 end |
| 1417 | 1408 |
| 1418 local random = _G.math.random | 1409 local random = math.random |
| 1419 local function _many_uniques_handle_it (u, prefix) | 1410 local function _many_uniques_handle_it (u, prefix) |
| 1420 if u then | 1411 if u then |
| 1421 -- Check and alert for an existing value. | 1412 -- Check and alert for an existing value. |
| 1422 u = tostring(u) | 1413 u = tostring(u) |
| 1423 if g_uniques[u].history ~= g_uniques.NOTFOUND then | 1414 if g_uniques[u].history ~= g_uniques.NOTFOUND then |
| 1493 wipe(candidates) | 1484 wipe(candidates) |
| 1494 wipe(sigmap) | 1485 wipe(sigmap) |
| 1495 end | 1486 end |
| 1496 local recent_loot = create_new_cache ('loot', comm_cleanup_ttl+3, prefer_local_loots) | 1487 local recent_loot = create_new_cache ('loot', comm_cleanup_ttl+3, prefer_local_loots) |
| 1497 | 1488 |
| 1498 local strsplit, GetItemInfo, GetItemIcon, UnitClass = | 1489 local strsplit, GetItemInfo, GetItemIcon, UnitClass = strsplit, GetItemInfo, GetItemIcon, UnitClass |
| 1499 _G.strsplit, _G.GetItemInfo, _G.GetItemIcon, _G.UnitClass | |
| 1500 | 1490 |
| 1501 -- 'from' only present if this is triggered by a broadcast | 1491 -- 'from' only present if this is triggered by a broadcast |
| 1502 function _do_loot (self, local_override, recipient, unique, itemid, count, from, extratext) | 1492 function _do_loot (self, local_override, recipient, unique, itemid, count, from, extratext) |
| 1503 local prefix = "_do_loot[" .. counter() .. "]" | 1493 local prefix = "_do_loot[" .. counter() .. "]" |
| 1504 local itexture = GetItemIcon(itemid) | 1494 local itexture = GetItemIcon(itemid) |
| 1745 end | 1735 end |
| 1746 self:Print "Baron Steamroller has been slain. Congratulations on your rug." | 1736 self:Print "Baron Steamroller has been slain. Congratulations on your rug." |
| 1747 | 1737 |
| 1748 elseif cmd == "debug" then | 1738 elseif cmd == "debug" then |
| 1749 if arg then | 1739 if arg then |
| 1750 self.is_guilded = _G.IsInGuild() | 1740 self.is_guilded = IsInGuild() |
| 1751 self.debug[arg] = not self.debug[arg] | 1741 self.debug[arg] = not self.debug[arg] |
| 1752 _G.print(arg,self.debug[arg]) | 1742 print(arg,self.debug[arg]) |
| 1753 if self.debug[arg] then self.DEBUG_PRINT = true end | 1743 if self.debug[arg] then self.DEBUG_PRINT = true end |
| 1754 else | 1744 else |
| 1755 self.DEBUG_PRINT = not self.DEBUG_PRINT | 1745 self.DEBUG_PRINT = not self.DEBUG_PRINT |
| 1756 end | 1746 end |
| 1757 | 1747 |
| 1881 self.dprint('flow', "Clear: display visible but eoiST not set??") | 1871 self.dprint('flow', "Clear: display visible but eoiST not set??") |
| 1882 end | 1872 end |
| 1883 self.display:Hide() | 1873 self.display:Hide() |
| 1884 end | 1874 end |
| 1885 g_restore_p = nil | 1875 g_restore_p = nil |
| 1886 _G.OuroLootSV = nil | 1876 OuroLootSV = nil |
| 1887 self:_reset_timestamps() | 1877 self:_reset_timestamps() |
| 1888 if verbose_p then | 1878 if verbose_p then |
| 1889 if (_G.OuroLootSV_saved and #_G.OuroLootSV_saved>0) then | 1879 if (OuroLootSV_saved and #OuroLootSV_saved>0) then |
| 1890 self:Print("Current loot data cleared, %d saved sets remaining.", #_G.OuroLootSV_saved) | 1880 self:Print("Current loot data cleared, %d saved sets remaining.", #OuroLootSV_saved) |
| 1891 else | 1881 else |
| 1892 self:Print("Current loot data cleared.") | 1882 self:Print("Current loot data cleared.") |
| 1893 end | 1883 end |
| 1894 end | 1884 end |
| 1895 _init(self,st) | 1885 _init(self,st) |
| 1907 -- 1) logging happens, followed by reload or logout/login | 1897 -- 1) logging happens, followed by reload or logout/login |
| 1908 -- 2) _log points to SV_log | 1898 -- 2) _log points to SV_log |
| 1909 -- 3) VARIABLES_LOADED replaces SV_log pointer with restored version | 1899 -- 3) VARIABLES_LOADED replaces SV_log pointer with restored version |
| 1910 -- 4) logging happens to _log table (now with no other references) | 1900 -- 4) logging happens to _log table (now with no other references) |
| 1911 -- 5) at logout, nothing new has been entered in the table being saved | 1901 -- 5) at logout, nothing new has been entered in the table being saved |
| 1912 local date = _G.date | 1902 local date = date |
| 1913 function addon:log_with_timestamp (msg) | 1903 function addon:log_with_timestamp (msg) |
| 1914 tinsert (_log, date('%m/%d %H:%M:%S ')..msg) | 1904 tinsert (_log, date('%m/%d %H:%M:%S ')..msg) |
| 1915 end | 1905 end |
| 1916 end | 1906 end |
| 1917 | 1907 |
| 1937 local change_chatframe | 1927 local change_chatframe |
| 1938 | 1928 |
| 1939 function addon:_set_chatty_change_chatframe (arg, silent_p) | 1929 function addon:_set_chatty_change_chatframe (arg, silent_p) |
| 1940 local frame | 1930 local frame |
| 1941 if type(arg) == 'number' then | 1931 if type(arg) == 'number' then |
| 1942 arg = _G.math.min (arg, _G.NUM_CHAT_WINDOWS) | 1932 arg = math.min (arg, _G.NUM_CHAT_WINDOWS) |
| 1943 frame = _G['ChatFrame'..arg] | 1933 frame = _G['ChatFrame'..arg] |
| 1944 elseif type(arg) == 'string' then | 1934 elseif type(arg) == 'string' then |
| 1945 frame = _G[arg] | 1935 frame = _G[arg] |
| 1946 end | 1936 end |
| 1947 if type(frame) == 'table' and type(frame.AddMessage) == 'function' then | 1937 if type(frame) == 'table' and type(frame.AddMessage) == 'function' then |
| 2015 local byindex, temp = {}, {} | 2005 local byindex, temp = {}, {} |
| 2016 local function sort (src, dest) | 2006 local function sort (src, dest) |
| 2017 for k in pairs(src) do | 2007 for k in pairs(src) do |
| 2018 temp[#temp+1] = k | 2008 temp[#temp+1] = k |
| 2019 end | 2009 end |
| 2020 _G.table.sort(temp) | 2010 table.sort(temp) |
| 2021 wipe(dest) | 2011 wipe(dest) |
| 2022 for i = 1, #temp do | 2012 for i = 1, #temp do |
| 2023 dest[i] = src[temp[i]] | 2013 dest[i] = src[temp[i]] |
| 2024 end | 2014 end |
| 2025 end | 2015 end |
| 2095 if not closest_boss then | 2085 if not closest_boss then |
| 2096 fencepost = closest_time | 2086 fencepost = closest_time |
| 2097 elseif not closest_time then | 2087 elseif not closest_time then |
| 2098 fencepost = closest_boss | 2088 fencepost = closest_boss |
| 2099 else | 2089 else |
| 2100 fencepost = _G.math.min(closest_time,closest_boss) | 2090 fencepost = math.min(closest_time,closest_boss) |
| 2101 end | 2091 end |
| 2102 end | 2092 end |
| 2103 return fencepost | 2093 return fencepost |
| 2104 end | 2094 end |
| 2105 | 2095 |
| 2189 do | 2179 do |
| 2190 function addon:snapshot_raid (only_inraid_p) | 2180 function addon:snapshot_raid (only_inraid_p) |
| 2191 local ss = CopyTable(g_loot.raiders) | 2181 local ss = CopyTable(g_loot.raiders) |
| 2192 local instance,maxsize = instance_tag() | 2182 local instance,maxsize = instance_tag() |
| 2193 if only_inraid_p then | 2183 if only_inraid_p then |
| 2194 for name,info in _G.next, ss do | 2184 for name,info in next, ss do |
| 2195 if info.online == 3 then | 2185 if info.online == 3 then |
| 2196 ss[name] = nil | 2186 ss[name] = nil |
| 2197 end | 2187 end |
| 2198 end | 2188 end |
| 2199 end | 2189 end |
| 2200 return ss, maxsize, instance, _G.time() | 2190 return ss, maxsize, instance, time() |
| 2201 end | 2191 end |
| 2202 end | 2192 end |
| 2203 | 2193 |
| 2204 -- Tie-in with Deadly Boss Mods (or other such addons) | 2194 -- Tie-in with Deadly Boss Mods (or other such addons) |
| 2205 do | 2195 do |
| 2382 end | 2372 end |
| 2383 end | 2373 end |
| 2384 | 2374 |
| 2385 -- Adding entries to the loot record, and tracking the corresponding timestamp. | 2375 -- Adding entries to the loot record, and tracking the corresponding timestamp. |
| 2386 do | 2376 do |
| 2387 local rawget, setmetatable = _G.rawget, _G.setmetatable | 2377 local rawget, setmetatable = rawget, setmetatable |
| 2388 | 2378 |
| 2389 --@debug@ | 2379 --@debug@ |
| 2390 local tos = {} | 2380 local tos = {} |
| 2391 tos.time = function (e) | 2381 tos.time = function (e) |
| 2392 return e.startday.text | 2382 return e.startday.text |
| 2498 function addon._addLootEntry (e) | 2488 function addon._addLootEntry (e) |
| 2499 setmetatable(e,loot_entry_mt) | 2489 setmetatable(e,loot_entry_mt) |
| 2500 | 2490 |
| 2501 if not done_todays_date then do_todays_date() end | 2491 if not done_todays_date then do_todays_date() end |
| 2502 | 2492 |
| 2503 local h, m = _G.GetGameTime() | 2493 local h, m = GetGameTime() |
| 2504 --local localuptime = math.floor(GetTime()) | 2494 --local localuptime = math.floor(GetTime()) |
| 2505 local time_t = _G.time() | 2495 local time_t = time() |
| 2506 e.hour = h | 2496 e.hour = h |
| 2507 e.minute = m | 2497 e.minute = m |
| 2508 e.stamp = time_t --localuptime | 2498 e.stamp = time_t --localuptime |
| 2509 if e.kind == 'loot' then | 2499 if e.kind == 'loot' then |
| 2510 if (not e.unique) or (#e.unique==0) then | 2500 if (not e.unique) or (#e.unique==0) then |
| 2511 e.unique = e.id .. (e.disposition or e.person) .. _G.date("%Y/%m/%d %H:%M",e.stamp) | 2501 e.unique = e.id .. (e.disposition or e.person) .. date("%Y/%m/%d %H:%M",e.stamp) |
| 2512 end | 2502 end |
| 2513 addon:Fire ('NewLootEntry', e) | 2503 addon:Fire ('NewLootEntry', e) |
| 2514 end | 2504 end |
| 2515 local index = #g_loot + 1 | 2505 local index = #g_loot + 1 |
| 2516 g_loot[index] = e | 2506 g_loot[index] = e |
| 2721 end | 2711 end |
| 2722 | 2712 |
| 2723 function _setup_unique_replace () | 2713 function _setup_unique_replace () |
| 2724 gur = {} | 2714 gur = {} |
| 2725 gur.cache = create_new_cache ('improv', 10, fixup_unique_replacements) | 2715 gur.cache = create_new_cache ('improv', 10, fixup_unique_replacements) |
| 2726 gur.me = tonumber(_G.UnitGUID('player'):sub(-7),16) | 2716 gur.me = tonumber(UnitGUID('player'):sub(-7),16) |
| 2727 gur.replacements = {} | 2717 gur.replacements = {} |
| 2728 gur.new_entry = new_entry | 2718 gur.new_entry = new_entry |
| 2729 gur.get_previous_replacement = get_previous_replacement | 2719 gur.get_previous_replacement = get_previous_replacement |
| 2730 g_unique_replace = gur | 2720 g_unique_replace = gur |
| 2731 _setup_unique_replace = nil | 2721 _setup_unique_replace = nil |
| 2757 clicky = addon.format_hypertext( | 2747 clicky = addon.format_hypertext( |
| 2758 [[ SYSTEM FAILURE -- RELEASE RINZLER ]], "|cffff0000", | 2748 [[ SYSTEM FAILURE -- RELEASE RINZLER ]], "|cffff0000", |
| 2759 function() StaticPopup_Show "OUROL_ARGH" end) | 2749 function() StaticPopup_Show "OUROL_ARGH" end) |
| 2760 end | 2750 end |
| 2761 StaticPopupDialogs["OUROL_ARGH"].text = horrible_error_text:format(err_msg) | 2751 StaticPopupDialogs["OUROL_ARGH"].text = horrible_error_text:format(err_msg) |
| 2762 _G.PlaySoundFile ([[Interface\AddOns\Ouro_Loot\sfrr.ogg]], "Master") | 2752 PlaySoundFile ([[Interface\AddOns\Ouro_Loot\sfrr.ogg]], "Master") |
| 2763 addon:Print (" ") | 2753 addon:Print (" ") |
| 2764 addon:Print (" ", clicky) | 2754 addon:Print (" ", clicky) |
| 2765 addon:Print (" ") | 2755 addon:Print (" ") |
| 2766 end | 2756 end |
| 2767 | 2757 |
| 2773 end | 2763 end |
| 2774 | 2764 |
| 2775 | 2765 |
| 2776 ------ Saved texts | 2766 ------ Saved texts |
| 2777 function addon:check_saved_table(silent_p) | 2767 function addon:check_saved_table(silent_p) |
| 2778 local s = _G.OuroLootSV_saved | 2768 local s = OuroLootSV_saved |
| 2779 if s and (#s > 0) then return s end | 2769 if s and (#s > 0) then return s end |
| 2780 _G.OuroLootSV_saved = nil | 2770 OuroLootSV_saved = nil |
| 2781 if not silent_p then self:Print("There are no saved loot texts.") end | 2771 if not silent_p then self:Print("There are no saved loot texts.") end |
| 2782 end | 2772 end |
| 2783 | 2773 |
| 2784 function addon:save_list() | 2774 function addon:save_list() |
| 2785 local s = self:check_saved_table(); if not s then return end | 2775 local s = self:check_saved_table(); if not s then return end |
| 2787 self:Print("#%d %s %d entries %s", i, t.date, t.count, t.name) | 2777 self:Print("#%d %s %d entries %s", i, t.date, t.count, t.name) |
| 2788 end | 2778 end |
| 2789 end | 2779 end |
| 2790 | 2780 |
| 2791 function addon:save_saveas(name) | 2781 function addon:save_saveas(name) |
| 2792 _G.OuroLootSV_saved = _G.OuroLootSV_saved or {} | 2782 OuroLootSV_saved = OuroLootSV_saved or {} |
| 2793 local SV = _G.OuroLootSV_saved | 2783 local SV = OuroLootSV_saved |
| 2794 local n = #SV + 1 | 2784 local n = #SV + 1 |
| 2795 local save = { | 2785 local save = { |
| 2796 name = name, | 2786 name = name, |
| 2797 date = makedate(), | 2787 date = makedate(), |
| 2798 count = #g_loot, | 2788 count = #g_loot, |
| 2874 local new_uniques, uniques_bywhen, when_array = {}, {}, {} | 2864 local new_uniques, uniques_bywhen, when_array = {}, {}, {} |
| 2875 for u,tstamp in pairs(p.when) do | 2865 for u,tstamp in pairs(p.when) do |
| 2876 uniques_bywhen[tstamp] = u | 2866 uniques_bywhen[tstamp] = u |
| 2877 when_array[#when_array+1] = tstamp | 2867 when_array[#when_array+1] = tstamp |
| 2878 end | 2868 end |
| 2879 _G.table.sort (when_array, compare_timestamps) | 2869 table.sort (when_array, compare_timestamps) |
| 2880 for i,tstamp in ipairs(when_array) do | 2870 for i,tstamp in ipairs(when_array) do |
| 2881 new_uniques[i] = uniques_bywhen[tstamp] | 2871 new_uniques[i] = uniques_bywhen[tstamp] |
| 2882 end | 2872 end |
| 2883 p.unique = new_uniques | 2873 p.unique = new_uniques |
| 2884 end | 2874 end |
| 2966 count = count + 1 | 2956 count = count + 1 |
| 2967 end | 2957 end |
| 2968 end | 2958 end |
| 2969 for i,e in self:filtered_loot_iter('loot') do | 2959 for i,e in self:filtered_loot_iter('loot') do |
| 2970 if e.unique and e.unique ~= "" then | 2960 if e.unique and e.unique ~= "" then |
| 2971 local hmmm = _G.rawget(g_uniques,e.unique) | 2961 local hmmm = rawget(g_uniques,e.unique) |
| 2972 if hmmm then | 2962 if hmmm then |
| 2973 hmmm.loot = i | 2963 hmmm.loot = i |
| 2974 elseif e.disposition == 'shard' or e.disposition == 'gvault' then | 2964 elseif e.disposition == 'shard' or e.disposition == 'gvault' then |
| 2975 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND } | 2965 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND } |
| 2976 count = count + 1 | 2966 count = count + 1 |
| 3272 -- Blessed be the lookup cache of the loot master. | 3262 -- Blessed be the lookup cache of the loot master. |
| 3273 g_uniques[U] = { loot = index, history = to_name } | 3263 g_uniques[U] = { loot = index, history = to_name } |
| 3274 end | 3264 end |
| 3275 local from_person_class = e.person_class or from_h.person_class | 3265 local from_person_class = e.person_class or from_h.person_class |
| 3276 or (g_loot.raiders[from_name] and g_loot.raiders[from_name].class) | 3266 or (g_loot.raiders[from_name] and g_loot.raiders[from_name].class) |
| 3277 or select(2,_G.UnitClass(from_name)) | 3267 or select(2,UnitClass(from_name)) |
| 3278 e.person = to_name | 3268 e.person = to_name |
| 3279 e.person_class = to_h.person_class | 3269 e.person_class = to_h.person_class |
| 3280 or (g_loot.raiders[to_name] and g_loot.raiders[to_name].class) | 3270 or (g_loot.raiders[to_name] and g_loot.raiders[to_name].class) |
| 3281 or select(2,_G.UnitClass(to_name)) | 3271 or select(2,UnitClass(to_name)) |
| 3282 self.hist_clean = nil | 3272 self.hist_clean = nil |
| 3283 self.loot_clean = nil | 3273 self.loot_clean = nil |
| 3284 | 3274 |
| 3285 if how == "local" then | 3275 if how == "local" then |
| 3286 if opts.chatty_on_local_changes then | 3276 if opts.chatty_on_local_changes then |
