From a37a962ecc57c213c722dbed41202a4311ab2817 Mon Sep 17 00:00:00 2001 From: "James D. Callahan III" Date: Sun, 13 Mar 2011 15:38:50 -0500 Subject: [PATCH] Added the ability to dump the trainers for a given profession via addon:DumpTrainers("tailoring") (for example). --- Recipe.lua | 12 ++++++++ Scanner.lua | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- Utilities.lua | 9 ++++-- 3 files changed, 107 insertions(+), 5 deletions(-) diff --git a/Recipe.lua b/Recipe.lua index 17305fb..a623ef6 100644 --- a/Recipe.lua +++ b/Recipe.lua @@ -627,6 +627,18 @@ function recipe_prototype:Dump(output) table.insert(output, "") end +function recipe_prototype:DumpTrainers(registry) + local trainer_data = self.acquire_data[A.TRAINER] + + if not trainer_data then + return + end + + for identifier in pairs(trainer_data) do + registry[identifier] = true + end +end + --- Public API function for retrieving specific information about a recipe. -- @name AckisRecipeList:GetRecipeData -- @usage AckisRecipeList:GetRecipeData(28972, "profession") diff --git a/Scanner.lua b/Scanner.lua index c6d1ffe..9d0e7d6 100644 --- a/Scanner.lua +++ b/Scanner.lua @@ -372,9 +372,6 @@ function addon:GenerateLinks() end -------------------------------------------------------------------------------- ---- Scans the items in the specified profession -------------------------------------------------------------------------------- do local ORDERED_PROFESSIONS = private.ordered_professions @@ -397,6 +394,9 @@ do table.sort(sorted_recipes, Sort_AscID) end + ------------------------------------------------------------------------------- + --- Scans the items in the specified profession + ------------------------------------------------------------------------------- local function ProfessionScan(prof_name) local master_list = LoadRecipe() @@ -482,6 +482,9 @@ do recipe:Dump(output) end + ------------------------------------------------------------------------------- + --- Dumps the items in the specified profession + ------------------------------------------------------------------------------- local function ProfessionDump(prof_name) local master_list = LoadRecipe() @@ -545,6 +548,88 @@ do end end end + + ------------------------------------------------------------------------------- + --- Dumps the trainers for the specified recipe/profession + ------------------------------------------------------------------------------- + local trainer_registry = {} + local sorted_data = {} + + local function ProfessionTrainerDump(prof_name) + local master_list = LoadRecipe() + + if not master_list then + addon:Print(L["DATAMINE_NODB_ERROR"]) + return + end + table.wipe(recipe_list) + + if prof_name == private.professions["Smelting"]:lower() then + prof_name = private.mining_name:lower() + end + for i in pairs(master_list) do + local prof = master_list[i].profession:lower() + + if prof and prof == prof_name then + recipe_list[i] = master_list[i] + end + end + SortRecipesByID() + table.wipe(output) + table.wipe(trainer_registry) + table.wipe(sorted_data) + + for index, spell_id in ipairs(addon.sorted_recipes) do + private.recipe_list[spell_id]:DumpTrainers(trainer_registry) + end + + for identifier in pairs(trainer_registry) do + table.insert(sorted_data, identifier) + end + table.sort(sorted_data) + + for index, identifier in ipairs(sorted_data) do + local trainer = private.trainer_list[identifier] + local trainer_name + + if trainer.spell_id then + table.insert(output, ("AddTrainer(%s, %s, \"%s\", %s, %s, \"%s\")"):format(identifier, trainer.spell_id, trainer.location, trainer.coord_x, trainer.coord_y, trainer.faction)) + else + table.insert(output, ("AddTrainer(%s, \"%s\", \"%s\", %s, %s, \"%s\")"):format(identifier, trainer.name, trainer.location, trainer.coord_x, trainer.coord_y, trainer.faction)) + end + end + addon:DisplayTextDump(nil, nil, table.concat(output, "\n")) + end + + function addon:DumpTrainers(prof_name) + if type(prof_name) == "number" then + prof_name = _G.GetSpellInfo(prof_name) + end + + local found = false + prof_name = string.lower(prof_name) + + local scan_all = prof_name == "all" + + if not scan_all then + for idx, name in ipairs(ORDERED_PROFESSIONS) do + if prof_name == name:lower() then + found = true + break + end + end + + if not found then + self:Print(L["DATAMINER_NODB_ERROR"]) + return + end + ProfessionTrainerDump(prof_name) + else + for idx, name in ipairs(ORDERED_PROFESSIONS) do + ProfessionTrainerDump(name:lower()) + end + end + end end -- do local RECIPE_TYPES = { diff --git a/Utilities.lua b/Utilities.lua index 4e80573..826c1c9 100644 --- a/Utilities.lua +++ b/Utilities.lua @@ -38,7 +38,11 @@ do lookup_list[identifier] = entry if faction then - entry.faction = FACTION_NAMES[faction + 1] + if _G.type(faction) == "string" then + entry.faction = faction + else + entry.faction = FACTION_NAMES[faction + 1] + end end if coord_x and coord_y then @@ -54,7 +58,8 @@ do if faction and lookup_list == private.mob_list then addon:Debug("Mob %d (%s) has been assigned to faction %s.", identifier, name, lookup_list[identifier].faction) end - --@end-alpha@ + --@end-alpha@ + return entry end end -- do -- 1.7.9.5