comparison 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
comparison
equal deleted inserted replaced
100:a57133ee3c9b 101:f7162a1cadc7
132 ['forum_current'] = '[item] by name', 132 ['forum_current'] = '[item] by name',
133 ['display_disabled_LODs'] = false, 133 ['display_disabled_LODs'] = false,
134 ['display_bcast_from'] = true, 134 ['display_bcast_from'] = true,
135 ['precache_history_uniques'] = false, 135 ['precache_history_uniques'] = false,
136 ['chatty_on_remote_changes'] = false, 136 ['chatty_on_remote_changes'] = false,
137 ['chatty_on_remote_changes_frame'] = 1, 137 ['chatty_on_local_changes'] = false,
138 ['chatty_on_changes_frame'] = 1,
138 ['itemfilter'] = {}, 139 ['itemfilter'] = {},
139 ['itemvault'] = {}, 140 ['itemvault'] = {},
140 } } 141 } }
141 local virgin = "First time loaded? Hi! Use the /ouroloot command" 142 local virgin = "First time loaded? Hi! Use the /ouroloot command"
142 .." to show the main display. You should probably browse the instructions" 143 .." to show the main display. You should probably browse the instructions"
390 local GetNumRaidMembers = _G.GetNumGroupMembers or _G.GetNumRaidMembers 391 local GetNumRaidMembers = _G.GetNumGroupMembers or _G.GetNumRaidMembers
391 local IsInRaid = _G.IsInRaid or (function() return GetNumRaidMembers() > 0 end) 392 local IsInRaid = _G.IsInRaid or (function() return GetNumRaidMembers() > 0 end)
392 -- En masse forward decls of symbols defined inside local blocks 393 -- En masse forward decls of symbols defined inside local blocks
393 local _register_bossmod, makedate, create_new_cache, _init, _log, _do_loot_metas 394 local _register_bossmod, makedate, create_new_cache, _init, _log, _do_loot_metas
394 local _history_by_loot_id, _setup_unique_replace, _unavoidable_collision 395 local _history_by_loot_id, _setup_unique_replace, _unavoidable_collision
395 local _notify_about_change, _notify_about_remote 396 local _notify_about_change
396 397
397 -- Try to extract numbers from the .toc "Version" and munge them into an 398 -- Try to extract numbers from the .toc "Version" and munge them into an
398 -- integral form for comparison. The result doesn't need to be meaningful as 399 -- integral form for comparison. The result doesn't need to be meaningful as
399 -- long as we can reliably feed two of them to "<" and get useful answers. 400 -- long as we can reliably feed two of them to "<" and get useful answers.
400 -- 401 --
955 self:_cache_history_uniques() 956 self:_cache_history_uniques()
956 end 957 end
957 958
958 self:_scan_LOD_modules() 959 self:_scan_LOD_modules()
959 960
960 self:_set_remote_change_chatframe (opts.chatty_on_remote_changes_frame, --[[silent_p=]]true) 961 self:_set_chatty_change_chatframe (opts.chatty_on_changes_frame, --[[silent_p=]]true)
961 962
962 if self.debug.flow then self:Print"is in control-flow debug mode." end 963 if self.debug.flow then self:Print"is in control-flow debug mode." end
963 end 964 end
964 --function addon:OnDisable() end 965 --function addon:OnDisable() end
965 966
1056 -- after the interesting event: cleanups/fixups, improvs from network, etc. 1057 -- after the interesting event: cleanups/fixups, improvs from network, etc.
1057 -- So firing a callback is delayed ever so briefly by human standards. 1058 -- So firing a callback is delayed ever so briefly by human standards.
1058 -- 1059 --
1059 -- Can't *quite* use the expiring caches for this, but that's okay. 1060 -- Can't *quite* use the expiring caches for this, but that's okay.
1060 do 1061 do
1062 local mtnewindex = function() error("This table is read-only", 3) end
1063 local function make_readonly (t)
1064 return _G.setmetatable({}, {
1065 __newindex = mtnewindex,
1066 __index = t,
1067 __metatable = false,
1068 })
1069 end
1070
1061 local unpack = _G.unpack 1071 local unpack = _G.unpack
1062 local function F (t) 1072 local function F (t)
1063 addon.callbacks:Fire (unpack(t)) 1073 addon.callbacks:Fire (unpack(t))
1064 flib.del(t) 1074 flib.del(t)
1065 end 1075 end
1066 function addon:Fire (...) 1076 function addon:Fire (...)
1067 self.dprint('callback', ...) 1077 self.dprint('callback', ...)
1068 local capture = flib.new(...) 1078 local capture = flib.new(...)
1079 for k,v in ipairs(capture) do if type(v) == 'table' then
1080 capture[k] = make_readonly(v)
1081 end end
1069 self:ScheduleTimer (F, 1.2, capture) 1082 self:ScheduleTimer (F, 1.2, capture)
1070 end 1083 end
1071 end 1084 end
1072 1085
1073 1086
1814 end 1827 end
1815 end 1828 end
1816 1829
1817 -- Routines for printing changes made by remote users. 1830 -- Routines for printing changes made by remote users.
1818 do 1831 do
1819 local remote_change_chatframe 1832 local change_chatframe
1820 1833
1821 function addon:_set_remote_change_chatframe (arg, silent_p) 1834 function addon:_set_chatty_change_chatframe (arg, silent_p)
1822 local frame 1835 local frame
1823 if type(arg) == 'number' then 1836 if type(arg) == 'number' then
1824 arg = _G.math.min (arg, _G.NUM_CHAT_WINDOWS) 1837 arg = _G.math.min (arg, _G.NUM_CHAT_WINDOWS)
1825 frame = _G['ChatFrame'..arg] 1838 frame = _G['ChatFrame'..arg]
1826 elseif type(arg) == 'string' then 1839 elseif type(arg) == 'string' then
1827 frame = _G[arg] 1840 frame = _G[arg]
1828 end 1841 end
1829 if type(frame) == 'table' and type(frame.AddMessage) == 'function' then 1842 if type(frame) == 'table' and type(frame.AddMessage) == 'function' then
1830 remote_change_chatframe = frame 1843 change_chatframe = frame
1831 if not silent_p then 1844 if not silent_p then
1832 local msg = "Now printing to chat frame " .. arg 1845 local msg = "Now printing to chat frame " .. arg
1833 if frame.GetName then 1846 if frame.GetName then
1834 msg = msg .. " (" .. tostring(frame:GetName()) .. ")" 1847 msg = msg .. " (" .. tostring(frame:GetName()) .. ")"
1835 end 1848 end
1842 else 1855 else
1843 self:Print("'%s' was not a valid chat frame number/name, no change has been made.", arg) 1856 self:Print("'%s' was not a valid chat frame number/name, no change has been made.", arg)
1844 end 1857 end
1845 end 1858 end
1846 1859
1847 function _notify_about_change (chatframe, source, index, olddisp, from_whom, from_class) 1860 local function _notify (chatframe, source, index, olddisp, from_whom, from_class)
1848 local e = g_loot[index] 1861 local e = g_loot[index]
1849 if not e then 1862 if not e then
1850 -- how did this happen? 1863 -- how did this happen?
1851 return 1864 return
1852 end 1865 end
1884 e.itemlink, from_text, to_text) 1897 e.itemlink, from_text, to_text)
1885 addon:CFPrint (chatframe, remote_chatty, source, index, 1898 addon:CFPrint (chatframe, remote_chatty, source, index,
1886 e.itemlink, from_text, to_text) 1899 e.itemlink, from_text, to_text)
1887 end 1900 end
1888 1901
1889 function _notify_about_remote (sender, index, olddisp, from_whom, from_class) 1902 function _notify_about_change (sender, index, olddisp, from_whom, from_class)
1890 _notify_about_change (remote_change_chatframe, sender, index, olddisp, from_whom, from_class) 1903 _notify (change_chatframe, sender, index, olddisp, from_whom, from_class)
1891 end 1904 end
1892 end 1905 end
1893 1906
1894 -- Adds indices to traverse the tables in a nice sorted order. 1907 -- Adds indices to traverse the tables in a nice sorted order.
1895 do 1908 do
3158 or select(2,_G.UnitClass(to_name)) 3171 or select(2,_G.UnitClass(to_name))
3159 self.hist_clean = nil 3172 self.hist_clean = nil
3160 self.loot_clean = nil 3173 self.loot_clean = nil
3161 3174
3162 if how == "local" then 3175 if how == "local" then
3163 _notify_about_change (_G.DEFAULT_CHAT_FRAME, _G.UNIT_YOU, index, 3176 if opts.chatty_on_local_changes then
3164 nil, from_name, from_person_class) 3177 _notify_about_change (_G.UNIT_YOU, index, nil, from_name, from_person_class)
3178 end
3165 self:vbroadcast('reassign', unique, id, from_name, to_name) 3179 self:vbroadcast('reassign', unique, id, from_name, to_name)
3166 elseif opts.chatty_on_remote_changes then 3180 elseif opts.chatty_on_remote_changes then
3167 _notify_about_remote (sender, index, nil, from_name, from_person_class) 3181 _notify_about_change (sender, index, nil, from_name, from_person_class)
3168 end 3182 end
3169 if self.display then 3183 if self.display then
3170 self.display:GetUserData("GUI state").eoiST:OuroLoot_Refresh(index) 3184 self.display:GetUserData("GUI state").eoiST:OuroLoot_Refresh(index)
3171 self:redisplay() 3185 self:redisplay()
3172 end 3186 end
3371 self.hist_clean = nil 3385 self.hist_clean = nil
3372 self.loot_clean = nil 3386 self.loot_clean = nil
3373 -- A unique tag has been set by this point. 3387 -- A unique tag has been set by this point.
3374 if how == "local" then 3388 if how == "local" then
3375 unique = assert(e.unique) 3389 unique = assert(e.unique)
3390 if opts.chatty_on_local_changes then
3391 _notify_about_change (_G.UNIT_YOU, index, olddisp)
3392 end
3376 self:vbroadcast('mark', unique, id, olddisp, newdisp) 3393 self:vbroadcast('mark', unique, id, olddisp, newdisp)
3377 end 3394 end
3378 self:Fire ('MarkAs', unique, id, e, olddisp or 'normal', newdisp or 'normal') 3395 self:Fire ('MarkAs', unique, id, e, olddisp or 'normal', newdisp or 'normal')
3379 return index 3396 return index
3380 end 3397 end
3465 addon.dprint('comm', "DOTmark/17, sender", sender, "unique", unique, 3482 addon.dprint('comm', "DOTmark/17, sender", sender, "unique", unique,
3466 "item", item, "from old", old, "to new", new) 3483 "item", item, "from old", old, "to new", new)
3467 local index = addon:loot_mark_disposition ("remote", sender, unique, item, old, new) 3484 local index = addon:loot_mark_disposition ("remote", sender, unique, item, old, new)
3468 --if not addon.enabled then return end -- hmm 3485 --if not addon.enabled then return end -- hmm
3469 if index and opts.chatty_on_remote_changes then 3486 if index and opts.chatty_on_remote_changes then
3470 _notify_about_remote (sender, index, old) 3487 _notify_about_change (sender, index, old)
3471 end 3488 end
3472 end 3489 end
3473 3490
3474 OCR_funcs['17reassign'] = function (sender, _, unique, item, from, to) 3491 OCR_funcs['17reassign'] = function (sender, _, unique, item, from, to)
3475 addon.dprint('comm', "DOTreassign/17, sender", sender, "unique", unique, 3492 addon.dprint('comm', "DOTreassign/17, sender", sender, "unique", unique,