diff 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
line wrap: on
line diff
--- a/core.lua	Mon Aug 06 14:57:14 2012 -0400
+++ b/core.lua	Wed Aug 08 14:43:26 2012 -0400
@@ -64,7 +64,8 @@
 - bcast_from    player's name if received rebroadcast from that player;
                 missing otherwise; can be deleted as a result of in-game
                 fiddling of loot data
-- extratext     text in Note column, including disposition and rebroadcasting
+- extratext     text in Note column, including disposition and rebroadcasting;
+                missing otherwise
 - extratext_byhand    true if text edited by player directly; missing otherwise
 
 
@@ -260,7 +261,7 @@
 		if cond then
 			return cond,msg,...
 		else
-			error('ASSERT() FAILED:  '..tostring(msg or 'nil'))
+			error('ASSERT() FAILED:  '.._G.tostring(msg or 'nil'),3)
 		end
 	end
 
@@ -308,6 +309,7 @@
 	SLASH_ACECONSOLE_OUROLOOT2 = nil
 	self.error (msg, --[[level=]]2)
 end
+addon.FILES_LOADED = 0
 
 -- Seriously?  ORLY?
 -- YARLY.  Go ahead and guess what was involved in tracking this down.  If
@@ -724,6 +726,15 @@
 		_G.OL = self
 		_G.g_uniques = g_uniques
 	end
+	-- This kludgy-looking thing is because if there are serious errors in
+	-- loading, some of the actions during PLAYER_LOGOUT can destroy data.
+	if self.FILES_LOADED ~= 7 then
+		print('|cffaee3ffouroloot reports load count of',self.FILES_LOADED,'fml|r')
+		self:SetEnabledState(false)
+		return
+	end
+	self.FILES_LOADED = nil
+
 	_log = OuroLootSV_log
 
 	-- VARIABLES_LOADED has fired by this point; test if we're doing something like
@@ -1466,8 +1477,7 @@
 				candidates[sig] = nil
 				local looti = addon._addLootEntry(loot)
 				addon.dprint('loot', "entry", i, "was found, added at index", looti)
-				if (loot.disposition ~= 'shard')
-				   and (loot.disposition ~= 'gvault')
+				if addon:_test_disposition (loot.disposition, 'affects_history')
 				   and (not addon.history_suppress)
 				then
 					addon:_addHistoryEntry(looti)
@@ -1583,15 +1593,16 @@
 			if local_override then
 				-- player is adding loot by hand, don't wait for network cache timeouts
 				-- keep this sync'd with prefer_local_loots above
-				if i.extratext == 'shard'
-				   or i.extratext == 'gvault'
-				   or i.extratext == 'offspec'
-				then
-					i.disposition = i.extratext
+				if i.extratext then
+					for disp,text in self:_iter_dispositions('from_notes_text') do
+						if text == i.extratext then
+							i.disposition = disp
+							break
+						end
+					end
 				end
 				local looti = self._addLootEntry(i)
-				if (i.disposition ~= 'shard')
-				   and (i.disposition ~= 'gvault')
+				if self:_test_disposition (i.disposition, 'affects_history')
 				   and (not self.history_suppress)
 				then
 					self:_addHistoryEntry(looti)
@@ -1984,7 +1995,7 @@
 			else
 				to_text = "normal"
 			end
-			to_text = addon.disposition_colors[e.disposition or "normal"].hex
+			to_text = addon.disposition_colors[e.disposition].hex
 				.. to_text .. "|r"
 		end
 
@@ -2551,6 +2562,75 @@
 	end
 end
 
