Mercurial > wow > ouroloot
diff core.lua @ 87:9fea75b0927b
If deleting a history entry results in an empty player table, remove that as well. Change g_uniques to store player's name rather than index as the history field, and indirect through the byname table.
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Fri, 22 Jun 2012 00:58:59 +0000 |
parents | 703bbe61d12d |
children | c9f955f9a285 |
line wrap: on
line diff
--- a/core.lua Thu Jun 21 21:14:24 2012 +0000 +++ b/core.lua Fri Jun 22 00:58:59 2012 +0000 @@ -523,7 +523,7 @@ -- Memoizing cache of unique IDs as we generate or search for them. Keys are -- the uniques, values are the following: --- 'history' active index into self.history +-- 'history' active player name in self.history -- 'history_may' index into player's uniques list, CAN QUICKLY BE OUTDATED -- and will instantly be wrong after manual insertion -- 'loot' active index into g_loot @@ -555,7 +555,7 @@ local hi,h = addon:get_loot_history (loot.person) for ui,u in ipairs(h.unique) do if k == u then - H, HU = hi, ui + H, HU = h.name, ui break end end @@ -565,7 +565,7 @@ for hi,h in ipairs(addon.history) do for ui,u in ipairs(h.unique) do if k == u then - H, HU = hi, ui + H, HU = h.name, ui break end end @@ -1326,8 +1326,8 @@ end addon.dprint('loot',"verified unique tag ("..u..")") else - -- Need to *find* an unused value. For now use a range of - -- J*10^4 where J is Jenny's Constant. Thank you, xkcd.com/1047. + -- Need to *find* an unused value. For now use a range of J*10^4 + -- where J is Jenny's Constant. Thank you, <xkcd.com/1047>. prefix = prefix or 'n' repeat u = prefix .. random(8675309) @@ -2504,6 +2504,7 @@ -- History if hi ~= g_uniques.NOTFOUND then + hi = addon.history.byname[hi] local hist = addon.history[hi] if ui and hist.unique[ui] == exist then -- ui is valid @@ -2796,7 +2797,7 @@ local count = 0 for hi,player in ipairs(self.history) do for ui,u in ipairs(player.unique) do - g_uniques[u] = { history = hi, history_may = ui } + g_uniques[u] = { history = player.name, history_may = ui } count = count + 1 end end @@ -2890,6 +2891,7 @@ local i,h = self:get_loot_history(e.person) local when = self:format_timestamp (g_today, e) + assert(h.name==e.person) -- If any of these change, update the end of history_handle_disposition. if (not e.unique) or (#e.unique==0) then @@ -2901,7 +2903,7 @@ h.id[U] = e.id h.count[U] = e.count - g_uniques[U] = { loot = lootindex, history = i } + g_uniques[U] = { loot = lootindex, history = e.person } end -- Create new history table based on current loot. @@ -2988,7 +2990,7 @@ -- Bah. Anybody that tricky is already recoding the tables directly anyhow. errtxt = "There is no record of %s ever having been assigned!" else - player_i = cache.history + player_i = addon.history.byname[cache.history] player_h = addon.history[player_i] if cache.history_may and needle == player_h.unique[cache.history_may] @@ -3082,6 +3084,7 @@ end else -- XXX do some sanity checks here? from_name == from_h.name, etc? + -- If something were wrong at this point, what could we do? local U = tremove (from_h.unique, hist_i) -- The loot master giveth... @@ -3095,7 +3098,7 @@ from_h.id[U] = nil from_h.count[U] = nil -- Blessed be the lookup cache of the loot master. - g_uniques[U] = { loot = index, history = to_i } + g_uniques[U] = { loot = index, history = to_name } end local from_person_class = e.person_class or from_h.person_class or (g_loot.raiders[from_name] and g_loot.raiders[from_name].class) @@ -3142,15 +3145,20 @@ player.when[u], player.id[u], player.count[u] = nil, nil, nil g_uniques[u] = nil addon.hist_clean = nil + return #player.unique end -- Mirror of _addHistoryEntry. Arguments are either: -- E - loot entry -- U,ITEM - unique tag, and a name/itemlink for errors - -- Returns true on success. - function addon:_delHistoryEntry (first, second) + -- If this entry was the only one for that player, will also remove that + -- player's tables from the history array. + -- + -- On success, returns the number of remaining history entries for that + -- player (potentially zero). On failure, returns nil+error. + function addon:_delHistoryEntry (first, item) if type(first) == 'table' then - second = first.itemlink or second + item = first.itemlink or item --elseif type(first) == 'string' then end @@ -3160,11 +3168,18 @@ -- from_h is the formatted error text return nil, (from_h .." Loot will be deleted, but history will NOT be updated." - ):format(second) + ):format(item) end - expunge (from_h, hist_i) - return true + local remaining = expunge (from_h, hist_i) + if not remaining then + return nil, "Something bizarre happening trying to delete "..item + elseif remaining > 0 then + return remaining + end + tremove (self.history, from_i) + self:_build_history_names() + return 0 end -- Any extra work for the "Mark as <x>" dropdown actions. The @@ -3229,7 +3244,7 @@ name_h.id[U] = e.id -- c.id name_h.count[U] = c and c.count or e.count sort_player(name_h) - g_uniques[U] = { loot = index, history = name_i } + g_uniques[U] = { loot = index, history = name } self.hist_clean = nil if c then flib.del(c) end