You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.5 KiB
50 lines
1.5 KiB
|
3 years ago
|
-- ------------------------------------------------------------------------------ --
|
||
|
|
-- TradeSkillMaster --
|
||
|
|
-- https://tradeskillmaster.com --
|
||
|
|
-- All Rights Reserved - Detailed license information included with addon. --
|
||
|
|
-- ------------------------------------------------------------------------------ --
|
||
|
|
|
||
|
|
--- Craft String functions
|
||
|
|
-- @module CraftString
|
||
|
|
|
||
|
|
local _, TSM = ...
|
||
|
|
local CraftString = TSM.Init("Util.CraftString")
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
-- ============================================================================
|
||
|
|
-- Module Functions
|
||
|
|
-- ============================================================================
|
||
|
|
|
||
|
|
function CraftString.Get(spellId, rank, level)
|
||
|
|
local suffix = ""
|
||
|
|
if rank and rank > 0 then
|
||
|
|
assert(not level or level <= 0)
|
||
|
|
suffix = ":r"..rank
|
||
|
|
end
|
||
|
|
if level and level > 0 then
|
||
|
|
assert(not rank or rank <= 0)
|
||
|
|
suffix = ":l"..level
|
||
|
|
end
|
||
|
|
return "c:"..spellId..suffix
|
||
|
|
end
|
||
|
|
|
||
|
|
function CraftString.FromRecipeString(recipeString)
|
||
|
|
local spellId = strmatch(recipeString, "^r:(%d+)")
|
||
|
|
local rank = tonumber(strmatch(recipeString, ":r(%d+)"))
|
||
|
|
local level = tonumber(strmatch(recipeString, ":l(%d+)"))
|
||
|
|
return CraftString.Get(spellId, rank, level)
|
||
|
|
end
|
||
|
|
|
||
|
|
function CraftString.GetSpellId(craftString)
|
||
|
|
return tonumber(strmatch(craftString, "^c:(%d+)"))
|
||
|
|
end
|
||
|
|
|
||
|
|
function CraftString.GetRank(craftString)
|
||
|
|
return tonumber(strmatch(craftString, ":r(%d+)"))
|
||
|
|
end
|
||
|
|
|
||
|
|
function CraftString.GetLevel(craftString)
|
||
|
|
return tonumber(strmatch(craftString, ":l(%d+)"))
|
||
|
|
end
|