+-- Disposition control; more precisely, how various dispositions affect flow
+-- and displays elsewhere.
+do
+	local default = {
+		text = "",
+		hex = "|cffffffff",
+		r = 1.0, g = 1.0, b = 1.0, a = 1,
+		can_reassign = true,
+		affects_history = true,
+		from_notes_text = false,
+	}
+	local mt = {
+		__index = function (t,k)
+			-- don't point index directly at default, need to catch nils
+			return default
+		end,
+	}
+	local alldisps = setmetatable({}, mt)
+	addon.disposition_colors = setmetatable({}, mt)
+
+	-- These two are clunky wrappers, probably rework this once gain some data.
+	function addon:_test_disposition (code, attrib)
+		return alldisps[code][attrib]
+	end
+	function addon:_iter_dispositions (attrib)
+		local r = {}
+		for code,disp in next, alldisps do
+			if disp.attrib then
+				r[code] = disp.text
+			end
+		end
+		return next, r
+	end
+
+	function addon:_add_loot_disposition (code, rhex, ghex, bhex, text,
+		can_reassign_p, do_history_p, from_notes_text_p
+	)
+		assert(type(code)=='string' and #code>0)
+		assert(type(text)=='string')
+		assert(type(rhex)=='string')
+		assert(type(bhex)=='string')
+		assert(type(ghex)=='string')
+		self.disposition_colors[code] = {
+			text = text,
+			-- for chat output by core code
+			hex = "|cff" .. rhex .. ghex .. bhex,
+			-- for lib-st
+			r = tonumber(rhex,16)/255,
+			g = tonumber(ghex,16)/255,
+			b = tonumber(bhex,16)/255,
+			a = 1,
+		}
+		-- not not = poor man's "toboolean", don't potentially hold arg
+		-- objects from garbage collection
+		alldisps[code] = {
+			text = text,
+			can_reassign = not not can_reassign_p,
+			affects_history = not not do_history_p,
+			from_notes_text = not not from_notes_text_p,
+		}
+	end
+
+	-- reassign while tagged, affects history, copy from notes
+	addon:_add_loot_disposition ('normal',  "ff","ff","ff", "",       true, true, false)
+	addon:_add_loot_disposition ('offspec', "c6","9b","6d", "offspec", true, true, true)
+	addon:_add_loot_disposition ('shard',   "a3","35","ee", "shard", false, false, true)
+	addon:_add_loot_disposition ('gvault',  "33","ff","99", _G.GUILD_BANK:lower(), false, false, true)
+end
+
 -- In the rare case of items getting put into the loot table without current
 -- item cache data (which will have arrived by now).
 function addon:do_item_cache_fixup()
@@ -2965,7 +3045,7 @@
 				local hmmm = rawget(g_uniques,e.unique)
 				if hmmm then
 					hmmm.loot = i
-				elseif e.disposition == 'shard' or e.disposition == 'gvault' then
+				elseif not self:_test_disposition (e.disposition, 'affects_history') then
 					g_uniques[e.unique] = { loot = i, history = g_uniques.NOTFOUND }
 					count = count + 1
 				else
@@ -3367,7 +3447,7 @@
 
 		local name = e.person
 
-		if (newdisp == 'shard' or newdisp == 'gvault') then
+		if not self:_test_disposition (newdisp, 'affects_history') 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
@@ -3382,7 +3462,7 @@
 				name_h.id[hist_u] = nil
 				name_h.count[hist_u] = nil
 				self.hist_clean = nil
-			elseif (olddisp == 'shard' or olddisp == 'gvault') then
+			elseif not self:_test_disposition (olddisp, 'affects_history') then
 				-- Sharding a vault item, or giving the auto-sharder something to bank,
 				-- etc, wouldn't necessarily have had a history entry to begin with.
 				-- So this isn't treated as an error.
@@ -3392,8 +3472,8 @@
 			return
 		end
 
-		if (olddisp == 'shard' or olddisp == 'gvault')
-		   and (newdisp == 'normal' or newdisp == 'offspec')
+		if (not self:_test_disposition (olddisp, 'affects_history'))
+		   and self:_test_disposition (newdisp, 'affects_history')
 		then
 			local name_i, name_h = self:get_loot_history(name)
 
@@ -3722,4 +3802,5 @@
 	end
 end
 
+addon.FILES_LOADED = 1
 -- vim:noet