Quantcast

Replaced "is_relevant", "is_visible", and "is_known" recipe members with recipe.state bitflags.

James D. Callahan III [04-01-10 - 17:59]
Replaced "is_relevant", "is_visible", and "is_known" recipe members with recipe.state bitflags.
Filename
ARL.lua
Constants.lua
Frame.lua
Player.lua
Waypoint.lua
diff --git a/ARL.lua b/ARL.lua
index e000b43..f61de15 100644
--- a/ARL.lua
+++ b/ARL.lua
@@ -517,8 +517,10 @@ function addon:OnInitialize()
 				       if scanned then
 					       local skill_level = Player.professions[recipe_prof]
 					       local has_level = skill_level and (type(skill_level) == "boolean" and true or skill_level >= recipe.skill_level)
+					       local SF = private.recipe_state_flags
+					       local is_known = (bit.band(recipe.state, SF.KNOWN) == SF.KNOWN)

-					       if ((not recipe.is_known and has_level) or shifted) and Player:IsCorrectFaction(recipe) then
+					       if ((not is_known and has_level) or shifted) and Player:IsCorrectFaction(recipe) then
 						       local _, _, _, hex = GetItemQualityColor(recipe.quality)

 						       self:AddLine(string.format("%s: %s%s|r (%d)", recipe.profession, hex, recipe.name, recipe.skill_level))
@@ -865,8 +867,12 @@ function addon:AddRecipe(spell_id, skill_level, item_id, quality, profession, sp
 		["medium_level"]	= medium_level or skill_level + 10,
 		["easy_level"]		= easy_level or skill_level + 15,
 		["trivial_level"]	= trivial_level or skill_level + 20,
-		["is_relevant"]		= true,				-- Set to be showing in the search results
+		["state"]		= 0,				-- State flags.
 	}
+	local SF = private.recipe_state_flags
+
+	-- Set the "relevant" flag for searches, until I peer at the search logic to make this unnecessary.
+	recipe.state = bit.bxor(recipe.state, SF.RELEVANT)

 	if not recipe.name then
 		self:Print(strformat(L["SpellIDCache"], spell_id))
@@ -1573,10 +1579,11 @@ do
 		local can_display = false
 		local current_profession = Player.current_prof
 		local recipe_list = private.recipe_list
+		local SF = private.recipe_state_flags

 		for recipe_id, recipe in pairs(recipe_list) do
 			if recipe.profession == current_profession then
-				local is_known = recipe.is_known
+				local is_known = (bit.band(recipe.state, SF.KNOWN) == SF.KNOWN)

 				can_display = CanDisplayRecipe(recipe)
 				recipes_total = recipes_total + 1
@@ -1597,7 +1604,11 @@ do
 			else
 				can_display = false
 			end
-			recipe.is_visible = can_display or nil
+			local is_visible = (bit.band(recipe.state, SF.VISIBLE) == SF.VISIBLE)
+
+			if (can_display and not is_visible) or (not can_display and is_visible) then
+				recipe.state = bit.bxor(recipe.state, SF.VISIBLE)
+			end
 		end
 		Player.recipes_total = recipes_total
 		Player.recipes_known = recipes_known
@@ -1748,6 +1759,7 @@ do
 		end
 		local recipe_list = private.recipe_list
 		local recipes_found = 0
+		local SF = private.recipe_state_flags

 		for i = 1, GetNumTradeSkills() do
 			local tradeName, tradeType = GetTradeSkillInfo(i)
@@ -1759,7 +1771,11 @@ do
 				local recipe = recipe_list[tonumber(SpellString)]

 				if recipe then
-					recipe.is_known = true
+					local is_known = (bit.band(recipe.state, SF.KNOWN) == SF.KNOWN)
+
+					if not is_known then
+						recipe.state = bit.bxor(recipe.state, SF.KNOWN)
+					end
 					recipes_found = recipes_found + 1
 				else
 					self:Debug(tradeName .. " " .. SpellString .. L["MissingFromDB"])
@@ -1934,10 +1950,12 @@ do
 			tinsert(text_table, strformat("Ackis Recipe List Text Dump for %s's %s, in the form of BBCode.\n", UnitName("player"), profession))
 		end
 		local recipe_list = private.recipe_list
+		local SF = private.recipe_state_flags

 		for recipe_id in pairs(recipe_list) do
 			local recipe = recipe_list[recipe_id]
 			local recipe_prof = GetSpellInfo(recipe.profession)
+			local is_known = (bit.band(recipe.state, SF.KNOWN) == SF.KNOWN)

 			if recipe_prof == profession then
 				-- CSV
@@ -1952,15 +1970,15 @@ do
 				-- BBCode
 				elseif output == "BBCode" then
 					-- Make the entry red
-					if not recipe.is_known then
+					if not is_known then
 						tinsert(text_table, "[color=red]")
 					end
 					tinsert(text_table, "\n[b]" .. recipe_id .. "[/b] - " .. recipe.name .. " (" .. recipe.skill_level .. ")\n")

 					-- Close Color tag
