changeset 70:3930518cb8d9

Added a public API so other addon developers can register themselves as a queue destination and added a UI so users can select that destination.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Wed, 28 Jul 2010 22:19:38 -0700
parents 4ae431c98059
children aaf9a155995b
files CHANGELOG.txt Core.lua Modules/Api.lua Modules/Crafting.lua Modules/QuickAuctions.lua
diffstat 5 files changed, 69 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGELOG.txt	Wed Jul 28 21:27:39 2010 -0700
+++ b/CHANGELOG.txt	Wed Jul 28 22:19:38 2010 -0700
@@ -3,6 +3,7 @@
 - Fixed a bug with the crafting threshold options.
 - Updated /ia queue so that it is a shortcut to using /ia crafting and then clicking export.
 - Added integration with ArkInventory. You can set up rules that use "itemauditor('profitable')" or "itemauditor('qa')" to find items managed by QuickAuctions.
+- Added a public API so other addon developers can register themselves as a queue destination and added a UI so users can change that destination.
 
 2010-07-27  Asa Ayers  <Asa.Ayers@Gmail.com>
 
--- a/Core.lua	Wed Jul 28 21:27:39 2010 -0700
+++ b/Core.lua	Wed Jul 28 22:19:38 2010 -0700
@@ -58,8 +58,7 @@
 				queue_skip = false,
 			},
 			ItemAuditor_enabled = true,
-			-- This is for development, so I have no plans to turn it into an option.
-			show_debug_frame_on_startup = false,
+			queue_destination = nil,
 		},
 		factionrealm = {
 			item_account = {},
--- a/Modules/Api.lua	Wed Jul 28 21:27:39 2010 -0700
+++ b/Modules/Api.lua	Wed Jul 28 22:19:38 2010 -0700
@@ -24,7 +24,28 @@
 	IAapi.RegisterCraftingDecider('Five', function() return 5 end)
 ]]
 function IAapi.RegisterCraftingDecider(name, decider)
+	assert(type(name) == 'string', 'name must be a string to identify your addon. This will be displayed to the user.')
+	assert(type(destination) == 'function', 'decider must be a function.')
 	Crafting.RegisterCraftingDecider(name, decider)
 end
 
+function IAapi.RegisterQueueDestination(name, destination)
+	assert(type(name) == 'string', 'name must be a string to identify your addon. This will be displayed to the user.')
+	assert(type(destination) == 'function', 'destination must be a function that will be called for each item when exporting the queue.')
+	
+	Crafting.RegisterQueueDestination(name, destination)
+end
 
+function IAapi.UnRegisterQueueDestination(name)
+	assert(type(name) == 'string', 'name must be the string that was used to register your addon.')
+	Crafting.UnRegisterQueueDestination(name)
+end
+
+--@debug@
+-- This is here so I have a second option in the menu and to serve as an example.
+local function testDestination(data)
+	ItemAuditor:Print('queue: '..data.recipeLink)
+end
+
+IAapi.RegisterQueueDestination('Echo', testDestination)
+--@end-debug@
--- a/Modules/Crafting.lua	Wed Jul 28 21:27:39 2010 -0700
+++ b/Modules/Crafting.lua	Wed Jul 28 22:19:38 2010 -0700
@@ -11,9 +11,33 @@
 
 
 local queueDestinations = {}
-
+local displayCraftingDestinations = {}
 function Crafting.RegisterQueueDestination(name, destination)
 	queueDestinations[name] = destination
+	displayCraftingDestinations[name] = name
+end
+
+function Crafting.UnRegisterQueueDestination(name)
+	queueDestinations[name] = nil
+	displayCraftingDestinations[name] = nil
+end
+
+function Crafting.GetQueueDestination()
+	local dest = ItemAuditor.db.profile.queue_destination
+	if dest and queueDestinations[dest] then
+		return queueDestinations[dest], dest
+	end
+	-- If there is none selected or the selected option has 
+	-- dissapeared, choose the first one in the list
+	for name, func in pairs(queueDestinations) do
+		if dest then
+			ItemAuditor:Print("%s is no longer available as a queue destination. %s is the new default", dest, name)
+		end
+		ItemAuditor.db.profile.queue_destination = name
+		return func, name
+	end
+	
+	error('Unable to determine queue destination.')
 end
 
 -- TODO: Convert this to a text field.
@@ -31,10 +55,8 @@
 end
 
 ItemAuditor.Options.args.crafting_options = {
-	name = "Crafting with Skillet",
-	desc = "/ia queue",
+	name = "Crafting",
 	type = 'group',
-	disabled = function() return Skillet == nil end,
 	args = {
 		crafting_threshold = {
 			type = "select",
@@ -45,6 +67,15 @@
 			set = function(info, value) ItemAuditor.db.char.crafting_threshold = value end,
 			order = 11,
 		},
+		queue_destination = {
+			type = "select",
+			name = "Queue Destination",
+			desc = "Select the addon who's queue you would like ItemAuditor to post to.",
+			values = displayCraftingDestinations,
+			get = function() return select(2, Crafting.GetQueueDestination()) end,
+			set = function(info, value) ItemAuditor.db.profile.queue_destination = value end,
+			order = 11,
+		},
 	},
 }
 
@@ -101,7 +132,7 @@
 	if type(destination) == 'function' then
 		-- do nothing
 	elseif destination == nil then
-		destination = queueDestinations['Skillet']
+		destination = Crafting.GetQueueDestination()
 	elseif type(destination) == 'string' then
 		destination = queueDestinations[destination]
 	else
@@ -188,15 +219,19 @@
 		end)
 	
 		btnSkillet = CreateFrame("Button", nil, craftingContent, "UIPanelButtonTemplate")
-		btnSkillet:SetText("Queue in Skillet")
+		
+		
 		btnSkillet:SetSize(125, 25) 
 		btnSkillet:SetPoint("BOTTOMRIGHT", btnProcess, 'BOTTOMLEFT', 0, 0)
 		btnSkillet:RegisterForClicks("LeftButtonUp");
 		btnSkillet:SetScript("OnClick", function (self, button, down)
-			ExportToSkillet()
+			Crafting.Export()
 		end)
 		
 	end
+	local destination = select(2, Crafting.GetQueueDestination())
+	btnSkillet:SetText("Export to "..destination)
+	
 	craftingContent:Show()
 	
 	if container.parent then
--- a/Modules/QuickAuctions.lua	Wed Jul 28 21:27:39 2010 -0700
+++ b/Modules/QuickAuctions.lua	Wed Jul 28 22:19:38 2010 -0700
@@ -119,13 +119,15 @@
 
 
 function ItemAuditor:Queue()
+	local dest, name = Crafting.GetQueueDestination()
 	local function Export(data)
-		ItemAuditor:Print(format("Adding %s x%s to skillet queue. Profit: %s", 
+		ItemAuditor:Print(format("Adding %s x%s to %s queue. Profit: %s", 
 			data.link, 
 			data.queue, 
+			name,
 			Utils.FormatMoney(data.profit)
 		))
-		Crafting.ExportToSkillet(data)
+		dest(data)
 	end
 	ItemAuditor:UpdateCraftingTable()
 	Crafting.Export(Export)