diff core.lua @ 84:c87bf3e756f3

Properly handle dropdown menus for the History tab now, initially with delete-item and delete-player entries. Some code cleanup and notes for future work.
author Farmbuyer of US-Kilrogg <farmbuyer@gmail.com>
date Thu, 21 Jun 2012 02:17:26 +0000
parents 940e53dd18c3
children 4771ee8eaa81
line wrap: on
line diff
--- a/core.lua	Mon Jun 18 03:02:10 2012 +0000
+++ b/core.lua	Thu Jun 21 02:17:26 2012 +0000
@@ -820,7 +820,7 @@
 						e.unique, e.history_unique = e.history_unique, nil
 					end
 					if e.unique == nil or #e.unique == 0 then
-						e.unique = e.id .. ' ' .. date("%Y/%m/%d %H:%M",e.stamp)
+						e.unique = e.id .. e.person .. date("%Y/%m/%d %H:%M:%S",e.stamp)
 					end
 				end
 			end
@@ -2266,6 +2266,7 @@
 	--    overrides the hour and minute printed; if absent, those values are
 	--    taken from the DAY entry.
 	-- FORMAT_STRING may contain $x (x in Y/M/D/h/m) tokens.
+	-- FIXME this is horribabble
 	local format_timestamp_values, point2dee = {}, "%.2d"
 	function addon:format_timestamp (fmt_opt, day_entry, time_entry_opt)
 		if not time_entry_opt then
@@ -2465,7 +2466,11 @@
 			Detecting A is strictly an optimization.  We should be able to do
 			this code safely in all cases.
 			]]
-			if winning_index ~= 1 then
+			if
+--@debug@
+true or
+--@end-debug@
+				winning_index ~= 1 then
 				--XXX this branch still needs to be tested with live data
 				local cache = g_uniques:SEARCH(exist)
 				local looti,hi,ui = cache.loot, cache.history, cache.history_may
@@ -2872,7 +2877,7 @@
 
 		-- If any of these change, update the end of history_handle_disposition.
 		if (not e.unique) or (#e.unique==0) then
-			e.unique = e.id .. ' ' .. when
+			e.unique = e.id .. e.person .. when
 		end
 		local U = e.unique
 		tinsert (h.unique, 1, U)
@@ -3100,28 +3105,50 @@
 		return index
 	end
 
-	-- Similar to _addHistoryEntry.  The second arg may be a loot entry
-	-- (which used to be at LOOTINDEX), or nil (and the loot entry will
-	-- be pulled from LOOTINDEX instead).
-	function addon:_delHistoryEntry (lootindex, opt_e)
-		local e = opt_e or g_loot[lootindex]
-		if e.kind ~= 'loot' then return end
-
-		local from_i, from_h, hist_i = _history_by_loot_id (e, "delete")
+	local function expunge (player, index_or_unique)
+		local i,u
+		if type(index_or_unique) == 'string' then
+			for u = 1, #player.unique do
+				if player.unique[u] == index_or_unique then
+					i = u
+					break
+				end
+			end
+		elseif type(index_or_unique) == 'number' then
+			i = index_or_unique
+		end
+		if not i then
+			return -- error here?
+		end
+		u = player.unique[i]
+		assert(#u>0)
+		tremove (player.unique, i)
+		player.when[u], player.id[u], player.count[u] = nil, nil, nil
+		g_uniques[u] = nil
+		addon.hist_clean = nil
+	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 type(first) == 'table' then
+			second = first.itemlink or second
+		--elseif type(first) == 'string' then
+		end
+
+		local from_i, from_h, hist_i = _history_by_loot_id (first, "delete")
+
 		if not from_i then
 			-- from_h is the formatted error text
-			self:Print(from_h .. "  Loot will be deleted, but history will NOT be updated.", e.itemlink)
-			return
+			return nil, (from_h
+			        .."  Loot will be deleted, but history will NOT be updated."
+			       ):format(second)
 		end
 
-		local hist_u = tremove (from_h.unique, hist_i)
-		from_h.when[hist_u] = nil
-		from_h.id[hist_u] = nil
-		from_h.count[hist_u] = nil
-		g_uniques[hist_u] = nil
-		self.hist_clean = nil
-
-		self:Print("Removed history entry %d/%s from '%s'.", lootindex, e.itemlink, e.person)
+		expunge (from_h, hist_i)
+		return true
 	end
 
 	-- Any extra work for the "Mark as <x>" dropdown actions.  The
@@ -3141,6 +3168,7 @@
 		if (newdisp == 'shard' or newdisp == 'gvault') then
 			local name_i, name_h, hist_i = _history_by_loot_id (e, "mark")
 			-- remove history entry if it exists
+			-- FIXME revist this and use expunge
 			if hist_i then
 				local c = flib.new()
 				local hist_u = tremove (name_h.unique, hist_i)
@@ -3174,14 +3202,14 @@
 			-- FIXME The deleted cache isn't nearly as useful now with the new data structures.
 			local when
 			if (not e.unique) or (#e.unique==0) then
-				when = g_today and self:format_timestamp (g_today, e) or date("%Y/%m/%d %H:%M",e.stamp)
-				e.unique = e.id .. ' ' .. when
+				when = g_today and self:format_timestamp (g_today, e) or date("%Y/%m/%d %H:%M:%S",e.stamp)
+				e.unique = e.id .. name .. when
 			end
 			local U = e.unique
 			local c = deleted_cache[U]
 			deleted_cache[U] = nil
 			name_h.unique[#name_h.unique+1] = U
-			name_h.when[U] = c and c.when or when or date("%Y/%m/%d %H:%M",e.stamp)
+			name_h.when[U] = c and c.when or when or date("%Y/%m/%d %H:%M:%S",e.stamp)
 			name_h.id[U] = e.id -- c.id
 			name_h.count[U] = c and c.count or e.count
 			sort_player(name_h)