Mercurial > wow > ouroloot
diff core.lua @ 101:f7162a1cadc7
Unify remote/local change notifications, and allow option toggles for each. When passing entry tables to the registered callbacks, make proxies for them first (the goal is to prevent accidents, not fraud).
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Wed, 01 Aug 2012 06:51:52 +0000 |
parents | a57133ee3c9b |
children | fe04f5c4114a |
line wrap: on
line diff
--- a/core.lua Mon Jul 30 19:25:46 2012 +0000 +++ b/core.lua Wed Aug 01 06:51:52 2012 +0000 @@ -134,7 +134,8 @@ ['display_bcast_from'] = true, ['precache_history_uniques'] = false, ['chatty_on_remote_changes'] = false, - ['chatty_on_remote_changes_frame'] = 1, + ['chatty_on_local_changes'] = false, + ['chatty_on_changes_frame'] = 1, ['itemfilter'] = {}, ['itemvault'] = {}, } } @@ -392,7 +393,7 @@ -- En masse forward decls of symbols defined inside local blocks local _register_bossmod, makedate, create_new_cache, _init, _log, _do_loot_metas local _history_by_loot_id, _setup_unique_replace, _unavoidable_collision -local _notify_about_change, _notify_about_remote +local _notify_about_change -- Try to extract numbers from the .toc "Version" and munge them into an -- integral form for comparison. The result doesn't need to be meaningful as @@ -957,7 +958,7 @@ self:_scan_LOD_modules() - self:_set_remote_change_chatframe (opts.chatty_on_remote_changes_frame, --[[silent_p=]]true) + self:_set_chatty_change_chatframe (opts.chatty_on_changes_frame, --[[silent_p=]]true) if self.debug.flow then self:Print"is in control-flow debug mode." end end @@ -1058,6 +1059,15 @@ -- -- Can't *quite* use the expiring caches for this, but that's okay. do + local mtnewindex = function() error("This table is read-only", 3) end + local function make_readonly (t) + return _G.setmetatable({}, { + __newindex = mtnewindex, + __index = t, + __metatable = false, + }) + end + local unpack = _G.unpack local function F (t) addon.callbacks:Fire (unpack(t)) @@ -1066,6 +1076,9 @@ function addon:Fire (...) self.dprint('callback', ...) local capture = flib.new(...) + for k,v in ipairs(capture) do if type(v) == 'table' then + capture[k] = make_readonly(v) + end end self:ScheduleTimer (F, 1.2, capture) end end @@ -1816,9 +1829,9 @@ -- Routines for printing changes made by remote users. do - local remote_change_chatframe - - function addon:_set_remote_change_chatframe (arg, silent_p) + local change_chatframe + + function addon:_set_chatty_change_chatframe (arg, silent_p) local frame if type(arg) == 'number' then arg = _G.math.min (arg, _G.NUM_CHAT_WINDOWS) @@ -1827,7 +1840,7 @@ frame = _G[arg] end if type(frame) == 'table' and type(frame.AddMessage) == 'function' then - remote_change_chatframe = frame + change_chatframe = frame if not silent_p then local msg = "Now printing to chat frame " .. arg if frame.GetName then @@ -1844,7 +1857,7 @@ end end - function _notify_about_change (chatframe, source, index, olddisp, from_whom, from_class) + local function _notify (chatframe, source, index, olddisp, from_whom, from_class) local e = g_loot[index] if not e then -- how did this happen? @@ -1886,8 +1899,8 @@ e.itemlink, from_text, to_text) end - function _notify_about_remote (sender, index, olddisp, from_whom, from_class) - _notify_about_change (remote_change_chatframe, sender, index, olddisp, from_whom, from_class) + function _notify_about_change (sender, index, olddisp, from_whom, from_class) + _notify (change_chatframe, sender, index, olddisp, from_whom, from_class) end end @@ -3160,11 +3173,12 @@ self.loot_clean = nil if how == "local" then - _notify_about_change (_G.DEFAULT_CHAT_FRAME, _G.UNIT_YOU, index, - nil, from_name, from_person_class) + if opts.chatty_on_local_changes then + _notify_about_change (_G.UNIT_YOU, index, nil, from_name, from_person_class) + end self:vbroadcast('reassign', unique, id, from_name, to_name) elseif opts.chatty_on_remote_changes then - _notify_about_remote (sender, index, nil, from_name, from_person_class) + _notify_about_change (sender, index, nil, from_name, from_person_class) end if self.display then self.display:GetUserData("GUI state").eoiST:OuroLoot_Refresh(index) @@ -3373,6 +3387,9 @@ -- A unique tag has been set by this point. if how == "local" then unique = assert(e.unique) + if opts.chatty_on_local_changes then + _notify_about_change (_G.UNIT_YOU, index, olddisp) + end self:vbroadcast('mark', unique, id, olddisp, newdisp) end self:Fire ('MarkAs', unique, id, e, olddisp or 'normal', newdisp or 'normal') @@ -3467,7 +3484,7 @@ local index = addon:loot_mark_disposition ("remote", sender, unique, item, old, new) --if not addon.enabled then return end -- hmm if index and opts.chatty_on_remote_changes then - _notify_about_remote (sender, index, old) + _notify_about_change (sender, index, old) end end