-					if not recipe.is_known then
+					if not is_known then
 						tinsert(text_table, "[/color]\nRecipe Flags:\n[list]")
-					elseif recipe.is_known then
+					elseif is_known then
 						tinsert(text_table, "\nRecipe Flags:\n[list]")
 					end
 				--Name
@@ -2022,7 +2040,7 @@ do
 				end

 				if not output or output == "Comma" then
-					if recipe.is_known then
+					if is_known then
 						tinsert(text_table, "\",true\n")
 					else
 						tinsert(text_table, "\",false\n")
@@ -2031,7 +2049,7 @@ do
 					tinsert(text_table, "\n[/list]")
 				end
 			end
-		end
+		end	-- for
 		return tconcat(text_table, "")
 	end
 end
diff --git a/Constants.lua b/Constants.lua
index 7911215..bbe272f 100644
--- a/Constants.lua
+++ b/Constants.lua
@@ -312,6 +312,15 @@ private.flag_members = {
 }

 -------------------------------------------------------------------------------
+-- Recipe state flags.
+-------------------------------------------------------------------------------
+private.recipe_state_flags = {
+	KNOWN		= 0x00000001,
+	RELEVANT	= 0x00000002,
+	VISIBLE		= 0x00000004,
+}
+
+-------------------------------------------------------------------------------
 -- Acquire types.
 -------------------------------------------------------------------------------
 private.acquire_types = {
diff --git a/Frame.lua b/Frame.lua
index dfc5845..7a5118a 100644
--- a/Frame.lua
+++ b/Frame.lua
@@ -117,6 +117,8 @@ local FACTION_NEUTRAL		= BFAC["Neutral"]
 local CATEGORY_COLORS		= private.category_colors
 local BASIC_COLORS		= private.basic_colors

+local SF = private.recipe_state_flags
+
 -------------------------------------------------------------------------------
 -- Acquire flag constants.
 -------------------------------------------------------------------------------
@@ -1333,12 +1335,10 @@ do
 		end
 		pattern = pattern:lower()

-		local recipe_list = private.recipe_list
-
-		for index in pairs(recipe_list) do
-			local entry = recipe_list[index]
-
-			entry.is_relevant = false
+		for index, entry in pairs(private.recipe_list) do
+			if bit.band(entry.state, SF.RELEVANT) == SF.RELEVANT then
+				entry.state = bit.bxor(entry.state, SF.RELEVANT)
+			end

 			for location_name in pairs(location_list) do
 				local breakout = false
@@ -1348,7 +1348,7 @@ do
 						local str = location_name:lower()

 						if str and str:find(pattern) then
-							entry.is_relevant = true
+							entry.state = bit.bxor(entry.state, SF.RELEVANT)
 							breakout = true
 							break
 						end
@@ -1364,7 +1364,7 @@ do
 				local str = acquire_names[acquire_type]:lower()

 				if str and str:find(pattern) and entry.acquire_data[acquire_type] then
-					entry.is_relevant = true
+					entry.state = bit.bxor(entry.state, SF.RELEVANT)
 					break
 				end
 			end
@@ -1373,7 +1373,7 @@ do
 				local str = entry[field] and tostring(entry[field]):lower() or nil

 				if str and str:find(pattern) then
-					entry.is_relevant = true
+					entry.state = bit.bxor(entry.state, SF.RELEVANT)
 					break
 				end
 			end
@@ -1416,7 +1416,11 @@ ARL_ClearButton:SetScript("OnClick",

 				  -- Reset the search flags
 				  for index in pairs(recipe_list) do
-					  recipe_list[index].is_relevant = true
+					  local recipe = recipe_list[index]
+
+					  if bit.band(recipe.state, SF.RELEVANT) ~= SF.RELEVANT then
+						  recipe.state = bit.bxor(recipe.state, SF.RELEVANT)
+					  end
 				  end
 				  MainPanel.search_editbox:SetText(_G.SEARCH)

@@ -1495,7 +1499,9 @@ MainPanel.search_editbox:SetScript("OnTextSet",
 						   for spell_id in pairs(recipe_list) do
 							   local recipe = recipe_list[spell_id]

-							   recipe.is_relevant = true
+							   if bit.band(recipe.state, SF.RELEVANT) ~= SF.RELEVANT then
+								   recipe.state = bit.bxor(recipe.state, SF.RELEVANT)
+							   end
 						   end
 						   ARL_SearchButton:SetNormalFontObject("GameFontDisableSmall")
 						   ARL_SearchButton:Disable()
@@ -2886,8 +2892,10 @@ do
 				for spell_id, affiliation in pairs(private.acquire_list[acquire_type].recipes) do
 					local recipe = private.recipe_list[spell_id]
 					local can_display = HasCredentials(affiliation)
+					local is_visible = (bit.band(recipe.state, SF.VISIBLE) == SF.VISIBLE)
+					local is_relevant = (bit.band(recipe.state, SF.RELEVANT) == SF.RELEVANT)

-					if can_display and recipe.is_visible and recipe.is_relevant then
+					if can_display and is_visible and is_relevant then
 						count = count + 1

 						if not recipe_registry[recipe] then
@@ -2923,8 +2931,10 @@ do
 				for spell_id, affiliation in pairs(private.location_list[loc_name].recipes) do
 					local recipe = private.recipe_list[spell_id]
 					local can_display = HasCredentials(affiliation)
+					local is_visible = (bit.band(recipe.state, SF.VISIBLE) == SF.VISIBLE)
+					local is_relevant = (bit.band(recipe.state, SF.RELEVANT) == SF.RELEVANT)

-					if can_display and recipe.is_visible and recipe.is_relevant then
+					if can_display and is_visible and is_relevant then
 						count = count + 1

 						if not recipe_registry[recipe] then
@@ -2948,12 +2958,14 @@ do

 			for i = 1, #sorted_recipes do
 				local recipe_index = sorted_recipes[i]
-				local recipe_entry = recipe_list[recipe_index]
+				local recipe = recipe_list[recipe_index]
+				local is_visible = (bit.band(recipe.state, SF.VISIBLE) == SF.VISIBLE)
+				local is_relevant = (bit.band(recipe.state, SF.RELEVANT) == SF.RELEVANT)

-				if recipe_entry.is_visible and recipe_entry.is_relevant then
+				if is_visible and is_relevant then
 					local t = AcquireTable()

-					t.text = FormatRecipeText(recipe_entry)
+					t.text = FormatRecipeText(recipe)
 					t.recipe_id = recipe_index

 					recipe_count = recipe_count + 1
@@ -3443,8 +3455,10 @@ do
 				for spell_id, affiliation in pairs(private.acquire_list[acquire_id].recipes) do
 					local recipe_entry = private.recipe_list[spell_id]
 					local can_display = HasCredentials(affiliation)
+					local is_visible = (bit.band(recipe_entry.state, SF.VISIBLE) == SF.VISIBLE)
+					local is_relevant = (bit.band(recipe_entry.state, SF.RELEVANT) == SF.RELEVANT)

-					if can_display and recipe_entry.is_visible and recipe_entry.is_relevant then
+					if can_display and is_visible and is_relevant then
 						local t = AcquireTable()
 						local expand = false
 						local type = "subheader"
@@ -3478,8 +3492,10 @@ do
 				for spell_id, affiliation in pairs(private.location_list[location_id].recipes) do
 					local recipe_entry = private.recipe_list[spell_id]
 					local can_display = HasCredentials(affiliation)
+					local is_visible = (bit.band(recipe_entry.state, SF.VISIBLE) == SF.VISIBLE)
+					local is_relevant = (bit.band(recipe_entry.state, SF.RELEVANT) == SF.RELEVANT)

-					if can_display and recipe_entry.is_visible and recipe_entry.is_relevant then
+					if can_display and is_visible and is_relevant then
 						local expand = false
 						local type = "subheader"
 						local t = AcquireTable()
diff --git a/Player.lua b/Player.lua
index 6ad2b5d..896d299 100644
--- a/Player.lua
+++ b/Player.lua
@@ -72,12 +72,14 @@ function Player:MarkExclusions()
 	local profession = self.current_prof
 	local known_count = 0
 	local unknown_count = 0
+	local SF = private.recipe_state_flags

 	for spell_id in pairs(exclusion_list) do
 		local recipe = recipe_list[spell_id]
+		local is_known = (bit.band(recipe.state, SF.KNOWN) == SF.KNOWN)

 		if recipe then
-			if recipe.is_known and recipe.profession == profession then
+			if is_known and recipe.profession == profession then
 				known_count = known_count + 1
 			elseif recipe_profession == profession then
 				unknown_count = unknown_count + 1
diff --git a/Waypoint.lua b/Waypoint.lua
index b0a7926..a57f8d0 100644
--- a/Waypoint.lua
+++ b/Waypoint.lua
@@ -433,12 +433,15 @@ function addon:SetupMap(single_recipe)
 		end
 	elseif addon.db.profile.autoscanmap then
 		local sorted_recipes = addon.sorted_recipes
+		local SF = private.recipe_state_flags

 		-- Scan through all recipes to display, and add the vendors to a list to get their acquire info
 		for i = 1, #sorted_recipes do
 			local recipe = recipe_list[sorted_recipes[i]]
+			local is_visible = (bit.band(recipe.state, SF.VISIBLE) == SF.VISIBLE)
+			local is_relevant = (bit.band(recipe.state, SF.RELEVANT) == SF.RELEVANT)

-			if recipe.is_visible and recipe.is_relevant then
+			if is_visible and is_relevant then
 				for acquire_type, acquire_info in pairs(recipe.acquire_data) do
 					for id_num, id_info in pairs(acquire_info) do
 						if acquire_type == A.REPUTATION then