Mercurial > wow > ouroloot
comparison core.lua @ 109:ce45011fab4c
- Test for errors during startup before trying to manipulate data.
- Thin encapsulation around dispositions. Abstract everything except the
insertion into GUI dropdowns (that comes next).
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Wed, 08 Aug 2012 14:43:26 -0400 |
parents | 04ccd12c2a41 |
children | f93c1a93923b |
comparison
equal
deleted
inserted
replaced
108:04ccd12c2a41 | 109:ce45011fab4c |
---|---|
62 - variant 1 = heroic item, 2 = LFR item; missing otherwise | 62 - variant 1 = heroic item, 2 = LFR item; missing otherwise |
63 - cache_miss if GetItemInfo failed; SHOULD be missing (changes other fields) | 63 - cache_miss if GetItemInfo failed; SHOULD be missing (changes other fields) |
64 - bcast_from player's name if received rebroadcast from that player; | 64 - bcast_from player's name if received rebroadcast from that player; |
65 missing otherwise; can be deleted as a result of in-game | 65 missing otherwise; can be deleted as a result of in-game |
66 fiddling of loot data | 66 fiddling of loot data |
67 - extratext text in Note column, including disposition and rebroadcasting | 67 - extratext text in Note column, including disposition and rebroadcasting; |
68 missing otherwise | |
68 - extratext_byhand true if text edited by player directly; missing otherwise | 69 - extratext_byhand true if text edited by player directly; missing otherwise |
69 | 70 |
70 | 71 |
71 Functions arranged like this, with these lables (for jumping to). As a | 72 Functions arranged like this, with these lables (for jumping to). As a |
72 rule, member functions with UpperCamelCase names are called directly by | 73 rule, member functions with UpperCamelCase names are called directly by |
258 end | 259 end |
259 function assert(cond,msg,...) | 260 function assert(cond,msg,...) |
260 if cond then | 261 if cond then |
261 return cond,msg,... | 262 return cond,msg,... |
262 else | 263 else |
263 error('ASSERT() FAILED: '..tostring(msg or 'nil')) | 264 error('ASSERT() FAILED: '.._G.tostring(msg or 'nil'),3) |
264 end | 265 end |
265 end | 266 end |
266 | 267 |
267 enabled = false | 268 enabled = false |
268 rebroadcast = false | 269 rebroadcast = false |
306 self:Printf([[|cffff1010ERROR:|r <|cff00ff00%s|r> Ouro Loot cannot finish loading. You will need to type |cff30adff%s|r once these problems are resolved, and try again.]], msg, _G.SLASH_RELOAD1) | 307 self:Printf([[|cffff1010ERROR:|r <|cff00ff00%s|r> Ouro Loot cannot finish loading. You will need to type |cff30adff%s|r once these problems are resolved, and try again.]], msg, _G.SLASH_RELOAD1) |
307 SLASH_ACECONSOLE_OUROLOOT1 = nil | 308 SLASH_ACECONSOLE_OUROLOOT1 = nil |
308 SLASH_ACECONSOLE_OUROLOOT2 = nil | 309 SLASH_ACECONSOLE_OUROLOOT2 = nil |
309 self.error (msg, --[[level=]]2) | 310 self.error (msg, --[[level=]]2) |
310 end | 311 end |
312 addon.FILES_LOADED = 0 | |
311 | 313 |
312 -- Seriously? ORLY? | 314 -- Seriously? ORLY? |
313 -- YARLY. Go ahead and guess what was involved in tracking this down. If | 315 -- YARLY. Go ahead and guess what was involved in tracking this down. If |
314 -- more such effects are added in the future, the "id==xxxxx" will need to | 316 -- more such effects are added in the future, the "id==xxxxx" will need to |
315 -- change into a probe of a table of known-problematic IDs. | 317 -- change into a probe of a table of known-problematic IDs. |
722 function addon:OnInitialize() | 724 function addon:OnInitialize() |
723 if self.author_debug then | 725 if self.author_debug then |
724 _G.OL = self | 726 _G.OL = self |
725 _G.g_uniques = g_uniques | 727 _G.g_uniques = g_uniques |
726 end | 728 end |
729 -- This kludgy-looking thing is because if there are serious errors in | |
730 -- loading, some of the actions during PLAYER_LOGOUT can destroy data. | |
731 if self.FILES_LOADED ~= 7 then | |
732 print('|cffaee3ffouroloot reports load count of',self.FILES_LOADED,'fml|r') | |
733 self:SetEnabledState(false) | |
734 return | |
735 end | |
736 self.FILES_LOADED = nil | |
737 | |
727 _log = OuroLootSV_log | 738 _log = OuroLootSV_log |
728 | 739 |
729 -- VARIABLES_LOADED has fired by this point; test if we're doing something like | 740 -- VARIABLES_LOADED has fired by this point; test if we're doing something like |
730 -- relogging during a raid and already have collected loot data | 741 -- relogging during a raid and already have collected loot data |
731 local OuroLootSV = OuroLootSV | 742 local OuroLootSV = OuroLootSV |
1464 if loot then | 1475 if loot then |
1465 maybe_trash_kill_entry() -- Generate *some* kind of boss/location entry | 1476 maybe_trash_kill_entry() -- Generate *some* kind of boss/location entry |
1466 candidates[sig] = nil | 1477 candidates[sig] = nil |
1467 local looti = addon._addLootEntry(loot) | 1478 local looti = addon._addLootEntry(loot) |
1468 addon.dprint('loot', "entry", i, "was found, added at index", looti) | 1479 addon.dprint('loot', "entry", i, "was found, added at index", looti) |
1469 if (loot.disposition ~= 'shard') | 1480 if addon:_test_disposition (loot.disposition, 'affects_history') |
1470 and (loot.disposition ~= 'gvault') | |
1471 and (not addon.history_suppress) | 1481 and (not addon.history_suppress) |
1472 then | 1482 then |
1473 addon:_addHistoryEntry(looti) | 1483 addon:_addHistoryEntry(looti) |
1474 elseif #loot.unique > 0 then | 1484 elseif #loot.unique > 0 then |
1475 g_uniques[loot.unique] = -- stub entry | 1485 g_uniques[loot.unique] = -- stub entry |
1581 i.disposition = 'shard' | 1591 i.disposition = 'shard' |
1582 end | 1592 end |
1583 if local_override then | 1593 if local_override then |
1584 -- player is adding loot by hand, don't wait for network cache timeouts | 1594 -- player is adding loot by hand, don't wait for network cache timeouts |
1585 -- keep this sync'd with prefer_local_loots above | 1595 -- keep this sync'd with prefer_local_loots above |
1586 if i.extratext == 'shard' | 1596 if i.extratext then |
1587 or i.extratext == 'gvault' | 1597 for disp,text in self:_iter_dispositions('from_notes_text') do |
1588 or i.extratext == 'offspec' | 1598 if text == i.extratext then |
1589 then | 1599 i.disposition = disp |
1590 i.disposition = i.extratext | 1600 break |
1601 end | |
1602 end | |
1591 end | 1603 end |
1592 local looti = self._addLootEntry(i) | 1604 local looti = self._addLootEntry(i) |
1593 if (i.disposition ~= 'shard') | 1605 if self:_test_disposition (i.disposition, 'affects_history') |
1594 and (i.disposition ~= 'gvault') | |
1595 and (not self.history_suppress) | 1606 and (not self.history_suppress) |
1596 then | 1607 then |
1597 self:_addHistoryEntry(looti) | 1608 self:_addHistoryEntry(looti) |
1598 else | 1609 else |
1599 g_uniques[i.unique] = -- stub entry | 1610 g_uniques[i.unique] = -- stub entry |
1982 if e.disposition then | 1993 if e.disposition then |
1983 to_text = addon.disposition_colors[e.disposition].text | 1994 to_text = addon.disposition_colors[e.disposition].text |
1984 else | 1995 else |
1985 to_text = "normal" | 1996 to_text = "normal" |
1986 end | 1997 end |
1987 to_text = addon.disposition_colors[e.disposition or "normal"].hex | 1998 to_text = addon.disposition_colors[e.disposition].hex |
1988 .. to_text .. "|r" | 1999 .. to_text .. "|r" |
1989 end | 2000 end |
1990 | 2001 |
1991 addon.dprint ('loot', "notification:", source, index, | 2002 addon.dprint ('loot', "notification:", source, index, |
1992 e.itemlink, from_text, to_text) | 2003 e.itemlink, from_text, to_text) |
2547 assert(g_loot[is].kind == 'boss') | 2558 assert(g_loot[is].kind == 'boss') |
2548 local boss = tremove (g_loot, is) | 2559 local boss = tremove (g_loot, is) |
2549 tinsert (g_loot, should_be, boss) | 2560 tinsert (g_loot, should_be, boss) |
2550 return should_be | 2561 return should_be |
2551 end | 2562 end |
2563 end | |
2564 | |
2565 -- Disposition control; more precisely, how various dispositions affect flow | |
2566 -- and displays elsewhere. | |
2567 do | |
2568 local default = { | |
2569 text = "", | |
2570 hex = "|cffffffff", | |
2571 r = 1.0, g = 1.0, b = 1.0, a = 1, | |
2572 can_reassign = true, | |
2573 affects_history = true, | |
2574 from_notes_text = false, | |
2575 } | |
2576 local mt = { | |
2577 __index = function (t,k) | |
2578 -- don't point index directly at default, need to catch nils | |
2579 return default | |
2580 end, | |
2581 } | |
2582 local alldisps = setmetatable({}, mt) | |
2583 addon.disposition_colors = setmetatable({}, mt) | |
2584 | |
2585 -- These two are clunky wrappers, probably rework this once gain some data. | |
2586 function addon:_test_disposition (code, attrib) | |
2587 return alldisps[code][attrib] | |
2588 end | |
2589 function addon:_iter_dispositions (attrib) | |
2590 local r = {} | |
2591 for code,disp in next, alldisps do | |
2592 if disp.attrib then | |
2593 r[code] = disp.text | |
2594 end | |
2595 end | |
2596 return next, r | |
2597 end | |
2598 | |
2599 function addon:_add_loot_disposition (code, rhex, ghex, bhex, text, | |
2600 can_reassign_p, do_history_p, from_notes_text_p | |
2601 ) | |
2602 assert(type(code)=='string' and #code>0) | |
2603 assert(type(text)=='string') | |
2604 assert(type(rhex)=='string') | |
2605 assert(type(bhex)=='string') | |
2606 assert(type(ghex)=='string') | |
2607 self.disposition_colors[code] = { | |
2608 text = text, | |
2609 -- for chat output by core code | |
2610 hex = "|cff" .. rhex .. ghex .. bhex, | |
2611 -- for lib-st | |
2612 r = tonumber(rhex,16)/255, | |
2613 g = tonumber(ghex,16)/255, | |
2614 b = tonumber(bhex,16)/255, | |
2615 a = 1, | |
2616 } | |
2617 -- not not = poor man's "toboolean", don't potentially hold arg | |
2618 -- objects from garbage collection | |
2619 alldisps[code] = { | |
2620 text = text, | |
2621 can_reassign = not not can_reassign_p, | |
2622 affects_history = not not do_history_p, | |
2623 from_notes_text = not not from_notes_text_p, | |
2624 } | |
2625 end | |
2626 | |
2627 -- reassign while tagged, affects history, copy from notes | |
2628 addon:_add_loot_disposition ('normal', "ff","ff","ff", "", true, true, false) | |
2629 addon:_add_loot_disposition ('offspec', "c6","9b","6d", "offspec", true, true, true) | |
2630 addon:_add_loot_disposition ('shard', "a3","35","ee", "shard", false, false, true) | |
2631 addon:_add_loot_disposition ('gvault', "33","ff","99", _G.GUILD_BANK:lower(), false, false, true) | |
2552 end | 2632 end |
2553 | 2633 |
2554 -- In the rare case of items getting put into the loot table without current | 2634 -- In the rare case of items getting put into the loot table without current |
2555 -- item cache data (which will have arrived by now). | 2635 -- item cache data (which will have arrived by now). |
2556 function addon:do_item_cache_fixup() | 2636 function addon:do_item_cache_fixup() |
2963 for i,e in self:filtered_loot_iter('loot') do | 3043 for i,e in self:filtered_loot_iter('loot') do |
2964 if e.unique and e.unique ~= "" then | 3044 if e.unique and e.unique ~= "" then |
2965 local hmmm = rawget(g_uniques,e.unique) | 3045 local hmmm = rawget(g_uniques,e.unique) |
2966 if hmmm then | 3046 if hmmm then |
2967 hmmm.loot = i | 3047 hmmm.loot = i |
2968 elseif e.disposition == 'shard' or e.disposition == 'gvault' then | 3048 elseif not self:_test_disposition (e.disposition, 'affects_history') then |
2969 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND } | 3049 g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND } |
2970 count = count + 1 | 3050 count = count + 1 |
2971 else | 3051 else |
2972 hmmm = "active data not found in history ("..i.."/"..tostring(e.unique) | 3052 hmmm = "active data not found in history ("..i.."/"..tostring(e.unique) |
2973 ..") in precache loop! trying to fixup for this session" | 3053 ..") in precache loop! trying to fixup for this session" |
3365 -- Ignore misclicks and the like | 3445 -- Ignore misclicks and the like |
3366 if olddisp == newdisp then return end | 3446 if olddisp == newdisp then return end |
3367 | 3447 |
3368 local name = e.person | 3448 local name = e.person |
3369 | 3449 |
3370 if (newdisp == 'shard' or newdisp == 'gvault') then | 3450 if not self:_test_disposition (newdisp, 'affects_history') then |
3371 local name_i, name_h, hist_i = _history_by_loot_id (e, "mark") | 3451 local name_i, name_h, hist_i = _history_by_loot_id (e, "mark") |
3372 -- remove history entry if it exists | 3452 -- remove history entry if it exists |
3373 -- FIXME revist this and use expunge | 3453 -- FIXME revist this and use expunge |
3374 if hist_i then | 3454 if hist_i then |
3375 local c = flib.new() | 3455 local c = flib.new() |
3380 deleted_cache[hist_u] = c | 3460 deleted_cache[hist_u] = c |
3381 name_h.when[hist_u] = nil | 3461 name_h.when[hist_u] = nil |
3382 name_h.id[hist_u] = nil | 3462 name_h.id[hist_u] = nil |
3383 name_h.count[hist_u] = nil | 3463 name_h.count[hist_u] = nil |
3384 self.hist_clean = nil | 3464 self.hist_clean = nil |
3385 elseif (olddisp == 'shard' or olddisp == 'gvault') then | 3465 elseif not self:_test_disposition (olddisp, 'affects_history') then |
3386 -- Sharding a vault item, or giving the auto-sharder something to bank, | 3466 -- Sharding a vault item, or giving the auto-sharder something to bank, |
3387 -- etc, wouldn't necessarily have had a history entry to begin with. | 3467 -- etc, wouldn't necessarily have had a history entry to begin with. |
3388 -- So this isn't treated as an error. | 3468 -- So this isn't treated as an error. |
3389 else | 3469 else |
3390 self:Print(name_h .. " Loot has been marked, but history will NOT be updated.", e.itemlink) | 3470 self:Print(name_h .. " Loot has been marked, but history will NOT be updated.", e.itemlink) |
3391 end | 3471 end |
3392 return | 3472 return |
3393 end | 3473 end |
3394 | 3474 |
3395 if (olddisp == 'shard' or olddisp == 'gvault') | 3475 if (not self:_test_disposition (olddisp, 'affects_history')) |
3396 and (newdisp == 'normal' or newdisp == 'offspec') | 3476 and self:_test_disposition (newdisp, 'affects_history') |
3397 then | 3477 then |
3398 local name_i, name_h = self:get_loot_history(name) | 3478 local name_i, name_h = self:get_loot_history(name) |
3399 | 3479 |
3400 -- Must create a new history entry. Could call '_addHistoryEntry(index)' | 3480 -- Must create a new history entry. Could call '_addHistoryEntry(index)' |
3401 -- but that would duplicate a lot of effort. To start with, check the | 3481 -- but that would duplicate a lot of effort. To start with, check the |
3720 self.dprint('comm', ":OCRN from", sender, "message is", msg) | 3800 self.dprint('comm', ":OCRN from", sender, "message is", msg) |
3721 return dotdotdot(sender,strsplit('\a',msg)) | 3801 return dotdotdot(sender,strsplit('\a',msg)) |
3722 end | 3802 end |
3723 end | 3803 end |
3724 | 3804 |
3805 addon.FILES_LOADED = 1 | |
3725 -- vim:noet | 3806 -- vim:noet |