View Single Post
10-28-18, 03:50 PM   #19
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 321
So here is how I eventually got the expansion and required level of a recipe by scanning the tooltip:

First I need a table like this to know in which order the expansion name (like "" for Vanilla, "Outland" for BC, "Northrend" for WotLK, etc.) and the profession name are given depending on the locale.

Code:
-- The %s in _G.ITEM_MIN_SKILL = "Requires %s (%d)" is replaced
-- by an expansion identifier and the profession name.
-- But the order depends on the locale.
-- e: expansion identifier
-- p: profession name
local itemMinSkillString = {
  ["enUS"] = "e p",
  ["enGB"] = "e p",
  ["deDE"] = "p e",
  ["frFR"] = "p e",
  ["itIT"] = "p e",
}

Let professionName be the localised itemSubType of the respective recipe as returned by getItemInfo(). Then the search pattern for scanning the tooltip must be built like this:

Code:
-- Need %%%%s here, because this string will be inserted twice.
local localisedItemMinSkill = string.gsub(string.gsub(string.gsub(itemMinSkillString[GetLocale()], " ", "%%%%s?"), "e", "(.*)"), "p", professionName)

-- "%s?%%.-s%s" matches both " %s " (EN), "%s " (FR) and " %1$s " (DE) in _G.ITEM_MIN_SKILL.
-- "%(%%.-d%)%s?" matches both " (%d)" (EN), " (%d) " (FR) and " (%2$d)" (DE) in _G.ITEM_MIN_SKILL.
local searchPattern = string.gsub(string.gsub("^" .. _G.ITEM_MIN_SKILL .. "$", "%s?%%.-s%s", "%%s?" .. localisedItemMinSkill .. "%%s"), "%(%%.-d%)%s?", "%%((%%d+)%%)%%s?")

-- Let msg be the respective line of the tooltip. Then you use string.match to get the (still localised) expansion identifier and the required skill out of this line:
Code:
local expansionIdentifier, requiredSkill = string.match(msg, searchPattern)

-- Trim trailing blank space if any.
expansionIdentifier = string.gsub(expansionIdentifier, "^(.-)%s$", "%1")

To change the localised expansion identifier into a non-localised one you need a table like this:

Code:
expansionIdentifierToVersionNumber = {
  ["enUS"] = {
    [""] =                      EP_VANILLA,
    ["Outland"] =               EP_BC,
    ["Northrend"] =             EP_WOTLK,
    ["Cataclysm"] =             EP_CATA,
    ["Pandaria"] =              EP_PANDARIA,
    ["Draenor"] =               EP_WOD,
    ["Legion"] =                EP_LEGION,
    ["Zandalari"] =             EP_BFA,
    ["Kul Tiran"] =             EP_BFA,
  },
  ["enGB"] = {
    [""] =                      EP_VANILLA,
    ["Outland"] =               EP_BC,
    ["Northrend"] =             EP_WOTLK,
    ["Cataclysm"] =             EP_CATA,
    ["Pandaria"] =              EP_PANDARIA,
    ["Draenor"] =               EP_WOD,
    ["Legion"] =                EP_LEGION,
    ["Zandalari"] =             EP_BFA,
    ["Kul Tiran"] =             EP_BFA,
  },
  ["deDE"] = {
    [""] =                      EP_VANILLA,
    ["der Scherbenwelt"] =      EP_BC,
    ["von Nordend"] =           EP_WOTLK,
    ["des Kataklysmus"] =       EP_CATA,
    ["von Pandaria"] =          EP_PANDARIA,
    ["von Draenor"] =           EP_WOD,
    ["der Verheerten Inseln"] = EP_LEGION,
    ["von Zandalar"] =          EP_BFA,
    ["von Kul Tiras"] =         EP_BFA,
  },
  ["frFR"] = {
    [""] =                      EP_VANILLA,
    ["de l’Outreterre"] =       EP_BC,
    ["du Norfendre"] =          EP_WOTLK,
    ["de Cataclysm"] =          EP_CATA,
    ["de Pandarie"] =           EP_PANDARIA,
    ["de Draenor"] =            EP_WOD,
    ["de Legion"] =             EP_LEGION,
    ["de Zandalar"] =           EP_BFA,
    ["de Kul Tiras"] =          EP_BFA,
  },
  ["itIT"] = {
    [""] =                      EP_VANILLA,
    ["delle Terre Esterne"] =   EP_BC,
    ["di Nordania"] =           EP_WOTLK,
    ["di Cataclysm"] =          EP_CATA,
    ["di Pandaria"] =           EP_PANDARIA,
    ["di Draenor"] =            EP_WOD,
    ["di Legion"] =             EP_LEGION,
    ["di Zandalar"] =           EP_BFA,
    ["di Kul Tiras"] =          EP_BFA,
  },
}
To do this:

Code:
local globalExpansionIdentifier = expansionIdentifierToVersionNumber[GetLocale()][expansionIdentifier]

If you want to see this in action, check out my first ever released addon: Bagnon RequiredLevel

Thanks to all of you for getting me there! :-)
  Reply With Quote