Keramond

TSM_API

Jul 28th, 2018
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1. -- ------------------------------------------------------------------------------ --
  2. --                                TradeSkillMaster                                --
  3. --                http://www.curse.com/addons/wow/tradeskill-master               --
  4. --                                                                                --
  5. --             A TradeSkillMaster Addon (http://tradeskillmaster.com)             --
  6. --    All Rights Reserved* - Detailed license information included with addon.    --
  7. -- ------------------------------------------------------------------------------ --
  8.  
  9. --- Public TSM API functions
  10. -- @module TSM_API
  11.  
  12. local _, TSM = ...
  13. TSM_API = {}
  14.  
  15.  
  16.  
  17. -- ============================================================================
  18. -- Public API Functions
  19. -- ============================================================================
  20.  
  21. --- Checks if a TSM UI is currently visible.
  22. -- @tparam string uiName A string which represents the UI ("AUCTION", "CRAFTING", "MAILING", or "VENDORING")
  23. -- @treturn boolean Whether or not the TSM UI is visible
  24. function TSM_API.IsUIVisible(uiName)
  25.     if uiName == "AUCTION" then
  26.         return TSM.UI.AuctionUI.IsVisible()
  27.     elseif uiName == "CRAFTING" then
  28.         return TSM.UI.CraftingUI.IsVisible()
  29.     elseif uiName == "MAILING" then
  30.         return TSM.UI.MailingUI.IsVisible()
  31.     elseif uiName == "VENDORING" then
  32.         return TSM.UI.VendoringUI.IsVisible()
  33.     else
  34.         error("Invalid uiName: "..tostring(uiName), 2)
  35.     end
  36. end
  37.  
  38. --- Gets a current list of TSM group paths.
  39. -- @tparam table result A table to store the result in
  40. -- @treturn table The passed table, populated with group paths
  41. function TSM_API.GetGroupPaths(result)
  42.     if type(result) ~= "table" then
  43.         error("Invalid 'result' argument type (must be a table): "..tostring(result), 2)
  44.     end
  45.     TSM.Groups:GetSortedGroupPathList(result)
  46.     return result
  47. end
  48.  
  49. --- Formats a TSM group path into a human-readable form
  50. -- @tparam string path The group path to be formatted
  51. -- @treturn string The formatted group path
  52. function TSM_API.FormatGroupPath(path)
  53.     if type(path) ~= "string" then
  54.         error("Invalid 'path' argument type (must be a string): "..tostring(path), 2)
  55.     elseif path == "" then
  56.         error("Invalid 'path' argument (empty string)", 2)
  57.     end
  58.     return TSMAPI_FOUR.Groups.FormatPath(path)
  59. end
  60.  
  61. --- Splits a TSM group path into its parent path and group name components.
  62. -- @tparam string path The group path to be split
  63. -- @?treturn string The path of the parent group or nil if the specified path has no parent
  64. -- @treturn string The name of the group
  65. function TSM_API.SplitGroupPath(path)
  66.     if type(path) ~= "string" then
  67.         error("Invalid 'path' argument type (must be a string): "..tostring(path), 2)
  68.     elseif path == "" then
  69.         error("Invalid 'path' argument (empty string)", 2)
  70.     end
  71.     local parentPath, groupName = TSMAPI_FOUR.Groups.SplitPath(path)
  72.     if parentPath == TSM.CONST.ROOT_GROUP_PATH then
  73.         parentPath = nil
  74.     end
  75.     return parentPath, groupName
  76. end
  77.  
  78. --- Gets the path to the group which a specific item is in.
  79. -- @tparam string|number item The item in either itemLink, itemString, or itemId representation
  80. -- @?treturn string The path to the group which the item is in, or nil if it's not in a group
  81. function TSM_API.GetGroupPathByItem(item)
  82.     if type(item) ~= "string" and type(item) ~= "number" then
  83.         error("Invalid 'item' argument type (must be a string or number): "..tostring(item), 2)
  84.     end
  85.     local path = TSMAPI_FOUR.Groups.GetPathByItem(item)
  86.     return path ~= TSM.CONST.ROOT_GROUP_PATH and path or nil
  87. end
Advertisement
Add Comment
Please, Sign In to add comment