From b7a4bd1bd52ff5b54f4359f392b14906fa1a1ae9 Mon Sep 17 00:00:00 2001 From: pschifferer Date: Fri, 5 Feb 2010 04:31:41 +0000 Subject: [PATCH] Added checks around skill updates and skill scanning. --- CauldronTradeskill.lua | 421 ++++++++++++++++++++++++------------------------ 1 file changed, 214 insertions(+), 207 deletions(-) diff --git a/CauldronTradeskill.lua b/CauldronTradeskill.lua index 4a9b072..4d1fdf3 100644 --- a/CauldronTradeskill.lua +++ b/CauldronTradeskill.lua @@ -22,237 +22,244 @@ function Cauldron:UpdateSkills() return; end - if IsTradeSkillLinked() then - skillName = "Linked-"..skillName; - end - - -- initialize the trade skill entry - if not self.db.realm.userdata[self.vars.playername].skills[skillName] then - self.db.realm.userdata[self.vars.playername].skills[skillName] = {}; - end - - -- initialize the reagent map - if not self.db.realm.userdata[self.vars.playername].reagentMap then - self.db.realm.userdata[self.vars.playername].reagentMap = {}; - end - - -- save the skill entry in a local var - local skillDB = self.db.realm.userdata[self.vars.playername].skills[skillName]; - if not skillDB.recipes then - skillDB.recipes = {}; - end - - local rescanNotify = false; - - -- initialize window information, if necessary - if not skillDB.window then - skillDB.window = { - search = "", - filter = { - optimal = true, - medium = true, - easy = true, - trivial = true, - haveAllReagents = false, - haveKeyReagents = false, - haveAnyReagents = false, - sortDefault = true, - sortDifficulty = false, - sortAlpha = false, - sortBenefit = false, - sortItemLevel = false, - sortRequiredLevel = false, - sortFavorites = false, - favorites = false, - achievements = false, - }, - skills = {}, - slots = {}, - categories = {}, - selected = 1, - }; - end - - -- make sure we're getting a full list - SetTradeSkillItemNameFilter(nil); - SetTradeSkillItemLevelFilter(0, 0); - - local category = ""; + if not Cauldron.scanningSkills then + + Cauldron.scanningSkills = true; - for i=1,GetNumTradeSkills() do --- self:info("i="..tostring(i)); - local name, difficulty, avail, expanded, verb = GetTradeSkillInfo(i); --- self:debug("UpdateSkills: name="..name.."; difficulty="..difficulty.."; avail="..avail); - - if name and difficulty ~= "header" then + if IsTradeSkillLinked() then + skillName = "Linked-"..skillName; + end + + -- initialize the trade skill entry + if not self.db.realm.userdata[self.vars.playername].skills[skillName] then + self.db.realm.userdata[self.vars.playername].skills[skillName] = {}; + end - local minMade, maxMade = GetTradeSkillNumMade(i); + -- initialize the reagent map + if not self.db.realm.userdata[self.vars.playername].reagentMap then + self.db.realm.userdata[self.vars.playername].reagentMap = {}; + end + + -- save the skill entry in a local var + local skillDB = self.db.realm.userdata[self.vars.playername].skills[skillName]; + if not skillDB.recipes then + skillDB.recipes = {}; + end + + local rescanNotify = false; + + -- initialize window information, if necessary + if not skillDB.window then + skillDB.window = { + search = "", + filter = { + optimal = true, + medium = true, + easy = true, + trivial = true, + haveAllReagents = false, + haveKeyReagents = false, + haveAnyReagents = false, + sortDefault = true, + sortDifficulty = false, + sortAlpha = false, + sortBenefit = false, + sortItemLevel = false, + sortRequiredLevel = false, + sortFavorites = false, + favorites = false, + achievements = false, + }, + skills = {}, + slots = {}, + categories = {}, + selected = 1, + }; + end + + -- make sure we're getting a full list + SetTradeSkillItemNameFilter(nil); + SetTradeSkillItemLevelFilter(0, 0); - -- adjust min/max made for specialities - -- TODO - - -- check if we're rescanning, updating or adding - local rescan = false; - if skillDB.rescan then - if skillDB.rescan.failedRecipes[name] then - rescan = true; - end - end + local category = ""; + + for i=1,GetNumTradeSkills() do + -- self:info("i="..tostring(i)); + local name, difficulty, avail, expanded, verb = GetTradeSkillInfo(i); + -- self:debug("UpdateSkills: name="..name.."; difficulty="..difficulty.."; avail="..avail); + + if name and difficulty ~= "header" then - if skillDB.recipes[name] and not rescan then - -- update the recipe info - skillDB.recipes[name].index = i; - skillDB.recipes[name].difficulty = difficulty; - skillDB.recipes[name].available = avail; - skillDB.recipes[name].minMade = minMade; - skillDB.recipes[name].maxMade = maxMade; + local minMade, maxMade = GetTradeSkillNumMade(i); - -- update reagent skill index - for _,r in ipairs(skillDB.recipes[name].reagents) do - r.skillIndex = i; - end - else - if rescan then - local msg = string.format(L["Rescanning recipe: %1$s..."], name); - Cauldron:Print(msg); - - -- remove it from the list (we're optimistic!) - skillDB.rescan.failedRecipes[name] = nil; + -- adjust min/max made for specialities + -- TODO + + -- check if we're rescanning, updating or adding + local rescan = false; + if skillDB.rescan then + if skillDB.rescan.failedRecipes[name] then + rescan = true; + end end - - -- add the recipe info and other miscellaneous info - local itemLink = GetTradeSkillItemLink(i); - local recipeLink = GetTradeSkillRecipeLink(i); - local _, _, _, _, _, _, _, _, slot, _ = GetItemInfo(itemLink); - local keywords = name; - - -- fill in the db entry - skillDB.recipes[name] = { - ['index'] = i, - ['name'] = name, - ['itemLink'] = itemLink, - ['recipeLink'] = recipeLink, - ['icon'] = GetTradeSkillIcon(i), - ['tradeskill'] = baseSkillName, - ['difficulty'] = difficulty, - ['available'] = avail, - ['minMade'] = minMade, - ['maxMade'] = maxMade, - - -- filter information - ['slot'] = slot, - ['defaultCategory'] = category, + if skillDB.recipes[name] and not rescan then + -- update the recipe info + skillDB.recipes[name].index = i; + skillDB.recipes[name].difficulty = difficulty; + skillDB.recipes[name].available = avail; + skillDB.recipes[name].minMade = minMade; + skillDB.recipes[name].maxMade = maxMade; - ['reagents'] = {}, - }; - - -- set the action verb for this skill - skillDB.recipes[name].verb = verb; + -- update reagent skill index + for _,r in ipairs(skillDB.recipes[name].reagents) do + r.skillIndex = i; + end + else + if rescan then + local msg = string.format(L["Rescanning recipe: %1$s..."], name); + Cauldron:Print(msg); + + -- remove it from the list (we're optimistic!) + skillDB.rescan.failedRecipes[name] = nil; + end - -- make sure the skill window info is initialized - if not skillDB.window.skills[name] then - skillDB.window.skills[name] = { - ['expanded'] = false, - ['favorite'] = false, + -- add the recipe info and other miscellaneous info + local itemLink = GetTradeSkillItemLink(i); + local recipeLink = GetTradeSkillRecipeLink(i); + local _, _, _, _, _, _, _, _, slot, _ = GetItemInfo(itemLink); + + local keywords = name; + + -- fill in the db entry + skillDB.recipes[name] = { + ['index'] = i, + ['name'] = name, + ['itemLink'] = itemLink, + ['recipeLink'] = recipeLink, + ['icon'] = GetTradeSkillIcon(i), + ['tradeskill'] = baseSkillName, + ['difficulty'] = difficulty, + ['available'] = avail, + ['minMade'] = minMade, + ['maxMade'] = maxMade, + + -- filter information + ['slot'] = slot, + ['defaultCategory'] = category, + + ['reagents'] = {}, }; - end - -- make sure the category for the window is initialized - if category ~= "" then - if not skillDB.window.categories[category] then - skillDB.window.categories[category] = { - ['shown'] = true, - ['expanded'] = true, + -- set the action verb for this skill + skillDB.recipes[name].verb = verb; + + -- make sure the skill window info is initialized + if not skillDB.window.skills[name] then + skillDB.window.skills[name] = { + ['expanded'] = false, + ['favorite'] = false, }; end - end - - -- populate the slot list - Cauldron:debug("slot: "..tostring(slot)); - if slot and (slot ~= "") then - skillDB.window.slots[slot] = { - checked = true, - }; - else - -- special slot representing items that don't have a slot - skillDB.window.slots.none = { - checked = true, - }; - end - - -- populate the reagent list - local num = GetTradeSkillNumReagents(i); - for j=1,num do - local rName, rIcon, rCount, _ = GetTradeSkillReagentInfo(i, j); - local rLink = GetTradeSkillReagentItemLink(i, j); - local rItemId = Cauldron:GetIdFromLink(rLink); - local key = not Cauldron:IsVendorItem(rItemId); - - if (not rName) or (not rIcon) or (not rLink) then - rescanNotify = true; - - -- store the info if it's not already from rescanning - if not rescan then - Cauldron:error("Failed to retrieve reagent info; marking recipe for rescan: "..name); - Cauldron:MarkRecipeForRescan(skillDB, name); - end - --[[ - Cauldron:debug("First attempt to get reagent info failed. Trying again. (skill: "..name..", reagentIndex: "..j..", name: "..tostring(rName)..", icon: "..tostring(rIcon)..", link: "..tostring(rLink)..")"); - -- be persisent about getting the info - rName, rIcon, _, _ = GetTradeSkillReagentInfo(i, j); - rLink = GetTradeSkillReagentItemLink(i, j); - ]] + -- make sure the category for the window is initialized + if category ~= "" then + if not skillDB.window.categories[category] then + skillDB.window.categories[category] = { + ['shown'] = true, + ['expanded'] = true, + }; + end end - - --[[ - if (not rName) or (not rIcon) or (not rLink) then - -- be persisent about getting the info - Cauldron:error("Can't get name/icon/link for reagent! (skill: "..name..", reagentIndex: "..j..", name: "..tostring(rName)..", icon: "..tostring(rIcon)..", link: "..tostring(rLink)..")"); + + -- populate the slot list + Cauldron:debug("slot: "..tostring(slot)); + if slot and (slot ~= "") then + skillDB.window.slots[slot] = { + checked = true, + }; + else + -- special slot representing items that don't have a slot + skillDB.window.slots.none = { + checked = true, + }; end - --]] - - local r = { - ["index"] = j, - ["name"] = rName, - ["numRequired"] = rCount, - ["skillIndex"] = i, - ["icon"] = rIcon, - ["link"] = rLink, - ["key"] = key, - }; - - table.insert(skillDB.recipes[name].reagents, r); - -- add the reagent to the reagent map - - if rName then - if not self.db.realm.userdata[self.vars.playername].reagentMap[rName] then - self.db.realm.userdata[self.vars.playername].reagentMap[rName] = {}; + -- populate the reagent list + local num = GetTradeSkillNumReagents(i); + for j=1,num do + local rName, rIcon, rCount, _ = GetTradeSkillReagentInfo(i, j); + local rLink = GetTradeSkillReagentItemLink(i, j); + local rItemId = Cauldron:GetIdFromLink(rLink); + local key = not Cauldron:IsVendorItem(rItemId); + + if (not rName) or (not rIcon) or (not rLink) then + rescanNotify = true; + + -- store the info if it's not already from rescanning + if not rescan then + Cauldron:error("Failed to retrieve reagent info; marking recipe for rescan: "..name); + Cauldron:MarkRecipeForRescan(skillDB, name); + end + + --[[ + Cauldron:debug("First attempt to get reagent info failed. Trying again. (skill: "..name..", reagentIndex: "..j..", name: "..tostring(rName)..", icon: "..tostring(rIcon)..", link: "..tostring(rLink)..")"); + -- be persisent about getting the info + rName, rIcon, _, _ = GetTradeSkillReagentInfo(i, j); + rLink = GetTradeSkillReagentItemLink(i, j); + ]] + end + + --[[ + if (not rName) or (not rIcon) or (not rLink) then + -- be persisent about getting the info + Cauldron:error("Can't get name/icon/link for reagent! (skill: "..name..", reagentIndex: "..j..", name: "..tostring(rName)..", icon: "..tostring(rIcon)..", link: "..tostring(rLink)..")"); + end + --]] + + local r = { + ["index"] = j, + ["name"] = rName, + ["numRequired"] = rCount, + ["skillIndex"] = i, + ["icon"] = rIcon, + ["link"] = rLink, + ["key"] = key, + }; + + table.insert(skillDB.recipes[name].reagents, r); + + -- add the reagent to the reagent map + + if rName then + if not self.db.realm.userdata[self.vars.playername].reagentMap[rName] then + self.db.realm.userdata[self.vars.playername].reagentMap[rName] = {}; + end + table.insert(self.db.realm.userdata[self.vars.playername].reagentMap[rName], skillName..";"..recipeLink); + + keywords = keywords..","..rName; end - table.insert(self.db.realm.userdata[self.vars.playername].reagentMap[rName], skillName..";"..recipeLink); - - keywords = keywords..","..rName; end + + -- fill in the keywords db entry + skillDB.recipes[name].keywords = keywords; end - - -- fill in the keywords db entry - skillDB.recipes[name].keywords = keywords; - end - else - -- save the header name - if name then - category = name; - - -- expand the header, so we get all the skills - if not expanded then - ExpandTradeSkillSubClass(i); + else + -- save the header name + if name then + category = name; + + -- expand the header, so we get all the skills + if not expanded then + ExpandTradeSkillSubClass(i); + end end end end + + Cauldron.scanningSkills = false; end - + if rescanNotify then Cauldron:error(L["Cauldron had issues with some recipes for this profession."]); local msg = string.format(L["Please close and re-open the %1$s window again to re-scan."], baseSkillName); -- 1.7.9.5