A simple LibStub library that helps with accessing information about which talents are known.
How to use:
Add library to yor project by placing it and LibStub (included) in a folder of your addon. Then put something like:
local libTalent = LibStub("LibTalent-1.0");
in your addon.
Functions:
libTalent:checkTalent(talent, [guid])
Checks if you have talent with name or spell ID indicated by 'talent'. If guid is provided, dos the same ofr unit with the given GUID. Must be done asynchronously for units other than yourself.
Returns the number of ranks learned (including 0); nil if a choice node, or a talent that the class does not have; -1 if used on a GUID that has not returned asynchronous data.
libTalent:getInspectTalents(unit, [callback])
Requests inspect data for the unit given (e.g. 'target') and registers an event to call getTalents(guid) for the GUID provided by the server when the requested data arrives.
If a function callback is given, this callback is called with guid as its argument when the server provides the inspect data.
Returns true if target was within inspect range, false otherwise.
libTalent:getTalents([guid])
Gets your own talents and caches them if guid is not provided, otherwise does the same for the unit with the given GUID.
Getting talents for other units is done asynchronously.
You shouldn't have to call this, as it is called automatically by checkTalent for your own character, and by getInspectTalents for other units.
libTalent.dumpTalents([guid])
Prints a list in the chat console of all talent spell IDs, names and ranks for your character, or for unit GUID is guid is provided.
libTalent:clearSelfCache()
Clears the cache of your own talents. Happens automatically if you change spec, forcing a getTalents() the next time you try to check your own talents, preventing stale talents.
libTalent:clearGuidCache([guid])
Clears all data for the unit with GUID guid from the cache. You may wish to call this to free memory if you check a lot of units. If guid is not given, clears all GUIDs.
libTalent:clearAllCaches()
Simply calls both clearGuidCache() and clearSelfCache().
Example:
If libTalent is an instance of LibTalent, then this would
-request the inspect data for 'target' from the server
-cache the talent data when the server responds
-use the callback feature to dump the talent data to the chat window once the data is cached.
libTalent:getInspectTalents('target', libTalent.dumpTalents);