annotate Modules/Api.lua @ 119:d94195157a6b

Moved the check for QAManager so it doesn't interfere with the tooltip or ArkInventory rule.
author Asa Ayers <Asa.Ayers@Gmail.com>
date Thu, 02 Sep 2010 21:16:04 -0700
parents 1fbbe3b53f6e
children
rev   line source
Asa@64 1 local ItemAuditor = select(2, ...)
Asa@64 2
Asa@64 3 local Crafting = ItemAuditor:GetModule("Crafting")
Asa@64 4
Asa@64 5 IAapi = {}
Asa@64 6
Asa@64 7 --[[
Asa@64 8 You can register a callback here to influence which items will get crafted and how many.
Asa@64 9 The decider function needs to return the number of items the user should have in their
Asa@64 10 inventory. If the number owned is less than the highest decided number, that item will
Asa@64 11 be queued to be crafted unless any decider vetos the item.
Asa@64 12
Asa@64 13 There is no way to unregister your decider but it can be overwritten with a function that simply returns 0.
Asa@64 14
Asa@64 15 Please make sure your decider runs as fast as possible, It will be called at least once
Asa@64 16 for every tradeskill being considered.
Asa@64 17
Asa@64 18 I find the (non) word "Decider" to be amusing, so I used it.
Asa@64 19
Asa@64 20 ItemAuditor will veto any item that costs more to create than it will sell for, It will also
Asa@64 21 queue one of every item that is profitable. If you simply wanted to increase that to 5 of every
Asa@64 22 profitable item you could use this:
Asa@64 23
Asa@64 24 IAapi.RegisterCraftingDecider('Five', function() return 5 end)
Asa@64 25 ]]
Asa@73 26 function IAapi.RegisterCraftingDecider(name, decider, optionsTable)
Asa@70 27 assert(type(name) == 'string', 'name must be a string to identify your addon. This will be displayed to the user.')
Asa@73 28 assert(type(decider) == 'function', 'decider must be a function.')
Asa@73 29 assert(optionsTable == nil or type(optionsTable) == 'table')
Asa@73 30 Crafting.RegisterCraftingDecider(name, decider, optionsTable)
Asa@64 31 end
Asa@64 32
Asa@70 33 function IAapi.RegisterQueueDestination(name, destination)
Asa@70 34 assert(type(name) == 'string', 'name must be a string to identify your addon. This will be displayed to the user.')
Asa@70 35 assert(type(destination) == 'function', 'destination must be a function that will be called for each item when exporting the queue.')
Asa@70 36
Asa@70 37 Crafting.RegisterQueueDestination(name, destination)
Asa@70 38 end
Asa@64 39
Asa@70 40 function IAapi.UnRegisterQueueDestination(name)
Asa@70 41 assert(type(name) == 'string', 'name must be the string that was used to register your addon.')
Asa@70 42 Crafting.UnRegisterQueueDestination(name)
Asa@70 43 end
Asa@70 44
Asa@96 45 function IAapi.GetItemCost(link)
Asa@96 46 assert(link, 'usage: IAapi.GetItemCost(itemLink)')
Asa@96 47 return ItemAuditor:GetItemCost(link)
Asa@96 48 end
Asa@96 49
Asa@96 50
Asa@96 51
Asa@95 52 local function registerLoadedAddons()
Asa@95 53 return ItemAuditor_RegisterAPI and ItemAuditor_RegisterAPI()
Asa@95 54 end
Asa@95 55 registerLoadedAddons()
Asa@95 56
Asa@95 57
Asa@95 58 -- This is here so I have a second option in the menu and to serve as an example of
Asa@95 59 -- how to register your addon with ItemAuditor.
Asa@70 60 --@debug@
Asa@95 61 local function RegisterWithItemAuditor()
Asa@95 62 local function testDestination(data)
Asa@95 63 -- Replace this with a call to the methods you need in your addon
Asa@95 64 ItemAuditor:Print('queue: '..data.recipeLink)
Asa@95 65 end
Asa@95 66 -- Replace Echo with the name of your addon so it can be selected from /ia options
Asa@95 67 IAapi.RegisterQueueDestination('Echo', testDestination)
Asa@70 68 end
Asa@70 69
Asa@95 70 if IAapi then
Asa@95 71 RegisterWithItemAuditor()
Asa@95 72 else
Asa@95 73 -- make sure to save any other addon's function
Asa@95 74 local original = ItemAuditor_RegisterAPI
Asa@95 75 -- this should not be local so it replaces (or creates) the global function
Asa@95 76 function ItemAuditor_RegisterAPI()
Asa@95 77 RegisterWithItemAuditor()
Asa@95 78 -- if original has a value (function), this will run it
Asa@95 79 return original and original()
Asa@95 80 end
Asa@95 81 end
Asa@95 82
Asa@95 83
Asa@95 84
Asa@95 85
Asa@70 86 --@end-debug@